To create a shader program that uses a subroutine to switch between pure-diffuse and Phong, take the following steps:
- Set up the vertex shader with a subroutine uniform variable, and two functions of the subroutine type:
subroutine vec3 shadeModelType( vec3 position, vec3 normal); subroutine uniform shadeModelType shadeModel; out vec3 LightIntensity; // Uniform variables and attributes here... subroutine( shadeModelType ) vec3 phongModel( vec3 position, vec3 norm ) { // The Phong reflection model calculations go here... } subroutine( shadeModelType ) vec3 diffuseOnly( vec3 position, vec3 norm ) { // Compute diffuse shading only.. } void main() { // Compute camPosition and camNorm ... // Evaluate the shading equation, calling ...