From b09e37fefdfe574e4b68bffccc98040673e98329 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Wed, 4 Apr 2012 22:39:46 +0100 Subject: [PATCH] Update random vegetation for project Rembrandt. Unfortunately due to a possible bug in the techniques code, the previous tree transparency handling has been disabled for the moment. --- Effects/tree.eff | 46 ++++++++++++++++++++++++++++++++++---- Shaders/deferred-tree.frag | 22 ++++++++++++++++++ Shaders/deferred-tree.vert | 30 +++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 Shaders/deferred-tree.frag create mode 100644 Shaders/deferred-tree.vert diff --git a/Effects/tree.eff b/Effects/tree.eff index 4307175ea..32da1964b 100644 --- a/Effects/tree.eff +++ b/Effects/tree.eff @@ -37,6 +37,44 @@ + + + + /sim/rendering/rembrandt + /sim/rendering/random-vegetation + + + + true + + 1.0 1.0 1.0 1.0 + 1.0 1.0 1.0 1.0 + off + + + gequal + 0.1 + + + 0 + 2d + + texture[0]/image + + clamp + clamp + + + Shaders/deferred-tree.vert + Shaders/deferred-tree.frag + + + texture + sampler-2d + 0 + + + @@ -123,7 +161,9 @@ - + + RenderBin @@ -166,7 +205,6 @@ sampler-2d 0 - visibility float @@ -209,7 +247,7 @@ fogtype - + --> diff --git a/Shaders/deferred-tree.frag b/Shaders/deferred-tree.frag new file mode 100644 index 000000000..da5c30582 --- /dev/null +++ b/Shaders/deferred-tree.frag @@ -0,0 +1,22 @@ +#extension GL_EXT_gpu_shader4 : enable +// +// attachment 0: normal.x | normal.x | normal.y | normal.y +// attachment 1: diffuse.r | diffuse.g | diffuse.b | material Id +// attachment 2: specular.l | shininess | emission.l | unused +// +uniform int materialID; +uniform sampler2D texture; +void main() { + vec4 texel = texture2D(texture, gl_TexCoord[0].st); + if (texel.a < 0.1) + discard; + float specular = 0.0; + float shininess = 0.1; + float emission = 0.0; + + // Normal is straight towards the viewer. + vec3 normal2 = (0.0, 0.0, 0.0); + gl_FragData[0] = vec4( 0.5, 0.5, 0.0, 1.0 ); + gl_FragData[1] = vec4( gl_Color.rgb * texel.rgb, float( materialID ) / 255.0 ); + gl_FragData[2] = vec4( specular, shininess / 255.0, emission, 1.0 ); +} diff --git a/Shaders/deferred-tree.vert b/Shaders/deferred-tree.vert new file mode 100644 index 000000000..65573225e --- /dev/null +++ b/Shaders/deferred-tree.vert @@ -0,0 +1,30 @@ +// Tree instance scheme: +// vertex - local position of quad vertex. +// normal - x y scaling, z number of varieties +// fog coord - rotation +// color - xyz of tree quad origin, replicated 4 times. +#version 120 + +void main() { + + // Texture coordinates + float numVarieties = gl_Normal.z; + float texFract = floor(fract(gl_MultiTexCoord0.x) * numVarieties) / numVarieties; + texFract += floor(gl_MultiTexCoord0.x) / numVarieties; + gl_TexCoord[0] = vec4(texFract, gl_MultiTexCoord0.y, 0.0, 0.0); + + // Position and scaling + vec3 position = gl_Vertex.xyz * gl_Normal.xxy; + float sr = sin(gl_FogCoord); + float cr = cos(gl_FogCoord); + + // Rotation of the generic quad to specific one for the tree. + position.xy = vec2(dot(position.xy, vec2(cr, sr)), dot(position.xy, vec2(-sr, cr))); + position = position + gl_Color.xyz; + gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0); + + // Color - white. + gl_FrontColor = vec4(1.0, 1.0, 1.0,1.0); + gl_BackColor = vec4(1.0, 1.0, 1.0,1.0); +} +