--- libgender/material.C 2004/12/10 05:37:09 1.53 +++ libgender/material.C 2005/02/11 14:54:55 1.60 @@ -57,8 +57,7 @@ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glTexImage2D (GL_TEXTURE_2D, - 0, + glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels); SDL_FreeSurface (image); /* No longer needed */ @@ -94,10 +93,14 @@ // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?) lz = z (vout.position); +#if 0 + lz = (log (max (lz, 0) + 1) / log (1e30)) - 1; +#else lz = ifelse (lz <= 0, 0, - log (lz + 1) / log (1e18) + log (lz + 1) / log (1e30) ) - 1; +#endif z (vout.position) = lz * w (vout.position); } @@ -125,7 +128,7 @@ i->second->enable (); if (ctx.pass->l) - ctx.pass->l->enable (); + ctx.pass->l->enable (ctx); } void material::disable (view &ctx) @@ -139,8 +142,83 @@ { } -static shader::varying_3f normal; + +void mat_timed::enable (view &ctx) +{ + material::enable (ctx); + + time->set (timer::now - (int)timer::now); + sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); +} + +void mat_timed::disable (view &ctx) +{ + material::disable (ctx); +} + +void mat_timed::vsh (view &ctx) +{ + using namespace shader::compile; + std_vsh (); + + if (ctx.pass->l) + f_normal = normal_matrix * vin.normal; +} + +void mat_timed::fsh (view &ctx) +{ + using namespace shader::compile; + + if (ctx.pass->l) + { + temp_1f fac; + + fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); + + //fac = (fac / 100) * (mod (time, 100)) ; + fac = time; + + xyz (fout.frag_color) = sin (time * 3.14159265*2);//ctx.pass->l->sh_colour * sh_colour * fac; + } +} + +void mat_gouraud_shaded::enable (view &ctx) +{ + material::enable (ctx); + + sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); +} + +void mat_gouraud_shaded::disable (view &ctx) +{ + material::disable (ctx); +} + +void mat_gouraud_shaded::vsh (view &ctx) +{ + using namespace shader::compile; + std_vsh (); + + if (ctx.pass->l) + f_normal = normal_matrix * vin.normal; +} + +void mat_gouraud_shaded::fsh (view &ctx) +{ + using namespace shader::compile; + + if (ctx.pass->l) + { + temp_1f fac; + + fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); + + xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; + } +} + static shader::varying_2f texcoord; +static shader::varying_3f normal; void test_material::vsh (view &ctx) { @@ -198,4 +276,6 @@ } test_material *testmat; +mat_gouraud_shaded *testmat2; +mat_timed *testmat3;