GLSL Programming/Blender/Two-Sided Smooth Surfaces

This tutorial covers two-sided per-pixel lighting (i.e. two-sided Phong shading).

Here we combine the per-pixel lighting discussed in the tutorial on smooth specular highlights with the two-sided lighting discussed in the tutorial on two-sided surfaces.

Shader Coder
The required changes to the code of the tutorial on smooth specular highlights are: new properties for the back material, new local variables for the material parameters in the fragment shader, which are set either to the front material parameters or the back material parameters according to. Also, the surface normal vector is negated in case a back face is rendered. Furthermore, back-face culling has to be deactivated as described in the tutorial on transparency. It's actually quite straightforward. However, keep in mind that Blender apparently never provides different data in  and  ; thus, you have to replace the uniforms in   by user-specified uniforms (see the tutorial on shading in view space).

The vertex shader could look like this:

And the fragment shader could be:

Summary
Congratulations, you have reached the end of this short tutorial. We have seen:
 * How two-sided surfaces can be rendered with per-pixel lighting.