Search
lxdream.org :: lxdream/src/pvr2/shaders.glsl :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/shaders.glsl
changeset 1232:e5b12e2fe6ba
prev1221:f50407acc682
next1240:190df8a791ca
author nkeynes
date Thu Feb 23 22:20:15 2012 +1000 (11 years ago)
permissions -rw-r--r--
last change Remove most of the remaining fixed-functionality in the shader rendering
path.
Rearrange the renderer to do each list for the full scene in turn, rather
than doing each tile completely
file annotate diff log raw
1.1 --- a/src/pvr2/shaders.glsl Mon Feb 13 22:16:43 2012 +1000
1.2 +++ b/src/pvr2/shaders.glsl Thu Feb 23 22:20:15 2012 +1000
1.3 @@ -66,44 +66,67 @@
1.4
1.5
1.6 #vertex DEFAULT_VERTEX_SHADER
1.7 +uniform mat4 view_matrix;
1.8 +attribute vec4 in_vertex;
1.9 +attribute vec4 in_colour;
1.10 +attribute vec4 in_colour2; /* rgb = colour, a = fog */
1.11 +attribute vec4 in_texcoord; /* uv = coord, z = palette, w = mode */
1.12 +
1.13 +varying vec4 frag_colour;
1.14 +varying vec4 frag_colour2;
1.15 +varying vec4 frag_texcoord;
1.16 void main()
1.17 {
1.18 - vec4 tmp = ftransform();
1.19 - float w = gl_Vertex.z;
1.20 + vec4 tmp = view_matrix * in_vertex;
1.21 + float w = in_vertex.z;
1.22 gl_Position = tmp * w;
1.23 - gl_FrontColor = gl_Color;
1.24 - gl_FrontSecondaryColor = gl_SecondaryColor;
1.25 - gl_TexCoord[0] = gl_MultiTexCoord0;
1.26 - gl_FogFragCoord = gl_FogCoord;
1.27 + frag_colour = in_colour;
1.28 + frag_colour2 = in_colour2;
1.29 + frag_texcoord = in_texcoord;
1.30 }
1.31
1.32 #fragment DEFAULT_FRAGMENT_SHADER
1.33
1.34 +uniform float alpha_ref;
1.35 uniform sampler2D primary_texture;
1.36 uniform sampler2D palette_texture;
1.37 +uniform vec3 fog_colour1;
1.38 +uniform vec3 fog_colour2;
1.39 +varying vec4 frag_colour;
1.40 +varying vec4 frag_colour2;
1.41 +varying vec4 frag_texcoord;
1.42
1.43 void main()
1.44 {
1.45 - vec4 tex = texture2D( primary_texture, gl_TexCoord[0].xy );
1.46 - if( gl_TexCoord[0].z >= 0.0 ) {
1.47 - tex = texture2D( palette_texture, vec2(gl_TexCoord[0].z + (tex.a*0.249023),0.5) );
1.48 + vec4 tex = texture2D( primary_texture, frag_texcoord.xy );
1.49 + if( frag_texcoord.z >= 0.0 ) {
1.50 + tex = texture2D( palette_texture, vec2(frag_texcoord.z + (tex.a*0.249023), 0.5) );
1.51 }
1.52 /* HACK: unfortunately we have to maintain compatibility with GLSL 1.20,
1.53 * which only supports varying float. So since we're propagating texcoord
1.54 * anyway, overload the last component to indicate texture mode.
1.55 */
1.56 - if( gl_TexCoord[0].w == 0.0 ) {
1.57 - gl_FragColor.rgb = mix( gl_Color.rgb * tex.rgb + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
1.58 - gl_FragColor.a = gl_Color.a * tex.a;
1.59 - } else if( gl_TexCoord[0].w >= 1.5 ) {
1.60 - gl_FragColor.rgb = mix( gl_Color.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
1.61 - gl_FragColor.a = gl_Color.a;
1.62 + vec3 main_colour;
1.63 + if( frag_texcoord.w == 0.0 ) {
1.64 + main_colour = frag_colour.rgb * tex.rgb + frag_colour2.rgb;
1.65 + gl_FragColor.a = frag_colour.a * tex.a;
1.66 + } else if( frag_texcoord.w >= 1.5 ) {
1.67 + main_colour = frag_colour.rgb;
1.68 + gl_FragColor.a = frag_colour.a;
1.69 } else {
1.70 - gl_FragColor.rgb = mix( mix(gl_Color.rgb,tex.rgb,tex.a) + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord);
1.71 - gl_FragColor.a = gl_Color.a;
1.72 + main_colour = mix(frag_colour.rgb,tex.rgb,tex.a) + frag_colour2.rgb;
1.73 + gl_FragColor.a = frag_colour.a;
1.74 }
1.75 - gl_FragDepth = gl_FragCoord.z;
1.76 + if( gl_FragColor.a < alpha_ref ) {
1.77 + discard;
1.78 + } else {
1.79 + if( frag_colour2.a >= 0.0 ) {
1.80 + gl_FragColor.rgb = mix( main_colour, fog_colour1, frag_colour2.a );
1.81 + } else {
1.82 + gl_FragColor.rgb = mix( main_colour, fog_colour2, -frag_colour2.a );
1.83 + }
1.84 + gl_FragDepth = gl_FragCoord.z;
1.85 + }
1.86 }
1.87
1.88 #program pvr2_shader = DEFAULT_VERTEX_SHADER DEFAULT_FRAGMENT_SHADER
1.89 -
.