I'd like to write a shader effect, where a transparent wall "glows" locally when a ball comes near it. By "glow" I mean simply make the transparent wall locally opaque. In my current implementation that wall doesn't glow correctly. In a script attached to the wall I pass the ball position to the wall-shader:
So far I've written this shader code:
Any idea what's wrong with my code? Isn't fragPos interpolated across the triangle?
Looks like your checking the distance in the pixel shader, after coordinates have already been transformed into eye / screen space.
You need to convert the point into the wall's local co-ordinate system, and then do the distance calculation in the vertext shader instead.
Convert the position of the ball into local space before sending to the shader:
And the shader changes:
answered Apr 12 '10 at 10:18 PM
Thanks to Horsman. I changed a bit of his code, so that it works fine even for objects of arbitrary triangulation:
Performance would be better, if the ball position in eye coordinates would not be computed in the vertex shader (=matrix multiplication for each vertex) but in a Unity script (=only one matrix multiplication).
answered Apr 13 '10 at 07:58 AM