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