--- libgender/material.C 2005/02/07 08:16:31 1.57 +++ libgender/material.C 2005/02/11 15:17:47 1.61 @@ -142,32 +142,89 @@ { } -static shader::varying_3f normal; -static shader::varying_2f texcoord; -void test_material2::vsh (view &ctx) +void mat_timed::enable (view &ctx) +{ + material::enable (ctx); + + time->set (timer::now); + sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); +} + +void mat_timed::disable (view &ctx) +{ + material::disable (ctx); +} + +shader::varying_3f fish; + +void mat_timed::vsh (view &ctx) { using namespace shader::compile; std_vsh (); if (ctx.pass->l) + { + f_normal = normal_matrix * vin.normal; + fish = xyz(vin.vertex) + zxy (vin.vertex) * 0.2; + } +} + +void mat_timed::fsh (view &ctx) +{ + using namespace shader::compile; + + if (ctx.pass->l) { - normal = normal_matrix * vin.normal; + temp_1f fac; + temp_3f normal; + + normal = f_normal + 0.3 * pow (sin (fish * 0.1 + float3 (time * 2, time * 3.14, time * 1.55)), 3); + + fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); + + xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; } } -void test_material2::fsh (view &ctx) +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 (normal), normalize (ctx.pass->l->sh_lightvec)); - xyz (fout.frag_color) = ctx.pass->l->sh_colour * fac;//normalize (ctx.pass->l->sh_lightvec); + + 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) { using namespace shader::compile; @@ -224,5 +281,6 @@ } test_material *testmat; -test_material2 *testmat2; +mat_gouraud_shaded *testmat2; +mat_timed *testmat3;