
Wierd Diffuse Light with Vertex Shader
My vertex shader code for simple diffuse light is the following:
vfconn OUT;
OUT.HPos = mul(ModelViewProj, IN.position);
OUT.Col0=IN.position*saturate( dot(IN.norm, normalize(litepos-IN.position)) );
OUT.texcoord=IN.texcoord;
return OUT;
And the results:
The radius of the lit area both increases with increasing x,y or z coords of the light (a rectangle on the x/y plane is lit)
I checked my vertices, normals and light position to be correct. Any idea whats wrong?
thank you in advance!
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
[edited by - orbano on January 11, 2004 6:34:09 AM]

"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Well for starters - You havent normalised your normal.
If you dont make sure that all the vectors u use are normalised - bad things tend to happen
Hope that helps
[edit]
also - do u mean for lighting to also be a function of position?
IN.position*saturate( dot(IN.norm, normalize(litepos-IN.position)) );
*regular* diffuse lighting would be:-
saturate(dot(normalize(NORMAL),normalize(Lightvector)));
where Lightvector is (as u correctly did) LightPosition (litepos)- Vertex Position (IN.position)
[edited by - Dh_UK on January 11, 2004 9:32:08 PM]
If you dont make sure that all the vectors u use are normalised - bad things tend to happen

Hope that helps
[edit]
also - do u mean for lighting to also be a function of position?
IN.position*saturate( dot(IN.norm, normalize(litepos-IN.position)) );
*regular* diffuse lighting would be:-
saturate(dot(normalize(NORMAL),normalize(Lightvector)));
where Lightvector is (as u correctly did) LightPosition (litepos)- Vertex Position (IN.position)
[edited by - Dh_UK on January 11, 2004 9:32:08 PM]
thank you! my vertex shader was just fine (ive been doing such stuff in SW for long). this morning i woke up with the solution: I created my surface normals with absoltue coordinates, not vertex-relative, so they were vertex+[0,0,1] (plane on x/y). Now i set them simply to 0,0,1 and everything is fine! Going for specular highlight!
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin

"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement