Not interpolating surface shader normals (by purpose)

Hey all,

is it possible to tell a surface shader to NOT interpolate the normals from vertex level to fragment level? What I am trying to do is a faceted shader (hard edges for every face) without changing the actual surface normals (because I finally want to use the shader as a terrain replacement shader, so I cannot change the surface normals).

Is that possible? And if not, could it be done with a non-surface shader?
It seems to be quite hard to find a solution to this, because everyone tries to get a smooth surface :).

Felix

It’s nearly impossible. The only way for pixels to get any values at all is by auto-interpolation during rasterizing. It seems like turning off interpolation could use the “face” normal, but faces don’t have normals or any other values. Everything is interpolated from verts. The pixel shader has no access to the verts it was built from, or even whether it was made from a line, tri, quad… , so there is no hope of computing the “face” normal in the pixel shader.

A surf/non-surf shader won’t matter. If you have any lighting at all, it goes off of the normals.

Mechanics-wise, the question is “can the rasterizer be told to compute a single “average of all verts” value, used for all pixels in the face, instead of linear interpolation?”

The common way to do it is to split all the verts (which is what flat shading does for you automatically.) All verts in a face get the exact same “face” normal, which interpolates to that normal. But there’s no way to tell Unity’s terrain mesh to do that.

I could see where you make a low-res normal map of the terrain (Unity provides enough access you could auto-generate it from the Terrain,) have the pixel shader compute UVnormMap = floor(IN.UV.xz/5+0.5), so that all pixels in a square use the exact same value, then look that up and use it for the normal.