Members - Reputation: 159
Posted 13 August 2012 - 02:52 PM
Members - Reputation: 1046
Posted 13 August 2012 - 05:33 PM
In my pixel shader I have something like:
float3 directionToCamera = normalize(cameraPosition - input.WorldPosition); // cameraPosition is a shader constant, WorldPosition is passed through to PS
float dp = dot(directionToCamera, input.WorldNormal); // WorldNormal is passed through to PS
Then, dp will be a value between 1 and -1. 1 when the surface faces the viewer, 0 when it's on edge, and -1 when it faces the opposite direction (if you're using backface culling presumably it won't be less than 0 in the PS). Then use this value to modify the texture amount.
You could probably do this in the vertex shader too. And you might be able to just use the viewspace normal (instead of passing cameraPosition into the shader), although I think this will give slightly different results (how much the surface faces the screen rather than the camera position).
Edited by phil_t, 13 August 2012 - 05:33 PM.