4 * Assorted shader definitions (optionally) used by the PVR2 rendering
7 * This file is preprocessed by genglsl to produce shaders.c and shaders.h.
9 * Copyright (c) 2007-2010 Nathan Keynes.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 * Quick reference for predefined variables
25 * Vertex shader input variables:
27 * vec4 gl_SecondaryColor;
30 * vec4 gl_MultiTexCoord0;
31 * vec4 gl_MultiTexCoord1;
32 * vec4 gl_MultiTexCoord2;
33 * vec4 gl_MultiTexCoord3;
34 * vec4 gl_MultiTexCoord4;
35 * vec4 gl_MultiTexCoord5;
36 * vec4 gl_MultiTexCoord6;
37 * vec4 gl_MultiTexCoord7;
40 * Vertex shader output variables:
41 * vec4 gl_Position; // must be written to
42 * float gl_PointSize; // may be written to
43 * vec4 gl_ClipVertex; // may be written to
44 * varying vec4 gl_FrontColor;
45 * varying vec4 gl_BackColor;
46 * varying vec4 gl_FrontSecondaryColor;
47 * varying vec4 gl_BackSecondaryColor;
48 * varying vec4 gl_TexCoord[]; // at most will be gl_MaxTextureCoords
49 * varying float gl_FogFragCoord;
51 * Fragment shader input variables:
52 * varying vec4 gl_Color;
53 * varying vec4 gl_SecondaryColor;
54 * varying vec4 gl_TexCoord[]; // at most will be gl_MaxTextureCoords
55 * varying float gl_FogFragCoord;
56 * varying vec2 gl_PointCoord;
58 * Fragme shader output variables:
60 * bool gl_FrontFacing;
62 * vec4 gl_FragData[gl_MaxDrawBuffers];
68 #vertex DEFAULT_VERTEX_SHADER
71 vec4 tmp = ftransform();
72 float w = gl_Vertex.z;
73 gl_Position = tmp * w;
74 gl_FrontColor = gl_Color;
75 gl_FrontSecondaryColor = gl_SecondaryColor;
76 gl_TexCoord[0] = gl_MultiTexCoord0;
77 gl_FogFragCoord = gl_FogCoord;
80 #fragment DEFAULT_FRAGMENT_SHADER
82 uniform sampler2D primary_texture;
83 uniform sampler1D palette_texture;
87 vec4 tex = texture2D( primary_texture, gl_TexCoord[0].xy );
88 if( gl_TexCoord[0].z >= 0.0 ) {
89 tex = texture1D( palette_texture, gl_TexCoord[0].z + (tex.a*0.249023) );
91 /* HACK: unfortunately we have to maintain compatibility with GLSL 1.20,
92 * which only supports varying float. So since we're propagating texcoord
93 * anyway, overload the last component to indicate texture mode.
95 if( gl_TexCoord[0].w == 0.0 ) {
96 gl_FragColor.rgb = mix( gl_Color.rgb * tex.rgb + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
97 gl_FragColor.a = gl_Color.a * tex.a;
98 } else if( gl_TexCoord[0].w >= 1.5 ) {
99 gl_FragColor.rgb = mix( gl_Color.rgb, gl_Fog.color.rgb, gl_FogFragCoord );
100 gl_FragColor.a = gl_Color.a;
102 gl_FragColor.rgb = mix( mix(gl_Color.rgb,tex.rgb,tex.a) + gl_SecondaryColor.rgb, gl_Fog.color.rgb, gl_FogFragCoord);
103 gl_FragColor.a = gl_Color.a;
105 gl_FragDepth = gl_FragCoord.z;
108 #program DEFAULT_PROGRAM = DEFAULT_VERTEX_SHADER DEFAULT_FRAGMENT_SHADER
.