filename | src/pvr2/shaders.glsl |
changeset | 1221:f50407acc682 |
prev | 1207:f7ca985659c6 |
next | 1232:e5b12e2fe6ba |
author | nkeynes |
date | Mon Feb 13 22:16:43 2012 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Make palette textures 2D (1 pixel high) instead of 1D - pretty much the same, but some systems don't support 1D textures |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Assorted shader definitions (optionally) used by the PVR2 rendering
5 * engine.
6 *
7 * This file is preprocessed by genglsl to produce shaders.c and shaders.h.
8 *
9 * Copyright (c) 2007-2010 Nathan Keynes.
10 *
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.
15 *
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.
20 */
22 /**
23 * Quick reference for predefined variables
25 * Vertex shader input variables:
26 * vec4 gl_Color;
27 * vec4 gl_SecondaryColor;
28 * vec3 gl_Normal;
29 * vec4 gl_Vertex;
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;
38 * float gl_FogCoord;
39 *
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;
50 *
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;
57 *
58 * Fragme shader output variables:
59 * vec4 gl_FragCoord;
60 * bool gl_FrontFacing;
61 * vec4 gl_FragColor;
62 * vec4 gl_FragData[gl_MaxDrawBuffers];
63 * float gl_FragDepth;
65 */
68 #vertex DEFAULT_VERTEX_SHADER
69 void main()
70 {
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;
78 }
80 #fragment DEFAULT_FRAGMENT_SHADER
82 uniform sampler2D primary_texture;
83 uniform sampler2D palette_texture;
85 void main()
86 {
87 vec4 tex = texture2D( primary_texture, gl_TexCoord[0].xy );
88 if( gl_TexCoord[0].z >= 0.0 ) {
89 tex = texture2D( palette_texture, vec2(gl_TexCoord[0].z + (tex.a*0.249023),0.5) );
90 }
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.
94 */
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;
101 } else {
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;
104 }
105 gl_FragDepth = gl_FragCoord.z;
106 }
108 #program pvr2_shader = DEFAULT_VERTEX_SHADER DEFAULT_FRAGMENT_SHADER
.