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.39 by root, Fri Nov 5 19:55:15 2004 UTC vs.
Revision 1.46 by root, Sun Nov 7 02:36:38 2004 UTC

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 vsh (ctx);
84 83
85 if (ctx.pass_data->l) 84 if (ctx.pass_data->l)
86 ctx.pass_data->l->vsh (); 85 ctx.pass_data->l->vsh ();
87 86
87 vsh (ctx);
88
89 // compute logarithmic depth - see the frustum matrix in view.C
88 { 90 {
89 using namespace shader::compile; 91 using namespace shader::compile;
90 92
91 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
96 lz = z (vout.position);
97 z (vout.position) = (log2 (lz) * (2 / log2 (1e10)) - 1) * w (vout.position);
92 } 98 }
93 99
94 vsh_src = shader::shader_builder::stop (); 100 vsh_src = shader::shader_builder::stop ();
95 101
102 shader::shader_builder::start ();
103
96 if (ctx.pass_data->l || 1) 104 if (ctx.pass_data->l)
97 { 105 {
98 shader::shader_builder::start (); 106 ctx.pass_data->l->fsh ();
99 shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); 107
100 fsh (ctx); 108 fsh (ctx);
109 }
110 else
111 shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.);
101 112
102 fsh_src = shader::shader_builder::stop (); 113 fsh_src = shader::shader_builder::stop ();
103 }
104 114
105 shader::program_object po = shader::get_program (vsh_src, fsh_src); 115 shader::program_object po = shader::get_program (vsh_src, fsh_src);
106 matmap.insert (pass::matmap_t::value_type (this, po)); 116 matmap.insert (pass::matmap_t::value_type (this, po));
107 117
108 po->enable (); 118 po->enable ();
109 } 119 }
110 else 120 else
111 i->second->enable (); 121 i->second->enable ();
122
123 if (ctx.pass_data->l)
124 ctx.pass_data->l->enable ();
112} 125}
113 126
114void material::disable (view &ctx) 127void material::disable (view &ctx)
115{ 128{
116} 129}
120: tex ("textures/rockwall.jpg"), texvar (tex.name) 133: tex ("textures/rockwall.jpg"), texvar (tex.name)
121, norm ("textures/rockwall_normal.jpg"), normvar (norm.name) 134, norm ("textures/rockwall_normal.jpg"), normvar (norm.name)
122{ 135{
123} 136}
124 137
125static shader::varying_3f normal, lightvec; 138static shader::varying_3f normal;
126static shader::varying_2f texcoord; 139static shader::varying_2f texcoord;
127 140
128void test_material::vsh (view &ctx) 141void test_material::vsh (view &ctx)
129{ 142{
130 using namespace shader::compile; 143 using namespace shader::compile;
133 146
134 if (ctx.pass_data->l) 147 if (ctx.pass_data->l)
135 { 148 {
136 texcoord = xy (vin.tex_coord[0]); 149 texcoord = xy (vin.tex_coord[0]);
137 normal = normal_matrix * vin.normal; 150 normal = normal_matrix * vin.normal;
138 lightvec = xyz (ctx.pass_data->l->lightpos - model_view_matrix * vin.vertex);
139 } 151 }
140} 152}
141 153
142void test_material::fsh (view &ctx) 154void test_material::fsh (view &ctx)
143{ 155{
146 if (ctx.pass_data->l) 158 if (ctx.pass_data->l)
147 { 159 {
148 temp_3f lc; 160 temp_3f lc;
149 temp_1f fac; 161 temp_1f fac;
150 162
151 lc = (*ctx.pass_data->l)();
152
153 temp_3f rot1, rot2, rot3; 163 temp_3f rot1, rot2, rot3;
154 164
155 yxz (rot1) = (texture_2d (normvar, texcoord) * 2.F - 1.F); 165 yxz (rot1) = (texture_2d (normvar, texcoord) * 2.F - 1.F);
156 166
157 //rot1 = normal_matrix * rot1; 167 //rot1 = normal_matrix * rot1;
159 rot2 = float3 (x(rot1), z(rot1), -y(rot1)); 169 rot2 = float3 (x(rot1), z(rot1), -y(rot1));
160 rot3 = float3 (y(rot1), -x(rot1), z(rot1)); 170 rot3 = float3 (y(rot1), -x(rot1), z(rot1));
161 171
162 normal = mat3 (rot1, rot2, rot3) * normal; 172 normal = mat3 (rot1, rot2, rot3) * normal;
163 173
164 fac = dot (normalize (normal), normalize (lightvec)); 174 fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec));
165 fac = max (pow (max (fac, 0.0), 6), 0.3); 175 fac = max (pow (max (fac, 0.0), 6), 0.3);
166 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * lc * fac; 176 xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac
177 * ctx.pass_data->l->sh_colour;
167 //xyz (fout.frag_color) = lc * fac; 178 //xyz (fout.frag_color) = lc * fac;
168 } 179 }
169} 180}
170 181
171void test_material::enable (view &ctx) 182void test_material::enable (view &ctx)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines