… | |
… | |
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_timed::enable (view &ctx) |
|
|
146 | { |
|
|
147 | material::enable (ctx); |
|
|
148 | |
|
|
149 | time->set (timer::now); |
|
|
150 | sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); |
|
|
151 | } |
|
|
152 | |
|
|
153 | void mat_timed::disable (view &ctx) |
|
|
154 | { |
|
|
155 | material::disable (ctx); |
|
|
156 | } |
|
|
157 | |
|
|
158 | void mat_timed::vsh (view &ctx) |
|
|
159 | { |
|
|
160 | using namespace shader::compile; |
|
|
161 | std_vsh (); |
|
|
162 | |
|
|
163 | if (ctx.pass->l) |
|
|
164 | f_normal = normal_matrix * vin.normal; |
|
|
165 | } |
|
|
166 | |
|
|
167 | void mat_timed::fsh (view &ctx) |
|
|
168 | { |
|
|
169 | using namespace shader::compile; |
|
|
170 | |
|
|
171 | if (ctx.pass->l) |
|
|
172 | { |
|
|
173 | temp_1f fac; |
|
|
174 | temp_3f normal; |
|
|
175 | |
|
|
176 | normal = f_normal + 0.3 * pow (sin (f_normal * 3.14159 + time), 3); |
|
|
177 | |
|
|
178 | fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
179 | |
|
|
180 | xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; |
|
|
181 | } |
|
|
182 | } |
|
|
183 | |
145 | void mat_gouraud_shaded::enable (view &ctx) |
184 | void mat_gouraud_shaded::enable (view &ctx) |
146 | { |
185 | { |
147 | material::enable (ctx); |
186 | material::enable (ctx); |
148 | |
187 | |
149 | sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); |
188 | sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); |
… | |
… | |
172 | temp_1f fac; |
211 | temp_1f fac; |
173 | |
212 | |
174 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
213 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
175 | |
214 | |
176 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; |
215 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; |
|
|
216 | } |
|
|
217 | } |
|
|
218 | |
|
|
219 | static shader::varying_3f f_normal; |
|
|
220 | |
|
|
221 | void mat_debug::enable (view &ctx) |
|
|
222 | { |
|
|
223 | material::enable (ctx); |
|
|
224 | |
|
|
225 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
226 | glEnable (GL_BLEND); |
|
|
227 | glDepthMask (1); |
|
|
228 | } |
|
|
229 | |
|
|
230 | void mat_debug::disable (view &ctx) |
|
|
231 | { |
|
|
232 | material::disable (ctx); |
|
|
233 | |
|
|
234 | glDisable (GL_BLEND); |
|
|
235 | glDepthMask (0); |
|
|
236 | } |
|
|
237 | |
|
|
238 | void mat_debug::vsh (view &ctx) |
|
|
239 | { |
|
|
240 | using namespace shader::compile; |
|
|
241 | std_vsh (); |
|
|
242 | |
|
|
243 | if (ctx.pass->l) |
|
|
244 | f_normal = normal_matrix * vin.normal; |
|
|
245 | } |
|
|
246 | |
|
|
247 | void mat_debug::fsh (view &ctx) |
|
|
248 | { |
|
|
249 | using namespace shader::compile; |
|
|
250 | |
|
|
251 | if (ctx.pass->l) |
|
|
252 | { |
|
|
253 | temp_1f fac; |
|
|
254 | |
|
|
255 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
256 | |
|
|
257 | xyz (fout.frag_color) = float3 (1.,0.,0.); |
|
|
258 | w (fout.frag_color) = 0.1; |
177 | } |
259 | } |
178 | } |
260 | } |
179 | |
261 | |
180 | static shader::varying_2f texcoord; |
262 | static shader::varying_2f texcoord; |
181 | static shader::varying_3f normal; |
263 | static shader::varying_3f normal; |
… | |
… | |
235 | material::disable (ctx); |
317 | material::disable (ctx); |
236 | } |
318 | } |
237 | |
319 | |
238 | test_material *testmat; |
320 | test_material *testmat; |
239 | mat_gouraud_shaded *testmat2; |
321 | mat_gouraud_shaded *testmat2; |
|
|
322 | mat_timed *testmat3; |
|
|
323 | mat_debug *debugmat; |
240 | |
324 | |