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.47 by root, Sun Nov 7 03:01:03 2004 UTC vs.
Revision 1.53 by root, Fri Dec 10 05:37:09 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 temp_1f lz; 93 temp_1f lz;
94 94
95 // TODO: negative z is not calculated in an acceptable way 95 // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?)
96 lz = z (vout.position); 96 lz = z (vout.position);
97 lz = ifelse (lz <= 0,
98 0,
99 log (lz + 1) / log (1e18)
100 ) - 1;
97 z (vout.position) = (log2 (lz) * (2 / log2 (1e10)) - 1) * w (vout.position); 101 z (vout.position) = lz * w (vout.position);
98#if 0
99 z (vout.position) =
100 ifelse (
101 z < 0,
102 -1,
103 log2 (lz) * (2 / log2 (1e10)) - 1
104 ) * w (vout.position);
105#endif
106 } 102 }
107 103
108 vsh_src = shader::shader_builder::stop (); 104 vsh_src = shader::shader_builder::stop ();
109 105
110 shader::shader_builder::start (); 106 shader::shader_builder::start ();
111 107
112 if (ctx.pass_data->l) 108 if (ctx.pass->l)
113 { 109 {
114 ctx.pass_data->l->fsh (); 110 ctx.pass->l->fsh ();
115
116 fsh (ctx); 111 fsh (ctx);
117 } 112 }
118 else 113 else
114 // many drivers need both vertex and fragment shader, 'caboom!' otherwise
119 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.); 115 shader::compile::fout.frag_color = shader::compile::float4 (0., 0., 0., 0.);
120 116
121 fsh_src = shader::shader_builder::stop (); 117 fsh_src = shader::shader_builder::stop ();
122 118
123 shader::program_object po = shader::get_program (vsh_src, fsh_src); 119 shader::program_object po = shader::get_program (vsh_src, fsh_src);
124 matmap.insert (pass::matmap_t::value_type (this, po)); 120 matmap.insert (pass_data::matmap_t::value_type (this, po));
125 121
126 po->enable (); 122 po->enable ();
127 } 123 }
128 else 124 else
129 i->second->enable (); 125 i->second->enable ();
130 126
131 if (ctx.pass_data->l) 127 if (ctx.pass->l)
132 ctx.pass_data->l->enable (); 128 ctx.pass->l->enable ();
133} 129}
134 130
135void material::disable (view &ctx) 131void material::disable (view &ctx)
136{ 132{
137} 133}
150{ 146{
151 using namespace shader::compile; 147 using namespace shader::compile;
152 148
153 std_vsh (); 149 std_vsh ();
154 150
155 if (ctx.pass_data->l) 151 if (ctx.pass->l)
156 { 152 {
157 texcoord = xy (vin.tex_coord[0]); 153 texcoord = xy (vin.tex_coord[0]);
158 normal = normal_matrix * vin.normal; 154 normal = normal_matrix * vin.normal;
159 } 155 }
160} 156}
161 157
162void test_material::fsh (view &ctx) 158void test_material::fsh (view &ctx)
163{ 159{
164 using namespace shader::compile; 160 using namespace shader::compile;
165 161
166 if (ctx.pass_data->l) 162 if (ctx.pass->l)
167 { 163 {
168 temp_3f lc; 164 temp_3f lc;
169 temp_1f fac; 165 temp_1f fac;
170 166
171 temp_3f rot1, rot2, rot3; 167 temp_3f rot1, rot2, rot3;
177 rot2 = float3 (x(rot1), z(rot1), -y(rot1)); 173 rot2 = float3 (x(rot1), z(rot1), -y(rot1));
178 rot3 = float3 (y(rot1), -x(rot1), z(rot1)); 174 rot3 = float3 (y(rot1), -x(rot1), z(rot1));
179 175
180 normal = mat3 (rot1, rot2, rot3) * normal; 176 normal = mat3 (rot1, rot2, rot3) * normal;
181 177
182 fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec)); 178 fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec));
183 fac = max (pow (max (fac, 0.0), 6), 0.3); 179 fac = max (pow (max (fac, 0.0), 6), 0.3);
184 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac 180 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac
185 * ctx.pass_data->l->sh_colour; 181 * ctx.pass->l->sh_colour;
186 //xyz (fout.frag_color) = lc * fac; 182 //xyz (fout.frag_color) = lc * fac;
187 } 183 }
188} 184}
189 185
190void test_material::enable (view &ctx) 186void test_material::enable (view &ctx)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines