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.41 by root, Sat Nov 6 01:56:20 2004 UTC vs.
Revision 1.51 by root, Fri Nov 26 03:48:40 2004 UTC

69{ 69{
70} 70}
71 71
72void material::enable (view &ctx) 72void material::enable (view &ctx)
73{ 73{
74 pass::matmap_t &matmap = ctx.pass_data->matmap; 74 pass_data::matmap_t &matmap = ctx.pass->matmap;
75 75
76 pass::matmap_t::iterator i = matmap.find (this); 76 pass_data::matmap_t::iterator i = matmap.find (this);
77 77
78 if (i == matmap.end ()) 78 if (i == matmap.end ())
79 { 79 {
80 string vsh_src, fsh_src; 80 string vsh_src, fsh_src;
81 81
82 shader::shader_builder::start (); 82 shader::shader_builder::start ();
83 83
84 if (ctx.pass_data->l) 84 if (ctx.pass->l)
85 ctx.pass_data->l->vsh (); 85 ctx.pass->l->vsh ();
86 86
87 vsh (ctx); 87 vsh (ctx);
88 88
89 // compute logarithmic depth - see the frustum matrix in view.C
89 { 90 {
90 using namespace shader::compile; 91 using namespace shader::compile;
91 92
92 //z (vout.position) = log2 (z (vout.position) / w (vout.position)) * w (vout.position); 93 temp_1f lz;
94
95 // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?)
96 lz = z (vout.position);
97 z (vout.position) = clamp (
98 ifelse (lz <= 0,
99 lz,
100 log (lz + 1) * (2 / log (1e10))
101 ) - 1,
102 -1.F, +1.F
103 ) * w (vout.position);
93 } 104 }
94 105
95 vsh_src = shader::shader_builder::stop (); 106 vsh_src = shader::shader_builder::stop ();
96 107
97 shader::shader_builder::start (); 108 shader::shader_builder::start ();
98 109
99 if (ctx.pass_data->l) 110 if (ctx.pass->l)
100 { 111 {
101 ctx.pass_data->l->fsh (); 112 ctx.pass->l->fsh ();
102 113
103 fsh (ctx); 114 fsh (ctx);
104 } 115 }
105 else 116 else
106 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.); 117 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.);
107 118
108 fsh_src = shader::shader_builder::stop (); 119 fsh_src = shader::shader_builder::stop ();
109 120
110 shader::program_object po = shader::get_program (vsh_src, fsh_src); 121 shader::program_object po = shader::get_program (vsh_src, fsh_src);
111 matmap.insert (pass::matmap_t::value_type (this, po)); 122 matmap.insert (pass_data::matmap_t::value_type (this, po));
112 123
113 po->enable (); 124 po->enable ();
114 } 125 }
115 else 126 else
116 i->second->enable (); 127 i->second->enable ();
128
129 if (ctx.pass->l)
130 ctx.pass->l->enable ();
117} 131}
118 132
119void material::disable (view &ctx) 133void material::disable (view &ctx)
120{ 134{
121} 135}
134{ 148{
135 using namespace shader::compile; 149 using namespace shader::compile;
136 150
137 std_vsh (); 151 std_vsh ();
138 152
139 if (ctx.pass_data->l) 153 if (ctx.pass->l)
140 { 154 {
141 texcoord = xy (vin.tex_coord[0]); 155 texcoord = xy (vin.tex_coord[0]);
142 normal = normal_matrix * vin.normal; 156 normal = normal_matrix * vin.normal;
143 } 157 }
144} 158}
145 159
146void test_material::fsh (view &ctx) 160void test_material::fsh (view &ctx)
147{ 161{
148 using namespace shader::compile; 162 using namespace shader::compile;
149 163
150 if (ctx.pass_data->l) 164 if (ctx.pass->l)
151 { 165 {
152 temp_3f lc; 166 temp_3f lc;
153 temp_1f fac; 167 temp_1f fac;
154 168
155 temp_3f rot1, rot2, rot3; 169 temp_3f rot1, rot2, rot3;
161 rot2 = float3 (x(rot1), z(rot1), -y(rot1)); 175 rot2 = float3 (x(rot1), z(rot1), -y(rot1));
162 rot3 = float3 (y(rot1), -x(rot1), z(rot1)); 176 rot3 = float3 (y(rot1), -x(rot1), z(rot1));
163 177
164 normal = mat3 (rot1, rot2, rot3) * normal; 178 normal = mat3 (rot1, rot2, rot3) * normal;
165 179
166 fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec)); 180 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec));
167 fac = max (pow (max (fac, 0.0), 6), 0.3); 181 fac = max (pow (max (fac, 0.0), 6), 0.3);
168 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac 182 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac
169 * ctx.pass_data->l->sh_colour; 183 * ctx.pass->l->sh_colour;
170 //xyz (fout.frag_color) = lc * fac; 184 //xyz (fout.frag_color) = lc * fac;
171 } 185 }
172} 186}
173 187
174void test_material::enable (view &ctx) 188void test_material::enable (view &ctx)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines