• Advertisement
Sign in to follow this  

VS to PS - which values are interpolated?

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

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


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

  • Advertisement