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

## Recommended Posts

Hi,

I'm having a bit of trouble getting my head around how interpolation works in HLSL when sending values from the vertex shader to the pixel shader. I've attached a shader I'm working with at the moment for rendering a water plane:

So I understand that HLSL will interpolate everything I've put in the vertex shader across the face of the current triangle when it is sent to the pixel shader, so I was wondering, could I move some of my other calculations across into the vertex shader? For example, my 'attenuation' calculation uses LightDirTS as a variable - would it still get interpolated properly if I move it over into the vertex shader and passed it in? Same with 'projTexCoord'.

Likewise I understand that things like 'reflectionVector' and 'specularLightingFactor' can't be in the VS because they are calculated using texture values (which are sampled per-pixel).

Can anyone help me understand exactly what should and shouldn't be in the vertex shader?

Thanks :)

##### Share on other sites

So I understand that HLSL will interpolate everything I've put in the vertex shader across the face of the current triangle when it is sent to the pixel shader,

Just to clarify ( mhagain already mention this ), but I think once you understand this then all that was mentioned before will make sense. HLSL does not interpolate everything in the vertex shader. Values passed from the vertex to the frapgment shader are interpolated, ie. vertex shader output only.

##### Share on other sites

lightDistance itself isn't linear though (abs(sqrt(xx+yy+zz))).

The easily mentally verifiable example I use is a massive triangle, say the size of a football field with me (a small camera) and a small light standing in the middle of the triangle.

Using vertex based calculations, maybe it's 50m to each vertex. Interpolate these 3 values and we get an interpolated result of 50m.
However, I'm actually standing 1m above the triangle...
Obviously vertex calculations plus interpolation are not correct for distance(as earlier- distance is not a linear function)

Yes that's correct, and a terrible example on my part. I must have turkey brain.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632917
• Total Posts
3009200
• ### Who's Online (See full list)

There are no registered users currently online

×