How to do it...

To create a shader program that generates a wood-grain effect using a noise texture, perform the following steps:

  1. Set up your vertex shader to pass the texture coordinate to the fragment shader via the TexCoord variable.
  2. Use the following code for the fragment shader:
layout(binding=0) uniform sampler2D NoiseTex; uniform vec4 DarkWoodColor = vec4( 0.8, 0.5, 0.1, 1.0 ); uniform vec4 LightWoodColor = vec4( 1.0, 0.75, 0.25, 1.0 ); uniform mat4 Slice; in vec2 TexCoord; layout ( location = 0 ) out vec4 FragColor; void main() { // Transform the texture coordinates to define the // "slice" of the log. vec4 cyl = Slice * vec4( TexCoord.st, 0.0, 1.0 ); // The distance from the log's y axis. float dist = length(cyl.xz); // Perturb ...

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.