… | |
… | |
95 | wpos = model_view_projection_matrix * vin.vertex; |
95 | wpos = model_view_projection_matrix * vin.vertex; |
96 | |
96 | |
97 | vout.position = wpos; |
97 | vout.position = wpos; |
98 | vout.tex_coord[0] = vin.tex_coord[0]; |
98 | vout.tex_coord[0] = vin.tex_coord[0]; |
99 | vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0); |
99 | vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0); |
|
|
100 | vout.tex_coord[2] = lightpos - model_view_matrix * vin.vertex; |
100 | |
101 | |
101 | p.vsh->end (); |
102 | p.vsh->end (); |
102 | p.vsh->compile (); |
103 | p.vsh->compile (); |
103 | |
104 | |
104 | p.fsh->start (); |
105 | p.fsh->start (); |
105 | |
106 | |
106 | temp_1f fac; |
107 | temp_1f fac; |
107 | |
108 | |
108 | fac = max (dot (fin.tex_coord[1], lightpos), 0.0); |
109 | fac = max (dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2])), 0.0); |
109 | fac = pow (fac, 3); |
110 | fac = pow (fac, 0.5); |
110 | xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * (fac + 0.3); |
111 | xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * max (fac, 0.4); |
111 | |
112 | |
112 | p.fsh->end (); |
113 | p.fsh->end (); |
113 | p.fsh->compile (); |
114 | p.fsh->compile (); |
114 | p.link (); |
115 | p.link (); |
115 | } |
116 | } |
116 | |
117 | |
117 | void test_material::enable (view &ctx) |
118 | void test_material::enable (view &ctx) |
118 | { |
119 | { |
119 | p.enable (); |
120 | p.enable (); |
120 | lightpos->set (-ctx.d); |
121 | lightpos->set (vec3 (0, 0, 0)); |
121 | texvar->enable (); |
122 | texvar->enable (); |
122 | } |
123 | } |
123 | |
124 | |
124 | void test_material::disable (view &ctx) |
125 | void test_material::disable (view &ctx) |
125 | { |
126 | { |