… | |
… | |
83 | return name; |
83 | return name; |
84 | } |
84 | } |
85 | |
85 | |
86 | test_material::test_material () |
86 | test_material::test_material () |
87 | //: tex ("textures/osama.jpg"), texvar (tex.name) |
87 | //: tex ("textures/osama.jpg"), texvar (tex.name) |
88 | : tex ("textures/rockwall.tga"), texvar (tex.name) |
88 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
89 | , norm ("textures/rockwall_height.tga"), normvar (norm.name) |
89 | , norm ("textures/rockwall_height.jpg"), normvar (norm.name) |
90 | { |
90 | { |
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, zpos; |
|
|
97 | varying_2f texcoord; |
|
|
98 | varying_3f lightvec, normal; |
96 | |
99 | |
97 | wpos = model_view_projection_matrix * vin.vertex; |
100 | wpos = model_view_matrix * vin.vertex; |
98 | |
101 | |
99 | //wpos = wpos / abs (w (wpos)); |
102 | temp_1f wz; |
|
|
103 | //wz = log2 (abs (wz)) * sign (wz); |
100 | |
104 | |
101 | vout.position = wpos; |
105 | vout.position = projection_matrix * wpos; |
102 | vout.tex_coord[0] = vin.tex_coord[0]; |
106 | texcoord = xy (vin.tex_coord[0]); |
103 | vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0); |
107 | normal = normal_matrix * vin.normal; |
104 | vout.tex_coord[2] = lightpos - model_view_matrix * vin.vertex; |
108 | lightvec = xyz (lightpos - model_view_matrix * vin.vertex); |
|
|
109 | camdist = 1 - max (length (lightvec) / 10000., 0); |
105 | |
110 | |
106 | p.vsh->end (); |
|
|
107 | p.vsh->compile (); |
111 | p.vsh->stop (); |
108 | |
112 | |
109 | p.fsh->start (); |
113 | p.fsh->start (); |
110 | |
114 | |
111 | temp_1f fac; |
115 | temp_1f fac; |
|
|
116 | temp_2f disp; |
|
|
117 | temp_1f dx, dy; |
|
|
118 | temp_1f bumpnormal; |
|
|
119 | temp_1f dist; |
112 | |
120 | |
113 | temp_2f disp; |
|
|
114 | |
|
|
115 | temp_1f dx, dy; |
|
|
116 | |
|
|
117 | temp_1f bumpnormal; |
|
|
118 | dx = dFdx (texture_2d (normvar, fin.tex_coord[0])); |
|
|
119 | dy = dFdy (texture_2d (normvar, fin.tex_coord[0])); |
|
|
120 | |
|
|
121 | disp = shader::compile::vec2 (dx, dy) * 0.1; |
|
|
122 | |
|
|
123 | fac = dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2])); |
121 | fac = dot (normalize (normal), normalize (lightvec)); |
124 | //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal); |
122 | //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal); |
125 | //fac = dot (bumpnormal, normalize (fin.tex_coord[2])); |
123 | //fac = dot (bumpnormal, normalize (fin.tex_coord[2])); |
126 | //fac = pow (max (fac, 0.0), 8); |
124 | fac = pow (max (fac, 0.0), 2); |
127 | xyz (fout.frag_color) = (texture_2d (texvar, fin.tex_coord[0] - disp) + 0.1) * max (fac, 0.0); |
125 | xyz (fout.frag_color) = texture_2d (texvar, texcoord) * (fac + 0.4) * camdist; |
128 | |
126 | |
129 | p.fsh->end (); |
|
|
130 | p.fsh->compile (); |
127 | p.fsh->stop (); |
131 | p.link (); |
128 | p.link (); |
132 | } |
129 | } |
133 | |
130 | |
134 | void test_material::enable (view &ctx) |
131 | void test_material::enable (view &ctx) |
135 | { |
132 | { |