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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines