VS to PS - which values are interpolated?

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

Recommended Posts

Hi everybody. Right now I'm implementing fog in HLSL for my small terrain engine. Everything works fine, but I'd like to know what gets interpolated from the VS to the PS. The reason behind this is the following: To save fillrate I calculate the distance from the camera to the vertex inside the VS and just use this value in the PS to calculate the lerp factor for my fog. Like this:
VS()
{
output.WorldPos = mul(input.Position, matWorld);
output.Distance = distance(output.WorldPos, cameraPos);
}

PS()
{
color = calculateFog(color, input.Distance);
}


While this works fine for my terrain, my water plane (just two triangles stretched across the whole terrain), is almost entirely drawn in my fog color, so I have to do this:
VS()
{
output.WorldPos = mul(input.Position, matWorld);
}

PS()
{
color = calculateFog(color, distance(input.WorldPos, CameraPos));
}


So, which one is better? And why is WorldPos interpolated to the PS, while Distance is not? regards

Share on other sites
All the values are interpolated.

You are smply overestimating the ability of linear interpolation to generate smooth values with very few sample points.. if your water plane has so few vertices, you cant expect the interpolation to somehow make it seem like there are lots of vertices..

if you calculate the distance in the pixel shader however, you can. If things worked the way you wanted, there would be not much need for pixel shaders.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 23
• 9
• 57
• Forum Statistics

• Total Topics
632639
• Total Posts
3007603
• Who's Online (See full list)

There are no registered users currently online

×