… | |
… | |
89 | { |
89 | { |
90 | using namespace shader::compile; |
90 | using namespace shader::compile; |
91 | |
91 | |
92 | temp_1f lz; |
92 | temp_1f lz; |
93 | |
93 | |
94 | // TODO: negative z is not calculated in an acceptable way, clipping does horrible things(?) |
94 | // TODO: negative z is not calculated in an a very acceptable way |
95 | lz = z (vout.position); |
95 | lz = z (vout.position); |
96 | #if 0 |
96 | lz = sign (lz) * (log (abs (lz) + exp (1e0)) - 1e0) / log (1e30); |
97 | lz = (log (max (lz, 0) + 1) / log (1e30)) - 1; |
|
|
98 | #else |
|
|
99 | lz = ifelse (lz <= 0, |
|
|
100 | 0, |
|
|
101 | log (lz + 1) / log (1e30) |
|
|
102 | ) - 1; |
|
|
103 | #endif |
|
|
104 | z (vout.position) = lz * w (vout.position); |
97 | z (vout.position) = lz * w (vout.position); |
105 | } |
98 | } |
106 | |
99 | |
107 | vsh_src = shader::shader_builder::stop (); |
100 | vsh_src = shader::shader_builder::stop (); |
108 | |
101 | |
… | |
… | |
140 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
133 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
141 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
134 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
142 | { |
135 | { |
143 | } |
136 | } |
144 | |
137 | |
|
|
138 | void mat_timed::enable (view &ctx) |
|
|
139 | { |
|
|
140 | material::enable (ctx); |
|
|
141 | |
|
|
142 | time->set (timer::now); |
|
|
143 | sh_colour->set (vec3 (255, 0, 0) * (1.F / 255.F)); |
|
|
144 | } |
|
|
145 | |
|
|
146 | void mat_timed::disable (view &ctx) |
|
|
147 | { |
|
|
148 | material::disable (ctx); |
|
|
149 | } |
|
|
150 | |
|
|
151 | void mat_timed::vsh (view &ctx) |
|
|
152 | { |
|
|
153 | using namespace shader::compile; |
|
|
154 | std_vsh (); |
|
|
155 | |
|
|
156 | if (ctx.pass->l) |
|
|
157 | f_normal = normal_matrix * vin.normal; |
|
|
158 | } |
|
|
159 | |
|
|
160 | void mat_timed::fsh (view &ctx) |
|
|
161 | { |
|
|
162 | using namespace shader::compile; |
|
|
163 | |
|
|
164 | if (ctx.pass->l) |
|
|
165 | { |
|
|
166 | temp_1f fac; |
|
|
167 | temp_3f normal; |
|
|
168 | |
|
|
169 | normal = f_normal + 0.3 * pow (sin (f_normal * 3.14159 + time), 3); |
|
|
170 | |
|
|
171 | fac = dot (normalize (normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
172 | |
|
|
173 | xyz (fout.frag_color) = fac * float3 (0.1,0.5,1);//ctx.pass->l->sh_colour * sh_colour * fac; |
|
|
174 | } |
|
|
175 | } |
|
|
176 | |
145 | void mat_gouraud_shaded::enable (view &ctx) |
177 | void mat_gouraud_shaded::enable (view &ctx) |
146 | { |
178 | { |
147 | material::enable (ctx); |
179 | material::enable (ctx); |
148 | |
180 | |
149 | sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); |
181 | sh_colour->set (vec3 (c.r, c.g, c.b) * (1.F / 255.F)); |
… | |
… | |
172 | temp_1f fac; |
204 | temp_1f fac; |
173 | |
205 | |
174 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
206 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
175 | |
207 | |
176 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; |
208 | xyz (fout.frag_color) = ctx.pass->l->sh_colour * sh_colour * fac; |
|
|
209 | } |
|
|
210 | } |
|
|
211 | |
|
|
212 | static shader::varying_3f f_normal; |
|
|
213 | |
|
|
214 | void mat_debug::enable (view &ctx) |
|
|
215 | { |
|
|
216 | material::enable (ctx); |
|
|
217 | |
|
|
218 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
|
219 | glEnable (GL_BLEND); |
|
|
220 | glDepthMask (1); |
|
|
221 | } |
|
|
222 | |
|
|
223 | void mat_debug::disable (view &ctx) |
|
|
224 | { |
|
|
225 | material::disable (ctx); |
|
|
226 | |
|
|
227 | glDisable (GL_BLEND); |
|
|
228 | glDepthMask (0); |
|
|
229 | } |
|
|
230 | |
|
|
231 | void mat_debug::vsh (view &ctx) |
|
|
232 | { |
|
|
233 | using namespace shader::compile; |
|
|
234 | std_vsh (); |
|
|
235 | |
|
|
236 | if (ctx.pass->l) |
|
|
237 | f_normal = normal_matrix * vin.normal; |
|
|
238 | } |
|
|
239 | |
|
|
240 | void mat_debug::fsh (view &ctx) |
|
|
241 | { |
|
|
242 | using namespace shader::compile; |
|
|
243 | |
|
|
244 | if (ctx.pass->l) |
|
|
245 | { |
|
|
246 | temp_1f fac; |
|
|
247 | |
|
|
248 | fac = dot (normalize (f_normal), normalize (ctx.pass->l->sh_lightvec)); |
|
|
249 | |
|
|
250 | xyz (fout.frag_color) = float3 (1.,0.,0.); |
|
|
251 | w (fout.frag_color) = 0.1; |
177 | } |
252 | } |
178 | } |
253 | } |
179 | |
254 | |
180 | static shader::varying_2f texcoord; |
255 | static shader::varying_2f texcoord; |
181 | static shader::varying_3f normal; |
256 | static shader::varying_3f normal; |
… | |
… | |
235 | material::disable (ctx); |
310 | material::disable (ctx); |
236 | } |
311 | } |
237 | |
312 | |
238 | test_material *testmat; |
313 | test_material *testmat; |
239 | mat_gouraud_shaded *testmat2; |
314 | mat_gouraud_shaded *testmat2; |
|
|
315 | mat_timed *testmat3; |
|
|
316 | mat_debug *debugmat; |
240 | |
317 | |