To create a shader program that generates a wood-grain effect using a noise texture, perform the following steps:
- Set up your vertex shader to pass the texture coordinate to the fragment shader via the TexCoord variable.
- 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 ...