… | |
… | |
84 | vsh (ctx); |
84 | vsh (ctx); |
85 | |
85 | |
86 | if (ctx.pass_data->l) |
86 | if (ctx.pass_data->l) |
87 | ctx.pass_data->l->vsh (); |
87 | ctx.pass_data->l->vsh (); |
88 | |
88 | |
|
|
89 | { |
|
|
90 | using namespace shader::compile; |
|
|
91 | |
|
|
92 | z (vout.position) = log2 (z (vout.position) / w (vout.position)) * w (vout.position); |
|
|
93 | } |
|
|
94 | |
89 | po->vsh->compile (shader::shader_builder::stop ()); |
95 | po->vsh->compile (shader::shader_builder::stop ()); |
90 | |
96 | |
91 | shader::shader_builder::start (); |
97 | shader::shader_builder::start (); |
92 | shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); |
98 | shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); |
93 | fsh (ctx); |
99 | fsh (ctx); |
… | |
… | |
110 | } |
116 | } |
111 | |
117 | |
112 | test_material::test_material () |
118 | test_material::test_material () |
113 | //: tex ("textures/osama.jpg"), texvar (tex.name) |
119 | //: tex ("textures/osama.jpg"), texvar (tex.name) |
114 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
120 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
115 | , norm ("textures/rockwall_height.jpg"), normvar (norm.name) |
121 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
116 | { |
122 | { |
117 | } |
123 | } |
118 | |
124 | |
119 | static shader::varying_3f normal, lightvec; |
125 | static shader::varying_3f normal, lightvec; |
120 | static shader::varying_2f texcoord; |
126 | static shader::varying_2f texcoord; |
… | |
… | |
142 | temp_3f lc; |
148 | temp_3f lc; |
143 | temp_1f fac; |
149 | temp_1f fac; |
144 | |
150 | |
145 | lc = (*ctx.pass_data->l)(); |
151 | lc = (*ctx.pass_data->l)(); |
146 | |
152 | |
|
|
153 | temp_3f rot1, rot2, rot3; |
|
|
154 | |
|
|
155 | yxz (rot1) = (texture_2d (normvar, texcoord) * 2.F - 1.F); |
|
|
156 | |
|
|
157 | //rot1 = normal_matrix * rot1; |
|
|
158 | |
|
|
159 | rot2 = float3 (x(rot1), z(rot1), -y(rot1)); |
|
|
160 | rot3 = float3 (y(rot1), -x(rot1), z(rot1)); |
|
|
161 | |
|
|
162 | normal = mat3 (rot1, rot2, rot3) * normal; |
|
|
163 | |
147 | fac = dot (normalize (normal), normalize (lightvec)); |
164 | fac = dot (normalize (normal), normalize (lightvec)); |
148 | fac = pow (max (fac, 0.0), 2); |
165 | fac = max (pow (max (fac, 0.0), 6), 0.3); |
149 | xyz (fout.frag_color) = texture_2d (texvar, texcoord) * lc * fac; |
166 | xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * lc * fac; |
|
|
167 | //xyz (fout.frag_color) = lc * fac; |
150 | } |
168 | } |
151 | } |
169 | } |
152 | |
170 | |
153 | void test_material::enable (view &ctx) |
171 | void test_material::enable (view &ctx) |
154 | { |
172 | { |
… | |
… | |
162 | normvar->disable (); |
180 | normvar->disable (); |
163 | texvar->disable (); |
181 | texvar->disable (); |
164 | material::disable (ctx); |
182 | material::disable (ctx); |
165 | } |
183 | } |
166 | |
184 | |
167 | test_material testmat; |
185 | test_material *testmat; |
|
|
186 | |