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.59 by root, Tue Feb 8 05:55:28 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 ((GLfloat) ((int)timer::now % 100)); 142 time->set (timer::now);
151 sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); 143 sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F));
152} 144}
153 145
154void mat_timed::disable (view &ctx) 146void mat_timed::disable (view &ctx)
155{ 147{
170 using namespace shader::compile; 162 using namespace shader::compile;
171 163
172 if (ctx.pass->l) 164 if (ctx.pass->l)
173 { 165 {
174 temp_1f fac; 166 temp_1f fac;
167 temp_3f normal;
175 168
169 normal = f_normal + 0.3 * pow (sin (f_normal * 3.14159 + time), 3);
170
176 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); 171 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec));
177 172
178 //fac = (fac / 100) * (mod (time, 100)) ;
179 fac = time;
180
181 xyz (fout.frag_color) = float3 ((255/100) * fac, fac, fac);//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;
182 } 174 }
183} 175}
184 176
185void mat_gouraud_shaded::enable (view &ctx) 177void mat_gouraud_shaded::enable (view &ctx)
186{ 178{
212 temp_1f fac; 204 temp_1f fac;
213 205
214 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); 206 fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec));
215 207
216 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;
217 } 252 }
218} 253}
219 254
220static shader::varying_2f texcoord; 255static shader::varying_2f texcoord;
221static shader::varying_3f normal; 256static shader::varying_3f normal;
276} 311}
277 312
278test_material *testmat; 313test_material *testmat;
279mat_gouraud_shaded *testmat2; 314mat_gouraud_shaded *testmat2;
280mat_timed *testmat3; 315mat_timed *testmat3;
316mat_debug *debugmat;
281 317

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines