… | |
… | |
140 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
140 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
141 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
141 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
142 | { |
142 | { |
143 | } |
143 | } |
144 | |
144 | |
|
|
145 | void mat_gouraud_shaded::enable (view &ctx) |
|
|
146 | { |
|
|
147 | material::enable (ctx); |
|
|
148 | |
|
|
149 | sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); |
|
|
150 | } |
|
|
151 | |
|
|
152 | void mat_gouraud_shaded::disable (view &ctx) |
|
|
153 | { |
|
|
154 | material::disable (ctx); |
|
|
155 | } |
|
|
156 | |
|
|
157 | void mat_gouraud_shaded::vsh (view &ctx) |
|
|
158 | { |
|
|
159 | using namespace shader::compile; |
|
|
160 | std_vsh (); |
|
|
161 | |
|
|
162 | if (ctx.pass->l) |
|
|
163 | f_normal = normal_matrix * vin.normal; |
|
|
164 | } |
|
|
165 | |
|
|
166 | void mat_gouraud_shaded::fsh (view &ctx) |
|
|
167 | { |
|
|
168 | using namespace shader::compile; |
|
|
169 | |
|
|
170 | if (ctx.pass->l) |
|
|
171 | { |
|
|
172 | temp_1f fac; |
|
|
173 | |
|
|
174 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
175 | |
|
|
176 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; |
|
|
177 | } |
|
|
178 | } |
|
|
179 | |
|
|
180 | static shader::varying_2f texcoord; |
145 | static shader::varying_3f normal; |
181 | static shader::varying_3f normal; |
146 | static shader::varying_2f texcoord; |
|
|
147 | |
|
|
148 | void test_material2::vsh (view &ctx) |
|
|
149 | { |
|
|
150 | using namespace shader::compile; |
|
|
151 | std_vsh (); |
|
|
152 | |
|
|
153 | if (ctx.pass->l) |
|
|
154 | { |
|
|
155 | normal = normal_matrix * vin.normal; |
|
|
156 | } |
|
|
157 | } |
|
|
158 | |
|
|
159 | void test_material2::fsh (view &ctx) |
|
|
160 | { |
|
|
161 | using namespace shader::compile; |
|
|
162 | |
|
|
163 | if (ctx.pass->l) |
|
|
164 | { |
|
|
165 | temp_1f fac; |
|
|
166 | fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
167 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * fac;//normalize (ctx.pass->l->sh_lightvec); |
|
|
168 | } |
|
|
169 | } |
|
|
170 | |
182 | |
171 | void test_material::vsh (view &ctx) |
183 | void test_material::vsh (view &ctx) |
172 | { |
184 | { |
173 | using namespace shader::compile; |
185 | using namespace shader::compile; |
174 | |
186 | |
… | |
… | |
222 | texvar->disable (); |
234 | texvar->disable (); |
223 | material::disable (ctx); |
235 | material::disable (ctx); |
224 | } |
236 | } |
225 | |
237 | |
226 | test_material *testmat; |
238 | test_material *testmat; |
227 | test_material2 *testmat2; |
239 | mat_gouraud_shaded *testmat2; |
228 | |
240 | |