Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Yet another per-pixel ligthing question (Cg)

This topic is 3896 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

I realize this is a common topic, my apologies for bringing this up again. I've been trying to move my lighting from object-space to eye-space, my problem is that my diffuse ligthing is not constant when rotating around a given object: I expect the diffuse light to not change when doing this. I assume this is correct, seeing how diffuse is not dependent on eye position. In the code below my ambient/specular lighting has been commented out. VP: // data from application to vertex program struct vertexIn { float4 Position : POSITION; float4 Normal : NORMAL; }; // vertex shader to pixel shader struct vertexOut { float4 HPosition : POSITION; float4 EyeNormal : TEXCOORD2; float4 PosEye : TEXCOORD3; }; // vertex shader vertexOut main(vertexIn IN) { vertexOut OUT; float4x4 ModelView = glstate.matrix.modelview[0]; float4x4 ModelViewIT = glstate.matrix.invtrans.modelview[0]; float4x4 ModelViewProj = glstate.matrix.mvp; // normal in eye coords OUT.EyeNormal.xyz = normalize(mul((float3x3)ModelViewIT, IN.Normal.xyz)); // pos in eye coords OUT.PosEye = mul(ModelView, IN.Position); // pos in clip coords OUT.HPosition = mul(ModelViewProj, IN.Position); return OUT; } FP: // data from vertex shader struct vertexOut { float4 HPosition : POSITION; float4 EyeNormal : TEXCOORD2; float4 PosEye : TEXCOORD3; }; // output from pixel shader struct pixelOut { float4 Color : COLOR0; }; // input from application struct pixelAppData { float4 lightColor; float materialShininess; float4 materialAmbient; float4 materialDiffuse; float4 materialSpecular; }; pixelOut main(vertexOut IN, uniform pixelAppData AppIn) { pixelOut OUT; float3 N = normalize(IN.EyeNormal.xyz); float4 lightPosEye = glstate.light[0].position; float3 L = normalize((lightPosEye - IN.PosEye).xyz); // not used atm float3 V = normalize(-IN.PosEye).xyz; // eye's position is always 0,0,0 in eye space // not used atm float3 H = normalize(L+V); float4 lightCoffs = lit(dot(N,L), dot(N,H), AppIn.materialShininess); // OUT.Color = AppIn.materialAmbient * lightCoffs[0]; OUT.Color = AppIn.lightColor * AppIn.materialDiffuse * lightCoffs[1]; // OUT.Color += AppIn.lightColor * AppIn.materialSpecular * lightCoffs[2]; return OUT; } My assumption is that the light position is somehow not correctly transformed into eye-space, however I'm using glLightfv(GL_LIGHT0, GL_POSITION, ..) to do this and according to my OpenGL manual this position given is automatically transfered into eye-space. Any help is appreciated.

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!