ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/material.C
(Generate patch)

Comparing cvsroot/libgender/material.C (file contents):
Revision 1.61 by root, Fri Feb 11 15:17:47 2005 UTC vs.
Revision 1.64 by root, Mon Jul 18 04:28:40 2005 UTC

89 { 89 {
90 using namespace shader::compile; 90 using namespace shader::compile;
91 91
92 temp_1f lz; 92 temp_1f lz;
93 93
94 // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?) 94 // TODO: negative z is not calculated in an a very acceptable way
95 lz = z (vout.position); 95 lz = z (vout.position);
96#if 0 96 lz = sign (lz) * (log (abs (lz) + exp (1e0)) - 1e0) / log (1e30);
97 lz = (log (max (lz, 0) + 1) / log (1e30)) - 1;
98#else
99 lz = ifelse (lz <= 0,
100 0,
101 log (lz + 1) / log (1e30)
102 ) - 1;
103#endif
104 z (vout.position) = lz * w (vout.position); 97 z (vout.position) = lz * w (vout.position);
105 } 98 }
106 99
107 vsh_src = shader::shader_builder::stop (); 100 vsh_src = shader::shader_builder::stop ();
108 101
140: tex ("textures/rockwall.jpg"), texvar (tex.name) 133: tex ("textures/rockwall.jpg"), texvar (tex.name)
141, norm ("textures/rockwall_normal.jpg"), normvar (norm.name) 134, norm ("textures/rockwall_normal.jpg"), normvar (norm.name)
142{ 135{
143} 136}
144 137
145
146void mat_timed::enable (view &ctx) 138void mat_timed::enable (view &ctx)
147{ 139{
148 material::enable (ctx); 140 material::enable (ctx);
149 141
150 time->set (timer::now); 142 time->set (timer::now);
154void mat_timed::disable (view &ctx) 146void mat_timed::disable (view &ctx)
155{ 147{
156 material::disable (ctx); 148 material::disable (ctx);
157} 149}
158 150
159shader::varying_3f fish;
160
161void mat_timed::vsh (view &ctx) 151void mat_timed::vsh (view &ctx)
162{ 152{
163 using namespace shader::compile; 153 using namespace shader::compile;
164 std_vsh (); 154 std_vsh ();
165 155
166 if (ctx.pass->l) 156 if (ctx.pass->l)
167 {
168 f_normal = normal_matrix * vin.normal; 157 f_normal = normal_matrix * vin.normal;
169 fish = xyz(vin.vertex) + zxy (vin.vertex) * 0.2;
170 }
171} 158}
172 159
173void mat_timed::fsh (view &ctx) 160void mat_timed::fsh (view &ctx)
174{ 161{
175 using namespace shader::compile; 162 using namespace shader::compile;
177 if (ctx.pass->l) 164 if (ctx.pass->l)
178 { 165 {
179 temp_1f fac; 166 temp_1f fac;
180 temp_3f normal; 167 temp_3f normal;
181 168
182 normal = f_normal + 0.3 * pow (sin (fish * 0.1 + float3 (time * 2, time * 3.14, time * 1.55)), 3); 169 normal = f_normal + 0.3 * pow (sin (f_normal * 3.14159 + time), 3);
183 170
184 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); 171 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec));
185 172
186 xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; 173 xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac;
187 } 174 }
217 temp_1f fac; 204 temp_1f fac;
218 205
219 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); 206 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec));
220 207
221 xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; 208 xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac;
209 }
210}
211
212static shader::varying_3f f_normal;
213
214void mat_debug::enable (view &ctx)
215{
216 material::enable (ctx);
217
218 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
219 glEnable (GL_BLEND);
220 glDepthMask (1);
221}
222
223void mat_debug::disable (view &ctx)
224{
225 material::disable (ctx);
226
227 glDisable (GL_BLEND);
228 glDepthMask (0);
229}
230
231void mat_debug::vsh (view &ctx)
232{
233 using namespace shader::compile;
234 std_vsh ();
235
236 if (ctx.pass->l)
237 f_normal = normal_matrix * vin.normal;
238}
239
240void mat_debug::fsh (view &ctx)
241{
242 using namespace shader::compile;
243
244 if (ctx.pass->l)
245 {
246 temp_1f fac;
247
248 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec));
249
250 xyz (fout.frag_color) = float3 (1.,0.,0.);
251 w (fout.frag_color) = 0.1;
222 } 252 }
223} 253}
224 254
225static shader::varying_2f texcoord; 255static shader::varying_2f texcoord;
226static shader::varying_3f normal; 256static shader::varying_3f normal;
281} 311}
282 312
283test_material *testmat; 313test_material *testmat;
284mat_gouraud_shaded *testmat2; 314mat_gouraud_shaded *testmat2;
285mat_timed *testmat3; 315mat_timed *testmat3;
316mat_debug *debugmat;
286 317

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines