ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.C
(Generate patch)

Comparing libgender/material.C (file contents):
Revision 1.45 by root, Sun Nov 7 02:28:18 2004 UTC vs.
Revision 1.50 by root, Sun Nov 7 22:40:58 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 // compute logarithmic depth - see the frustum matrix in view.C
90 { 90 {
91 using namespace shader::compile; 91 using namespace shader::compile;
92 92
93 z (vout.position) = (log2 (max (z (vout.position), 0)) * (2 / log2 (1e10)) - 1) * 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) = (ifelse (
98 lz < 0,
99 lz,
100 log (lz) * (2 / log (1e10))
101 ) - 1) * w (vout.position);
94 } 102 }
95 103
96 vsh_src = shader::shader_builder::stop (); 104 vsh_src = shader::shader_builder::stop ();
97 105
98 shader::shader_builder::start (); 106 shader::shader_builder::start ();
99 107
100 if (ctx.pass_data->l) 108 if (ctx.pass->l)
101 { 109 {
102 ctx.pass_data->l->fsh (); 110 ctx.pass->l->fsh ();
103 111
104 fsh (ctx); 112 fsh (ctx);
105 } 113 }
106 else 114 else
107 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.); 115 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.);
108 116
109 {
110 using namespace shader::compile;
111 //x (fout.frag_color) = Z;//D
112 //y (fout.frag_color) = Z;//D
113 //z (fout.frag_color) = Z;//D
114 }
115
116 fsh_src = shader::shader_builder::stop (); 117 fsh_src = shader::shader_builder::stop ();
117 118
118 shader::program_object po = shader::get_program (vsh_src, fsh_src); 119 shader::program_object po = shader::get_program (vsh_src, fsh_src);
119 matmap.insert (pass::matmap_t::value_type (this, po)); 120 matmap.insert (pass_data::matmap_t::value_type (this, po));
120 121
121 po->enable (); 122 po->enable ();
122 } 123 }
123 else 124 else
124 i->second->enable (); 125 i->second->enable ();
125 126
126 if (ctx.pass_data->l) 127 if (ctx.pass->l)
127 ctx.pass_data->l->enable (); 128 ctx.pass->l->enable ();
128} 129}
129 130
130void material::disable (view &ctx) 131void material::disable (view &ctx)
131{ 132{
132} 133}
145{ 146{
146 using namespace shader::compile; 147 using namespace shader::compile;
147 148
148 std_vsh (); 149 std_vsh ();
149 150
150 if (ctx.pass_data->l) 151 if (ctx.pass->l)
151 { 152 {
152 texcoord = xy (vin.tex_coord[0]); 153 texcoord = xy (vin.tex_coord[0]);
153 normal = normal_matrix * vin.normal; 154 normal = normal_matrix * vin.normal;
154 } 155 }
155} 156}
156 157
157void test_material::fsh (view &ctx) 158void test_material::fsh (view &ctx)
158{ 159{
159 using namespace shader::compile; 160 using namespace shader::compile;
160 161
161 if (ctx.pass_data->l) 162 if (ctx.pass->l)
162 { 163 {
163 temp_3f lc; 164 temp_3f lc;
164 temp_1f fac; 165 temp_1f fac;
165 166
166 temp_3f rot1, rot2, rot3; 167 temp_3f rot1, rot2, rot3;
172 rot2 = float3 (x(rot1), z(rot1), -y(rot1)); 173 rot2 = float3 (x(rot1), z(rot1), -y(rot1));
173 rot3 = float3 (y(rot1), -x(rot1), z(rot1)); 174 rot3 = float3 (y(rot1), -x(rot1), z(rot1));
174 175
175 normal = mat3 (rot1, rot2, rot3) * normal; 176 normal = mat3 (rot1, rot2, rot3) * normal;
176 177
177 fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec)); 178 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec));
178 fac = max (pow (max (fac, 0.0), 6), 0.3); 179 fac = max (pow (max (fac, 0.0), 6), 0.3);
179 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac 180 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac
180 * ctx.pass_data->l->sh_colour; 181 * ctx.pass->l->sh_colour;
181 //xyz (fout.frag_color) = lc * fac; 182 //xyz (fout.frag_color) = lc * fac;
182 } 183 }
183} 184}
184 185
185void test_material::enable (view &ctx) 186void test_material::enable (view &ctx)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines