Basic Per Pixel Lighting/Specular Question

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

Recommended Posts

I have a tessellated plane (128x128 vertices), which I've applied a texture and a normal map to. In the pixel shader I use the sampled normal along with the vertex-to-eye vector and the vertex-to-light vector to work out the lighting and specular highlight at that point on the plane. All pretty standard stuff... nothing out of the ordinary. Since the plane is entirely flat, I thought that it is silly to render a 128x128 vertex plane when I could just render a 2x2 plane (i.e. a quad) and it would look that same. So I changed this, but now my lighting has stopped working. I know why, I just don't know how to get around the problem. The previously highly tessellated plane allowed for the vertex-to-eye and vertex-to-light vectors to interpolate across the plane. With a quad however, you only have four vertices. So your vertex-to-whatever vector can only be one of four absolute values. You lose the interpolation across the plane. This results in large very blocky and very sudden lighting as the vectors change across the plane from one sides extreme to the other. I'm just wondering how I go about tackling this problem. How do I do per-pixel lighting on a simple quad surface with no tessellation? How do I determine the to-eye and to-light vectors from any point on the plane? I'll just point out that the plane is on the xz axis and everything is done in world space, which is also object space in this case, so therefore I have no need for tangent space.

Share on other sites
It would be good if you posted your shaders. I'm not sure I understand how your lighting can be blocky, since vertex output data is still interpolated for the pixel shader. However, you can always compute the vectors in the pixel shader. You can get the coordinate of a pixel by simply passing the vertex coordinate from the vertex shader to the pixel shader.

Share on other sites
In cases like these, do not use vertex-eye or vertex-light, but rather fragment-eye and fragment-light. The basic idea is to pass your vertex position down to the pixel shader using a texture coordinate slot (so it gets linearly interpolated). This gives you the exact fragment position. Now, you'll want to calculate the eye/light directions at the fragment level - this way the calculations are independent of vertices.

Share on other sites
I don't know if this helps much, but your loss in precision might be due the data format you choose. The interpolation, is it done with floating numbers, or half/fixed data types? Try to choose for the most precise data type you got in this case.

Greetings,
Rick

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 9
• 14
• 9
• 9
• 9
• Forum Statistics

• Total Topics
633331
• Total Posts
3011394
• Who's Online (See full list)

There are no registered users currently online

×