diff options
Diffstat (limited to 'src/GLSLShaderTest/wood.frag')
-rw-r--r-- | src/GLSLShaderTest/wood.frag | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/GLSLShaderTest/wood.frag b/src/GLSLShaderTest/wood.frag new file mode 100644 index 0000000..50ff2d5 --- /dev/null +++ b/src/GLSLShaderTest/wood.frag @@ -0,0 +1,66 @@ +// +// Simple fragment shader for wood +// +// Author: John Kessenich +// +// Copyright (c) 2002-2004 3Dlabs Inc. Ltd. +// +// See 3Dlabs-License.txt for license information +// + +//uniform float GrainSizeRecip; +//uniform vec3 DarkColor; +//uniform vec3 spread; +const float GrainSizeRecip = 1; +const vec3 DarkColor = vec3 (0.6, 0.3, 0.1); +const vec3 spread = vec3 (0.15, 0.075, 0.0); + +varying float lightIntensity; +varying vec3 Position; + +void main (void) +{ + // + // cheap noise + // + vec3 location = Position; + vec3 floorvec = vec3(floor(10.0 * Position.x), 0.0, floor(10.0 * Position.z)); + vec3 noise = Position * 10.0 - floorvec - 0.5; + noise *= noise; + location += noise * 0.12; + + // + // distance from axis + // + float dist = location.x * location.x + location.z * location.z; + float grain = dist * GrainSizeRecip; + + // + // grain effects as function of distance + // + float brightness = fract(grain); + if (brightness > 0.5) + brightness = (1.0 - brightness); + vec3 color = DarkColor + brightness * spread; + + brightness = fract(grain * 7.0); + if (brightness > 0.5) + brightness = 1.0 - brightness; + color -= brightness * spread; + + // + // also as a function of lines parallel to the axis + // + brightness = fract(grain * 47.0) * 0.60; + float line = fract(Position.z + Position.x); + float snap = floor(line * 20.0) * (1.0/20.0); + if (line < snap + 0.006) + color -= brightness * spread; + + // + // apply lighting effects from vertex processor + // + color = clamp(color * lightIntensity, 0.0, 1.0); + + gl_FragColor = vec4(color, 1.0); +} |