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.
27 // - implement dFdx, dFdy,
31 // From Shader Spec, ver. 1.10, rev. 59
34 __fixed_input vec4 gl_FragCoord;
35 __fixed_input bool gl_FrontFacing;
36 __fixed_output vec4 gl_FragColor;
37 __fixed_output vec4 gl_FragData[gl_MaxDrawBuffers];
38 __fixed_output float gl_FragDepth;
40 varying vec4 gl_Color;
41 varying vec4 gl_SecondaryColor;
42 varying vec4 gl_TexCoord[gl_MaxTextureCoords];
43 varying float gl_FogFragCoord;
47 //// 8.7 Texture Lookup Functions (with bias)
49 vec4 texture1D(const sampler1D sampler, const float coord, const float bias)
54 __asm vec4_texb1d __retVal, sampler, coord4;
57 vec4 texture1DProj(const sampler1D sampler, const vec2 coord, const float bias)
59 // do projection here (there's no vec4_texbp1d instruction)
61 pcoord.x = coord.x / coord.y;
63 __asm vec4_texb1d __retVal, sampler, pcoord;
66 vec4 texture1DProj(const sampler1D sampler, const vec4 coord, const float bias)
68 // do projection here (there's no vec4_texbp1d instruction)
70 pcoord.x = coord.x / coord.z;
72 __asm vec4_texb1d __retVal, sampler, pcoord;
76 vec4 texture2D(const sampler2D sampler, const vec2 coord, const float bias)
81 __asm vec4_texb2d __retVal, sampler, coord4;
84 vec4 texture2DProj(const sampler2D sampler, const vec3 coord, const float bias)
86 // do projection here (there's no vec4_texbp2d instruction)
88 pcoord.xy = coord.xy / coord.z;
90 __asm vec4_texb2d __retVal, sampler, pcoord;
93 vec4 texture2DProj(const sampler2D sampler, const vec4 coord, const float bias)
95 // do projection here (there's no vec4_texbp2d instruction)
97 pcoord.xy = coord.xy / coord.w;
99 __asm vec4_texb2d __retVal, sampler, pcoord;
103 vec4 texture3D(const sampler3D sampler, const vec3 coord, const float bias)
106 coord4.xyz = coord.xyz;
108 __asm vec4_texb3d __retVal, sampler, coord4;
111 vec4 texture3DProj(const sampler3D sampler, const vec4 coord, const float bias)
113 // do projection here (there's no vec4_texbp3d instruction)
115 pcoord.xyz = coord.xyz / coord.w;
117 __asm vec4_texb3d __retVal, sampler, pcoord;
121 vec4 textureCube(const samplerCube sampler, const vec3 coord, const float bias)
123 __asm vec4_texcube __retVal, sampler, coord, bias;
127 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
129 __asm vec4_shad1d __retVal, sampler, coord, bias;
132 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
134 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q), bias);
137 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
139 __asm vec4_shad2d __retVal, sampler, coord, bias;
142 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
144 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q), bias);
152 // 8.8 Fragment Processing Functions
155 float dFdx (float p) {
175 float dFdy (float p) {
195 float fwidth (float p) {
196 return abs (dFdx (p)) + abs (dFdy (p));
199 vec2 fwidth (vec2 p) {
200 return abs (dFdx (p)) + abs (dFdy (p));
203 vec3 fwidth (vec3 p) {
204 return abs (dFdx (p)) + abs (dFdy (p));
207 vec4 fwidth (vec4 p) {
208 return abs (dFdx (p)) + abs (dFdy (p));