From: <sam...@us...> - 2013-12-10 01:58:25
|
Revision: 14695 http://sourceforge.net/p/supertuxkart/code/14695 Author: samuncle Date: 2013-12-10 01:58:22 +0000 (Tue, 10 Dec 2013) Log Message: ----------- Now the grass shader can be used with the new pipeline. Modified Paths: -------------- main/trunk/data/shaders/grass.frag main/trunk/data/shaders/grass.vert Modified: main/trunk/data/shaders/grass.frag =================================================================== --- main/trunk/data/shaders/grass.frag 2013-12-10 01:57:20 UTC (rev 14694) +++ main/trunk/data/shaders/grass.frag 2013-12-10 01:58:22 UTC (rev 14695) @@ -1,3 +1,21 @@ +/*--- GENERIC HEADER -----------------------------------------------------------------------------*/ + +varying vec3 nor; +uniform float far; +uniform float objectid; + +const float near = 1.0; + +vec4 encdepth(float v) { + vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v; + enc = fract(enc); + enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0); + return enc; +} + +/*--- END OF GENERIC HEADER ----------------------------------------------------------------------*/ + + uniform sampler2D tex; void main() @@ -4,5 +22,19 @@ { vec4 color = texture2D(tex, gl_TexCoord[0].st); - gl_FragColor = color; + + + +/*--- GENERIC FOOTER -----------------------------------------------------------------------------*/ + + float linear_z = (2.0 * near) / (far + near - gl_FragCoord.z * (far - near)); + // Tune for better inside range without losing outdoors + linear_z *= 2.0; + + + gl_FragData[0] = color; + gl_FragData[1] = vec4(nor, linear_z); + gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid); + +/*--- END OF GENERIC FOOTER ----------------------------------------------------------------------*/ } Modified: main/trunk/data/shaders/grass.vert =================================================================== --- main/trunk/data/shaders/grass.vert 2013-12-10 01:57:20 UTC (rev 14694) +++ main/trunk/data/shaders/grass.vert 2013-12-10 01:58:22 UTC (rev 14695) @@ -1,3 +1,11 @@ +/*--- GENERIC HEADER ---*/ + +varying vec3 nor; +uniform mat4 invtworldm; + + +/*--- END OF GENERIC HEADER --*/ + uniform vec3 windDir; void main() @@ -7,5 +15,11 @@ vec4 vertexPosition = gl_Vertex; vertexPosition.xyz += windDir * gl_Color.r; + nor = (invtworldm * vec4(gl_Normal, 0.0)).xyz; + nor = normalize(nor); + nor = nor * 0.5 + 0.5; + gl_Position = gl_ModelViewProjectionMatrix * vertexPosition; + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |