… | |
… | |
82 | |
82 | |
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.jpg"), texvar (tex.name) |
|
|
89 | , norm ("textures/rockwall_height.jpg"), normvar (norm.name) |
88 | { |
90 | { |
89 | using namespace shader::compile; |
91 | using namespace shader::compile; |
90 | |
92 | |
91 | p.vsh->start (); |
93 | p.vsh->start (); |
92 | |
94 | |
93 | temp_4f wpos; |
95 | temp_4f wpos; |
|
|
96 | varying_1f camdist, zpos; |
|
|
97 | varying_2f texcoord; |
|
|
98 | varying_3f lightvec, normal; |
94 | |
99 | |
95 | wpos = model_view_projection_matrix * vin.vertex; |
100 | wpos = model_view_matrix * vin.vertex; |
96 | |
101 | |
97 | vout.position = wpos; |
102 | temp_1f wz; |
|
|
103 | //wz = log2 (abs (wz)) * sign (wz); |
|
|
104 | |
|
|
105 | vout.position = projection_matrix * wpos; |
98 | vout.tex_coord[0] = vin.tex_coord[0]; |
106 | texcoord = xy (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); |
107 | normal = normal_matrix * vin.normal; |
100 | 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); |
101 | |
110 | |
102 | p.vsh->end (); |
111 | p.vsh->end (); |
103 | p.vsh->compile (); |
112 | p.vsh->compile (); |
104 | |
113 | |
105 | p.fsh->start (); |
114 | p.fsh->start (); |
106 | |
115 | |
107 | temp_1f fac; |
116 | temp_1f fac; |
108 | |
117 | temp_2f disp; |
|
|
118 | temp_1f dx, dy; |
|
|
119 | temp_1f bumpnormal; |
|
|
120 | temp_1f dist; |
|
|
121 | |
|
|
122 | fac = dot (normalize (normal), normalize (lightvec)); |
109 | fac = max (dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2])), 0.0); |
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])); |
110 | fac = pow (fac, 0.5); |
125 | fac = pow (max (fac, 0.0), 2); |
111 | xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * max (fac, 0.4); |
126 | xyz (fout.frag_color) = texture_2d (texvar, texcoord) * (fac + 0.4) * camdist; |
112 | |
127 | |
113 | p.fsh->end (); |
128 | p.fsh->end (); |
114 | p.fsh->compile (); |
129 | p.fsh->compile (); |
115 | p.link (); |
130 | p.link (); |
116 | } |
131 | } |
… | |
… | |
118 | void test_material::enable (view &ctx) |
133 | void test_material::enable (view &ctx) |
119 | { |
134 | { |
120 | p.enable (); |
135 | p.enable (); |
121 | lightpos->set (vec3 (0, 0, 0)); |
136 | lightpos->set (vec3 (0, 0, 0)); |
122 | texvar->enable (); |
137 | texvar->enable (); |
|
|
138 | normvar->enable (); |
123 | } |
139 | } |
124 | |
140 | |
125 | void test_material::disable (view &ctx) |
141 | void test_material::disable (view &ctx) |
126 | { |
142 | { |
|
|
143 | normvar->disable (); |
127 | texvar->disable (); |
144 | texvar->disable (); |
128 | p.disable (); |
145 | p.disable (); |
129 | } |
146 | } |
130 | |
147 | |