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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines