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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines