--- libgender/material.C 2004/11/07 02:28:18 1.45 +++ libgender/material.C 2004/11/07 22:40:58 1.50 @@ -71,9 +71,9 @@ void material::enable (view &ctx) { - pass::matmap_t &matmap = ctx.pass_data->matmap; + pass_data::matmap_t &matmap = ctx.pass->matmap; - pass::matmap_t::iterator i = matmap.find (this); + pass_data::matmap_t::iterator i = matmap.find (this); if (i == matmap.end ()) { @@ -81,8 +81,8 @@ shader::shader_builder::start (); - if (ctx.pass_data->l) - ctx.pass_data->l->vsh (); + if (ctx.pass->l) + ctx.pass->l->vsh (); vsh (ctx); @@ -90,41 +90,42 @@ { using namespace shader::compile; - z (vout.position) = (log2 (max (z (vout.position), 0)) * (2 / log2 (1e10)) - 1) * w (vout.position); + temp_1f lz; + + // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?) + lz = z (vout.position); + z (vout.position) = (ifelse ( + lz < 0, + lz, + log (lz) * (2 / log (1e10)) + ) - 1) * w (vout.position); } vsh_src = shader::shader_builder::stop (); shader::shader_builder::start (); - if (ctx.pass_data->l) + if (ctx.pass->l) { - ctx.pass_data->l->fsh (); + ctx.pass->l->fsh (); fsh (ctx); } else shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.); - { - using namespace shader::compile; - //x (fout.frag_color) = Z;//D - //y (fout.frag_color) = Z;//D - //z (fout.frag_color) = Z;//D - } - fsh_src = shader::shader_builder::stop (); shader::program_object po = shader::get_program (vsh_src, fsh_src); - matmap.insert (pass::matmap_t::value_type (this, po)); + matmap.insert (pass_data::matmap_t::value_type (this, po)); po->enable (); } else i->second->enable (); - if (ctx.pass_data->l) - ctx.pass_data->l->enable (); + if (ctx.pass->l) + ctx.pass->l->enable (); } void material::disable (view &ctx) @@ -147,7 +148,7 @@ std_vsh (); - if (ctx.pass_data->l) + if (ctx.pass->l) { texcoord = xy (vin.tex_coord[0]); normal = normal_matrix * vin.normal; @@ -158,7 +159,7 @@ { using namespace shader::compile; - if (ctx.pass_data->l) + if (ctx.pass->l) { temp_3f lc; temp_1f fac; @@ -174,10 +175,10 @@ normal = mat3 (rot1, rot2, rot3) * normal; - fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec)); + fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); fac = max (pow (max (fac, 0.0), 6), 0.3); xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac - * ctx.pass_data->l->sh_colour; + * ctx.pass->l->sh_colour; //xyz (fout.frag_color) = lc * fac; } }