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); +} +