… | |
… | |
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 | |
|
|
146 | void mat_timed::enable (view &ctx) |
145 | void mat_timed::enable (view &ctx) |
147 | { |
146 | { |
148 | material::enable (ctx); |
147 | material::enable (ctx); |
149 | |
148 | |
150 | time->set (timer::now); |
149 | time->set (timer::now); |
… | |
… | |
154 | void mat_timed::disable (view &ctx) |
153 | void mat_timed::disable (view &ctx) |
155 | { |
154 | { |
156 | material::disable (ctx); |
155 | material::disable (ctx); |
157 | } |
156 | } |
158 | |
157 | |
159 | shader::varying_3f fish; |
|
|
160 | |
|
|
161 | void mat_timed::vsh (view &ctx) |
158 | void mat_timed::vsh (view &ctx) |
162 | { |
159 | { |
163 | using namespace shader::compile; |
160 | using namespace shader::compile; |
164 | std_vsh (); |
161 | std_vsh (); |
165 | |
162 | |
166 | if (ctx.pass->l) |
163 | if (ctx.pass->l) |
167 | { |
|
|
168 | f_normal = normal_matrix * vin.normal; |
164 | f_normal = normal_matrix * vin.normal; |
169 | fish = xyz(vin.vertex) + zxy (vin.vertex) * 0.2; |
|
|
170 | } |
|
|
171 | } |
165 | } |
172 | |
166 | |
173 | void mat_timed::fsh (view &ctx) |
167 | void mat_timed::fsh (view &ctx) |
174 | { |
168 | { |
175 | using namespace shader::compile; |
169 | using namespace shader::compile; |
… | |
… | |
177 | if (ctx.pass->l) |
171 | if (ctx.pass->l) |
178 | { |
172 | { |
179 | temp_1f fac; |
173 | temp_1f fac; |
180 | temp_3f normal; |
174 | temp_3f normal; |
181 | |
175 | |
182 | normal = f_normal + 0.3 * pow (sin (fish * 0.1 + float3 (time * 2, time * 3.14, time * 1.55)), 3); |
176 | normal = f_normal + 0.3 * pow (sin (f_normal * 3.14159 + time), 3); |
183 | |
177 | |
184 | fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); |
178 | fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); |
185 | |
179 | |
186 | xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; |
180 | xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; |
187 | } |
181 | } |
… | |
… | |
217 | temp_1f fac; |
211 | temp_1f fac; |
218 | |
212 | |
219 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
213 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
220 | |
214 | |
221 | 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; |
222 | } |
259 | } |
223 | } |
260 | } |
224 | |
261 | |
225 | static shader::varying_2f texcoord; |
262 | static shader::varying_2f texcoord; |
226 | static shader::varying_3f normal; |
263 | static shader::varying_3f normal; |
… | |
… | |
281 | } |
318 | } |
282 | |
319 | |
283 | test_material *testmat; |
320 | test_material *testmat; |
284 | mat_gouraud_shaded *testmat2; |
321 | mat_gouraud_shaded *testmat2; |
285 | mat_timed *testmat3; |
322 | mat_timed *testmat3; |
|
|
323 | mat_debug *debugmat; |
286 | |
324 | |