2 * Mesa 3-D graphics library
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // From Shader Spec, ver. 1.10, rev. 59
29 __fixed_input vec4 gl_FragCoord;
30 __fixed_input bool gl_FrontFacing;
31 __fixed_output vec4 gl_FragColor;
32 __fixed_output vec4 gl_FragData[gl_MaxDrawBuffers];
33 __fixed_output float gl_FragDepth;
35 varying vec4 gl_Color;
36 varying vec4 gl_SecondaryColor;
37 varying vec4 gl_TexCoord[gl_MaxTextureCoords];
38 varying float gl_FogFragCoord;
42 //// 8.7 Texture Lookup Functions (with bias)
44 vec4 texture1D(const sampler1D sampler, const float coord, const float bias)
49 __asm vec4_texb1d __retVal, sampler, coord4;
52 vec4 texture1DProj(const sampler1D sampler, const vec2 coord, const float bias)
54 // do projection here (there's no vec4_texbp1d instruction)
56 pcoord.x = coord.x / coord.y;
58 __asm vec4_texb1d __retVal, sampler, pcoord;
61 vec4 texture1DProj(const sampler1D sampler, const vec4 coord, const float bias)
63 // do projection here (there's no vec4_texbp1d instruction)
65 pcoord.x = coord.x / coord.z;
67 __asm vec4_texb1d __retVal, sampler, pcoord;
71 vec4 texture2D(const sampler2D sampler, const vec2 coord, const float bias)
76 __asm vec4_texb2d __retVal, sampler, coord4;
79 vec4 texture2DProj(const sampler2D sampler, const vec3 coord, const float bias)
81 // do projection here (there's no vec4_texbp2d instruction)
83 pcoord.xy = coord.xy / coord.z;
85 __asm vec4_texb2d __retVal, sampler, pcoord;
88 vec4 texture2DProj(const sampler2D sampler, const vec4 coord, const float bias)
90 // do projection here (there's no vec4_texbp2d instruction)
92 pcoord.xy = coord.xy / coord.w;
94 __asm vec4_texb2d __retVal, sampler, pcoord;
98 vec4 texture3D(const sampler3D sampler, const vec3 coord, const float bias)
101 coord4.xyz = coord.xyz;
103 __asm vec4_texb3d __retVal, sampler, coord4;
106 vec4 texture3DProj(const sampler3D sampler, const vec4 coord, const float bias)
108 // do projection here (there's no vec4_texbp3d instruction)
110 pcoord.xyz = coord.xyz / coord.w;
112 __asm vec4_texb3d __retVal, sampler, pcoord;
116 vec4 textureCube(const samplerCube sampler, const vec3 coord, const float bias)
121 __asm vec4_texcube __retVal, sampler, coord4;
125 // For shadow textures, we use the regular tex instructions since they should
126 // do the depth comparison step.
128 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
133 __asm vec4_texb1d __retVal, sampler, coord4;
136 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
139 pcoord.x = coord.x / coord.w;
142 __asm vec4_texb1d __retVal, sampler, pcoord;
145 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
150 __asm vec4_texb2d __retVal, sampler, coord4;
153 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
156 pcoord.xy = coord.xy / coord.w;
159 __asm vec4_texb2d __retVal, sampler, pcoord;
167 // 8.8 Fragment Processing Functions
170 float dFdx(const float p)
172 __asm vec4_ddx __retVal.x, p.xxxx;
175 vec2 dFdx(const vec2 p)
177 __asm vec4_ddx __retVal.xy, p.xyyy;
180 vec3 dFdx(const vec3 p)
182 __asm vec4_ddx __retVal.xyz, p.xyzz;
185 vec4 dFdx(const vec4 p)
187 __asm vec4_ddx __retVal, p;
190 float dFdy(const float p)
192 __asm vec4_ddy __retVal.x, p.xxxx;
195 vec2 dFdy(const vec2 p)
197 __asm vec4_ddy __retVal.xy, p.xyyy;
200 vec3 dFdy(const vec3 p)
202 __asm vec4_ddy __retVal.xyz, p.xyzz;
205 vec4 dFdy(const vec4 p)
207 __asm vec4_ddy __retVal, p;
210 float fwidth (const float p)
212 // XXX hand-write with __asm
213 return abs(dFdx(p)) + abs(dFdy(p));
216 vec2 fwidth(const vec2 p)
218 // XXX hand-write with __asm
219 return abs(dFdx(p)) + abs(dFdy(p));
222 vec3 fwidth(const vec3 p)
224 // XXX hand-write with __asm
225 return abs(dFdx(p)) + abs(dFdy(p));
228 vec4 fwidth(const vec4 p)
230 // XXX hand-write with __asm
231 return abs(dFdx(p)) + abs(dFdy(p));