… | |
… | |
91 | using namespace shader::compile; |
91 | using namespace shader::compile; |
92 | |
92 | |
93 | p.vsh->start (); |
93 | p.vsh->start (); |
94 | |
94 | |
95 | temp_4f wpos; |
95 | temp_4f wpos; |
96 | varying_1f camdist; |
96 | varying_1f camdist, zpos; |
|
|
97 | varying_2f texcoord; |
97 | varying_3f lightvec; |
98 | varying_3f lightvec, normal; |
98 | |
99 | |
99 | wpos = model_view_projection_matrix * vin.vertex; |
100 | wpos = model_view_matrix * vin.vertex; |
100 | |
101 | |
101 | //wpos = wpos / abs (w (wpos)); |
102 | temp_1f wz; |
|
|
103 | //wz = log2 (abs (wz)) * sign (wz); |
102 | |
104 | |
103 | vout.position = wpos; |
105 | vout.position = projection_matrix * wpos; |
104 | vout.tex_coord[0] = vin.tex_coord[0]; |
106 | texcoord = xy (vin.tex_coord[0]); |
105 | xyz (vout.tex_coord[1]) = normal_matrix * vin.normal; |
107 | normal = normal_matrix * vin.normal; |
106 | lightvec = xyz (lightpos - model_view_matrix * vin.vertex); |
108 | lightvec = xyz (lightpos - model_view_matrix * vin.vertex); |
107 | camdist = length (xyz (vout.tex_coord[2])); |
109 | camdist = 1 - max (length (lightvec) / 10000., 0); |
108 | |
110 | |
109 | p.vsh->end (); |
111 | p.vsh->end (); |
110 | p.vsh->compile (); |
112 | p.vsh->compile (); |
111 | |
113 | |
112 | p.fsh->start (); |
114 | p.fsh->start (); |
… | |
… | |
115 | temp_2f disp; |
117 | temp_2f disp; |
116 | temp_1f dx, dy; |
118 | temp_1f dx, dy; |
117 | temp_1f bumpnormal; |
119 | temp_1f bumpnormal; |
118 | temp_1f dist; |
120 | temp_1f dist; |
119 | |
121 | |
120 | dist = min (x(camdist), 10000.); |
|
|
121 | |
|
|
122 | fac = dot (normalize (xyz (fin.tex_coord[1])), normalize (lightvec)); |
122 | fac = dot (normalize (normal), normalize (lightvec)); |
123 | //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal); |
123 | //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal); |
124 | //fac = dot (bumpnormal, normalize (fin.tex_coord[2])); |
124 | //fac = dot (bumpnormal, normalize (fin.tex_coord[2])); |
125 | //fac = pow (max (fac, 0.0), 8); |
125 | fac = pow (max (fac, 0.0), 2); |
126 | xyz (fout.frag_color) = (texture_2d (texvar, fin.tex_coord[0] - disp)) * max (fac * (0.4 + 1.F * (1 - dist / 10000.)), 0); |
126 | xyz (fout.frag_color) = texture_2d (texvar, texcoord) * (fac + 0.4) * camdist; |
127 | |
127 | |
128 | p.fsh->end (); |
128 | p.fsh->end (); |
129 | p.fsh->compile (); |
129 | p.fsh->compile (); |
130 | p.link (); |
130 | p.link (); |
131 | } |
131 | } |