How it works...

The main function of the fragment shader retrieves a noise value from NoiseTex and stores it in the noise variable. The next two lines set the variable color to either the base diffuse reflectivity (Material.Kd) or PaintColor, depending on whether or not the noise value is greater than the threshold value (Threshold). This will cause a sharp transition between the two colors, and the size of the spatters will be related to the frequency of the noise.

Finally, the Phong shading model is evaluated using color as the diffuse reflectivity. The result is applied to the fragment.

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.