Jump to content
  • Advertisement
Sign in to follow this  
Bow_vernon

OpenGL Scene with many lights (need help!..again..)

This topic is 2828 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Damn, I just want to shade my scene, but calculating lighting per object isn't that funny. So I just read about deferred shading, But none of them use openGL(GLSL), And I'm having trouble setting up the G-Buffer. For the diffuse, normals, I could handle it. But I dont know how to store position. Well I tried to store the position(in view space). Since my english's bad, let's just review what I've achieved:

1. Well I stored the diffuse unlit scene . It gave me the scene with proper texture (unlit)
2. I stored the normal, it gave me the scene in bluish color(like in the normal map), but the normal is stored in viewspace
3. I stored the position. Here's how. It gave me greenish and reddish texture(contains the position in viewspace)
4. By the way, I did 4 pass to the rendering stage (I dont use MRT) I just want to see how deferred shading works, then optimizing it.

//In Vertex Shader

varying vec3 vPos;
void main()
{
gl_Position = ftransform();
vPos = gl_ModelViewMatrix * gl_Vertex;
}

//In Fragment shader

varying vec3 vPos;
uniform float fNear;
uniform float fFar;
void main()
{
//Convert pos. store xyz in normalized rgb value, and distance in
//alpha (normalized)

float fDist = length(vPos);
vec3 vPos2 = vPos / fDist; //normalize it

vec4 vColor;

vColor.r = (vPos2.x * 0.5) + 0.5; //In range [0,1]
vColor.g = (vPos2.y * 0.5) + 0.5; //In range [0,1]
vColor.b = (vPos2.z * 0.5) + 0.5; //In range [0,1]
vColor.a = (fDist - fNear)/fFar; //In range [0,1]
}

the above shader gives me the correct position (should be), cause it shows a scene with reddish and greenish color. Well, when I test the scene using directional lighting only, it worked well (I transform the light's dir to view space, then send it to the lighting shader.)

But when I attempted to try point light, it doesnt show anything. It's as if I stored the position uncorrectly. Well, next time I'll post a screenshot, But can somebody tell what's wrong??

Or maybe a good deferred shading demo/tutorial with glsl??I've searched the google but no dice. Shite.

Share this post


Link to post
Share on other sites
Advertisement
Why not write this part
vColor.r = (vPos2.x * 0.5) + 0.5; //In range [0,1]
vColor.g = (vPos2.y * 0.5) + 0.5; //In range [0,1]
vColor.b = (vPos2.z * 0.5) + 0.5; //In range [0,1]

as
vColor.rgb = (vPos2.xyz * 0.5) + 0.5; //In range [0,1]

because it would be 1 instruction for the GPU.

Share this post


Link to post
Share on other sites
Well, thx. I'll optimize that later. The thing is I cant get the deferred shader to work. I think it's because the precision issue (I Dont know). Or perhaps because I stored the position in the viewspace (camera space)??
But it should work. I did some simple attenuation test, it's not working....Meanwhile, I'll do a more in-depth search in google first. Then I'll come back here. Thx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!