implement biased texture functions
[mesa.git] / src / mesa / shader / slang / library / slang_fragment_builtin.gc
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2006 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25 //
26 // TODO:
27 // - implement dFdx, dFdy,
28 //
29
30 //
31 // From Shader Spec, ver. 1.10, rev. 59
32 //
33
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;
39
40 varying vec4 gl_Color;
41 varying vec4 gl_SecondaryColor;
42 varying vec4 gl_TexCoord[gl_MaxTextureCoords];
43 varying float gl_FogFragCoord;
44
45
46
47 //// 8.7 Texture Lookup Functions (with bias)
48
49 vec4 texture1D(const sampler1D sampler, const float coord, const float bias)
50 {
51 vec4 coord4;
52 coord4.x = coord;
53 coord4.w = bias;
54 __asm vec4_texb1d __retVal, sampler, coord4;
55 }
56
57 vec4 texture1DProj(const sampler1D sampler, const vec2 coord, const float bias)
58 {
59 // do projection here (there's no vec4_texbp1d instruction)
60 vec4 pcoord;
61 pcoord.x = coord.x / coord.y;
62 pcoord.w = bias;
63 __asm vec4_texb1d __retVal, sampler, pcoord;
64 }
65
66 vec4 texture1DProj(const sampler1D sampler, const vec4 coord, const float bias)
67 {
68 // do projection here (there's no vec4_texbp1d instruction)
69 vec4 pcoord;
70 pcoord.x = coord.x / coord.z;
71 pcoord.w = bias;
72 __asm vec4_texb1d __retVal, sampler, pcoord;
73 }
74
75
76 vec4 texture2D(const sampler2D sampler, const vec2 coord, const float bias)
77 {
78 vec4 coord4;
79 coord4.xy = coord.xy;
80 coord4.w = bias;
81 __asm vec4_texb2d __retVal, sampler, coord4;
82 }
83
84 vec4 texture2DProj(const sampler2D sampler, const vec3 coord, const float bias)
85 {
86 // do projection here (there's no vec4_texbp2d instruction)
87 vec4 pcoord;
88 pcoord.xy = coord.xy / coord.z;
89 pcoord.w = bias;
90 __asm vec4_texb2d __retVal, sampler, pcoord;
91 }
92
93 vec4 texture2DProj(const sampler2D sampler, const vec4 coord, const float bias)
94 {
95 // do projection here (there's no vec4_texbp2d instruction)
96 vec4 pcoord;
97 pcoord.xy = coord.xy / coord.w;
98 pcoord.w = bias;
99 __asm vec4_texb2d __retVal, sampler, pcoord;
100 }
101
102
103 vec4 texture3D(const sampler3D sampler, const vec3 coord, const float bias)
104 {
105 vec4 coord4;
106 coord4.xyz = coord.xyz;
107 coord4.w = bias;
108 __asm vec4_texb3d __retVal, sampler, coord4;
109 }
110
111 vec4 texture3DProj(const sampler3D sampler, const vec4 coord, const float bias)
112 {
113 // do projection here (there's no vec4_texbp3d instruction)
114 vec4 pcoord;
115 pcoord.xyz = coord.xyz / coord.w;
116 pcoord.w = bias;
117 __asm vec4_texb3d __retVal, sampler, pcoord;
118 }
119
120
121 vec4 textureCube(const samplerCube sampler, const vec3 coord, const float bias)
122 {
123 __asm vec4_texcube __retVal, sampler, coord, bias;
124 }
125
126
127 vec4 shadow1D(const sampler1DShadow sampler, const vec3 coord, const float bias)
128 {
129 __asm vec4_shad1d __retVal, sampler, coord, bias;
130 }
131
132 vec4 shadow1DProj(const sampler1DShadow sampler, const vec4 coord, const float bias)
133 {
134 return shadow1D (sampler, vec3 (coord.s / coord.q, 0.0, coord.p / coord.q), bias);
135 }
136
137 vec4 shadow2D(const sampler2DShadow sampler, const vec3 coord, const float bias)
138 {
139 __asm vec4_shad2d __retVal, sampler, coord, bias;
140 }
141
142 vec4 shadow2DProj(const sampler2DShadow sampler, const vec4 coord, const float bias)
143 {
144 return shadow2D (sampler, vec3 (coord.s / coord.q, coord.t / coord.q, coord.p / coord.q), bias);
145 }
146
147
148
149
150
151 //
152 // 8.8 Fragment Processing Functions
153 //
154
155 float dFdx (float p) {
156 // XXX:
157 return 0.001;
158 }
159
160 vec2 dFdx (vec2 p) {
161 // XXX:
162 return vec2 (0.001);
163 }
164
165 vec3 dFdx (vec3 p) {
166 // XXX:
167 return vec3 (0.001);
168 }
169
170 vec4 dFdx (vec4 p) {
171 // XXX:
172 return vec4 (0.001);
173 }
174
175 float dFdy (float p) {
176 // XXX:
177 return 0.001;
178 }
179
180 vec2 dFdy (vec2 p) {
181 // XXX:
182 return vec2 (0.001);
183 }
184
185 vec3 dFdy (vec3 p) {
186 // XXX:
187 return vec3 (0.001);
188 }
189
190 vec4 dFdy (vec4 p) {
191 // XXX:
192 return vec4 (0.001);
193 }
194
195 float fwidth (float p) {
196 return abs (dFdx (p)) + abs (dFdy (p));
197 }
198
199 vec2 fwidth (vec2 p) {
200 return abs (dFdx (p)) + abs (dFdy (p));
201 }
202
203 vec3 fwidth (vec3 p) {
204 return abs (dFdx (p)) + abs (dFdy (p));
205 }
206
207 vec4 fwidth (vec4 p) {
208 return abs (dFdx (p)) + abs (dFdy (p));
209 }
210