Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Multiple lights PHONG  (Read 752 times)
0 Members and 1 Guest are viewing this topic.
Online Kefwar
« Posted 2014-02-24 19:26:41 »

I'm trying to implement the shaders of this tutorial, but all I get is a black screen. With my old shaders everything is rendering. Could someone give me some advise how to implement it?

I tried adding lights, but that made no difference:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glEnable(GL_NORMALIZE);
       
        // Light model parameters:
        // -------------------------------------------
       
        FloatBuffer lmKa = BufferUtil.asFloatBuffer(0.0f, 0.0f, 0.0f, 0.0f);
        lmKa.flip();
        glLightModel(GL_LIGHT_MODEL_AMBIENT, lmKa);
       
        glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0f);
        glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, 0.0f);
       
        // -------------------------------------------
        // Spotlight Attenuation
       
        FloatBuffer spot_direction = BufferUtil.asFloatBuffer(1.0f, -1.0f, -1.0f, 0f);
        spot_direction.flip();
        int spot_exponent = 30;
        int spot_cutoff = 180;
       
        glLight(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);
        glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, spot_exponent);
        glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, spot_cutoff);
       
        float Kc = 1.0f;
        float Kl = 0.0f;
        float Kq = 0.0f;
       
        glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION,Kc);
        glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, Kl);
        glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, Kq);
       
       
        // -------------------------------------------
        // Lighting parameters:

        FloatBuffer light_pos = BufferUtil.asFloatBuffer(0.0f, 5.0f, 5.0f, 1.0f);
        FloatBuffer light_Ka  = BufferUtil.asFloatBuffer(1.0f, 0.5f, 0.5f, 1.0f);
        FloatBuffer light_Kd  = BufferUtil.asFloatBuffer(1.0f, 0.1f, 0.1f, 1.0f);
        FloatBuffer light_Ks  = BufferUtil.asFloatBuffer(1.0f, 1.0f, 1.0f, 1.0f);
        light_pos.flip();
        light_Ka.flip();
        light_Kd.flip();
        light_Ks.flip();
       
        glLight(GL_LIGHT0, GL_POSITION, light_pos);
        glLight(GL_LIGHT0, GL_AMBIENT, light_Ka);
        glLight(GL_LIGHT0, GL_DIFFUSE, light_Kd);
        glLight(GL_LIGHT0, GL_SPECULAR, light_Ks);

        // -------------------------------------------
        // Material parameters:

        FloatBuffer material_Ka = BufferUtil.asFloatBuffer(0.5f, 0.0f, 0.0f, 1.0f);
        FloatBuffer material_Kd = BufferUtil.asFloatBuffer(0.4f, 0.4f, 0.5f, 1.0f);
        FloatBuffer material_Ks = BufferUtil.asFloatBuffer(0.8f, 0.8f, 0.0f, 1.0f);
        FloatBuffer material_Ke = BufferUtil.asFloatBuffer(0.1f, 0.0f, 0.0f, 0.0f);
        material_Ka.flip();
        material_Kd.flip();
        material_Ks.flip();
        material_Ke.flip();
        float material_Se = 20.0f;

        glMaterial(GL_FRONT_AND_BACK, GL_AMBIENT, material_Ka);
        glMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE, material_Kd);
        glMaterial(GL_FRONT_AND_BACK, GL_SPECULAR, material_Ks);
        glMaterial(GL_FRONT_AND_BACK, GL_EMISSION, material_Ke);
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, material_Se);
Offline StrideColossus
« Reply #1 - Posted 2014-02-25 09:53:34 »

Been a while since I've used the fixed-function methods, but:
1  
2  
3  
FloatBuffer lmKa = BufferUtil.asFloatBuffer(0.0f, 0.0f, 0.0f, 0.0f);
        lmKa.flip();
        glLightModel(GL_LIGHT_MODEL_AMBIENT, lmKa);


sets the ambient light to black?  Maybe that's the problem?
Online Kefwar
« Reply #2 - Posted 2014-02-25 14:14:47 »

sets the ambient light to black?  Maybe that's the problem?
That was part of the problem, and my Normals were wrong. It is fixed.

But OpenGL only has 8 lights, so how can I add more lights? Do I have to add my own uniforms?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Longor1996
« Reply #3 - Posted 2014-02-25 14:26:50 »

For multiple lights you can use...

- Use a Texture to tell your Shader about the lights.
- Use uniforms to tell your Shader about the lights.
- A system that sorts all visible models against the lightsources, then activates the 8 closest ones for each model.
- A system that simply uses the 8 closest lightsources.
- Deffered Lighting
- Voxel Cone Tracing
- ...?

Mind that it is terribly inperformant to do a lot of lighting-calculations.
The easiest way to get around that is Deffered-Lighting.

Have a nice day.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Online Kefwar
« Reply #4 - Posted 2014-02-25 15:45:11 »

Mind that it is terribly inperformant to do a lot of lighting-calculations.
The easiest way to get around that is Deffered-Lighting.
Thank you for the information. I have been looking and think I found something useful:
Tutorial
Is this what you mean?
Offline Longor1996
« Reply #5 - Posted 2014-02-25 16:43:27 »

Yes, that is what I mean with 'Deferred Lighting'.

Mind that:
- It is very hard to have translucent objects with this.
- It is very hard to do antialiasing with this.

Have a nice day!

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Online Kefwar
« Reply #6 - Posted 2014-02-26 20:13:29 »

Is deferred lightning possible with older hardware.
1  
2  
3  
Vertex shader failed to compile with the following errors:
ERROR: 0:1: error(#106) Version number not supported by GL2
ERROR: error(#273) 1 compilation errors.  No code generated

Everywhere they use the newer versions  Undecided
Offline pitbuller
« Reply #7 - Posted 2014-02-26 20:18:45 »

Simplest way to use multiple lights with fixed function is multipass rendering. There you basically render models many times using additive blending and you disable depth writes and set depth test to equal.
Online Kefwar
« Reply #8 - Posted 2014-02-26 20:58:23 »

Simplest way to use multiple lights with fixed function is multipass rendering. There you basically render models many times using additive blending and you disable depth writes and set depth test to equal.

Just to make sure, it is'nt possible to do deferred lighting with my hardware? (ATI Mobility Radeon HD 3650 with OpenGL 6.14.10.11672)
Offline Longor1996
« Reply #9 - Posted 2014-02-26 21:36:03 »

Can you run Battlefield 3, Crysis 3, CoD Modern Warfare 4/5/etc. on that computer?
If so, Deferred-Lighting is avaible, since these games use it.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Kefwar
« Reply #10 - Posted 2014-02-26 21:53:25 »

Can you run Battlefield 3, Crysis 3, CoD Modern Warfare 4/5/etc. on that computer?
If so, Deferred-Lighting is avaible, since these games use it.

- Longor1996
I have never tried those games, because I only have 3GB RAM and a 2.00 gHz processor  Cry.

Simplest way to use multiple lights with fixed function is multipass rendering. There you basically render models many times using additive blending and you disable depth writes and set depth test to equal.

Does this make a big impact on the performance when you have much lights in an level? (for example a street with street lamps at night, or even a whole village).
Offline EgonOlsen
« Reply #11 - Posted 2014-02-26 22:07:33 »

I would step away from deferred lighting and just do something like this:

Quote
A system that sorts all visible models against the lightsources, then activates the 8 closest ones for each model.

That's much easier to do and it should be sufficient for a lot of cases. If you have multiple lights in a village, they usually don't affect all the models at once.  

Online Kefwar
« Reply #12 - Posted 2014-02-27 20:52:46 »

This is odd, after trying to add the Deferred rendering, the camera doesn't move/rotate anymore.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
        // Perform camera transformations
        camera.apply();

        shader.setUniform("projection", camera.getProjectionMatrix());
        shader.setUniform("view", camera.getViewMatrix());

        // Render the geometry into the FBO
        multipleRenderTarget.start();
        render();
        multipleRenderTarget.stop();
       
        deferredRendering.render();

Vertex shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
uniform mat4 projection;
uniform mat4 view;

void main( void )
{
    gl_Position = projection * view * gl_Vertex;
    gl_TexCoord[0] = gl_MultiTexCoord0;

    gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0);
}

The camera was working this way before and when I disable the Deferred rendering.
Online Kefwar
« Reply #13 - Posted 2014-03-08 19:42:52 »

This is more like it Cheesy
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (66 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!