Search
lxdream.org :: lxdream/src/pvr2/shaders.glsl :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/shaders.glsl
changeset 1140:7dc1c71ece76
prev1130:5f56fc931112
next1207:f7ca985659c6
author nkeynes
date Tue Oct 26 08:39:02 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change Implement fragment shader to support palette textures 'directly', and
therefore avoid having to reload all palette textures whenever the palette
changes.
file annotate diff log raw
1.1 --- a/src/pvr2/shaders.glsl Fri Sep 17 20:08:50 2010 +1000
1.2 +++ b/src/pvr2/shaders.glsl Tue Oct 26 08:39:02 2010 +1000
1.3 @@ -19,6 +19,52 @@
1.4 * GNU General Public License for more details.
1.5 */
1.6
1.7 +/**
1.8 + * Quick reference for predefined variables
1.9 +
1.10 + * Vertex shader input variables:
1.11 + * vec4 gl_Color;
1.12 + * vec4 gl_SecondaryColor;
1.13 + * vec3 gl_Normal;
1.14 + * vec4 gl_Vertex;
1.15 + * vec4 gl_MultiTexCoord0;
1.16 + * vec4 gl_MultiTexCoord1;
1.17 + * vec4 gl_MultiTexCoord2;
1.18 + * vec4 gl_MultiTexCoord3;
1.19 + * vec4 gl_MultiTexCoord4;
1.20 + * vec4 gl_MultiTexCoord5;
1.21 + * vec4 gl_MultiTexCoord6;
1.22 + * vec4 gl_MultiTexCoord7;
1.23 + * float gl_FogCoord;
1.24 + *
1.25 + * Vertex shader output variables:
1.26 + * vec4 gl_Position; // must be written to
1.27 + * float gl_PointSize; // may be written to
1.28 + * vec4 gl_ClipVertex; // may be written to
1.29 + * varying vec4 gl_FrontColor;
1.30 + * varying vec4 gl_BackColor;
1.31 + * varying vec4 gl_FrontSecondaryColor;
1.32 + * varying vec4 gl_BackSecondaryColor;
1.33 + * varying vec4 gl_TexCoord[]; // at most will be gl_MaxTextureCoords
1.34 + * varying float gl_FogFragCoord;
1.35 + *
1.36 + * Fragment shader input variables:
1.37 + * varying vec4 gl_Color;
1.38 + * varying vec4 gl_SecondaryColor;
1.39 + * varying vec4 gl_TexCoord[]; // at most will be gl_MaxTextureCoords
1.40 + * varying float gl_FogFragCoord;
1.41 + * varying vec2 gl_PointCoord;
1.42 + *
1.43 + * Fragme shader output variables:
1.44 + * vec4 gl_FragCoord;
1.45 + * bool gl_FrontFacing;
1.46 + * vec4 gl_FragColor;
1.47 + * vec4 gl_FragData[gl_MaxDrawBuffers];
1.48 + * float gl_FragDepth;
1.49 +
1.50 + */
1.51 +
1.52 +
1.53 #vertex DEFAULT_VERTEX_SHADER
1.54 void main()
1.55 {
1.56 @@ -32,11 +78,32 @@
1.57 }
1.58
1.59 #fragment DEFAULT_FRAGMENT_SHADER
1.60 +
1.61 +uniform sampler2D primary_texture;
1.62 +uniform sampler1D palette_texture;
1.63 +
1.64 void main()
1.65 {
1.66 - gl_FragColor = gl_Color;
1.67 + vec4 tex = texture2D( primary_texture, gl_TexCoord[0].xy );
1.68 + if( gl_TexCoord[0].z >= 0.0 ) {
1.69 + tex = texture1D( palette_texture, gl_TexCoord[0].z + (tex.a*0.249023) );
1.70 + }
1.71 + /* HACK: unfortunately we have to maintain compatibility with GLSL 1.20,
1.72 + * which only supports varying float. So since we're propagating texcoord
1.73 + * anyway, overload the last component to indicate texture mode.
1.74 + */
1.75 + if( gl_TexCoord[0].w == 0.0 ) {
1.76 + gl_FragColor.rgb = mix( gl_Color.rgb * tex.rgb + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
1.77 + gl_FragColor.a = gl_Color.a * tex.a;
1.78 + } else if( gl_TexCoord[0].w >= 1.5 ) {
1.79 + gl_FragColor.rgb = mix( gl_Color.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
1.80 + gl_FragColor.a = gl_Color.a;
1.81 + } else {
1.82 + gl_FragColor.rgb = mix( mix(gl_Color.rgb,tex.rgb,tex.a) + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord);
1.83 + gl_FragColor.a = gl_Color.a;
1.84 + }
1.85 gl_FragDepth = gl_FragCoord.z;
1.86 }
1.87
1.88 -#program DEFAULT_PROGRAM = DEFAULT_VERTEX_SHADER
1.89 +#program DEFAULT_PROGRAM = DEFAULT_VERTEX_SHADER DEFAULT_FRAGMENT_SHADER
1.90
.