… | |
… | |
78 | if (i == matmap.end ()) |
78 | if (i == matmap.end ()) |
79 | { |
79 | { |
80 | string vsh_src, fsh_src; |
80 | string vsh_src, fsh_src; |
81 | |
81 | |
82 | shader::shader_builder::start (); |
82 | shader::shader_builder::start (); |
83 | vsh (ctx); |
|
|
84 | |
83 | |
85 | if (ctx.pass_data->l) |
84 | if (ctx.pass_data->l) |
86 | ctx.pass_data->l->vsh (); |
85 | ctx.pass_data->l->vsh (); |
87 | |
86 | |
|
|
87 | vsh (ctx); |
|
|
88 | |
88 | { |
89 | { |
89 | using namespace shader::compile; |
90 | using namespace shader::compile; |
90 | |
91 | |
91 | z (vout.position) = log2 (z (vout.position) / w (vout.position)) * w (vout.position); |
92 | //z (vout.position) = (log2 (z (vout.position) + 1.F) - 1); |
|
|
93 | z (vout.position) = z (vout.position) - 1; |
92 | } |
94 | } |
93 | |
95 | |
94 | vsh_src = shader::shader_builder::stop (); |
96 | vsh_src = shader::shader_builder::stop (); |
95 | |
97 | |
|
|
98 | shader::shader_builder::start (); |
|
|
99 | |
96 | if (ctx.pass_data->l || 1) |
100 | if (ctx.pass_data->l) |
97 | { |
101 | { |
98 | shader::shader_builder::start (); |
102 | ctx.pass_data->l->fsh (); |
99 | shader::compile::fout.frag_color = shader::compile::float4 (1., 1., 0., 1.); |
103 | |
100 | fsh (ctx); |
104 | fsh (ctx); |
|
|
105 | } |
|
|
106 | else |
|
|
107 | shader::compile::fout.frag_color = shader::compile::float4 (1., 0., 1., 1.); |
101 | |
108 | |
102 | fsh_src = shader::shader_builder::stop (); |
109 | fsh_src = shader::shader_builder::stop (); |
103 | } |
|
|
104 | |
110 | |
105 | shader::program_object po = shader::get_program (vsh_src, fsh_src); |
111 | shader::program_object po = shader::get_program (vsh_src, fsh_src); |
106 | matmap.insert (pass::matmap_t::value_type (this, po)); |
112 | matmap.insert (pass::matmap_t::value_type (this, po)); |
107 | |
113 | |
108 | po->enable (); |
114 | po->enable (); |
… | |
… | |
120 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
126 | : tex ("textures/rockwall.jpg"), texvar (tex.name) |
121 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
127 | , norm ("textures/rockwall_normal.jpg"), normvar (norm.name) |
122 | { |
128 | { |
123 | } |
129 | } |
124 | |
130 | |
125 | static shader::varying_3f normal, lightvec; |
131 | static shader::varying_3f normal; |
126 | static shader::varying_2f texcoord; |
132 | static shader::varying_2f texcoord; |
127 | |
133 | |
128 | void test_material::vsh (view &ctx) |
134 | void test_material::vsh (view &ctx) |
129 | { |
135 | { |
130 | using namespace shader::compile; |
136 | using namespace shader::compile; |
… | |
… | |
133 | |
139 | |
134 | if (ctx.pass_data->l) |
140 | if (ctx.pass_data->l) |
135 | { |
141 | { |
136 | texcoord = xy (vin.tex_coord[0]); |
142 | texcoord = xy (vin.tex_coord[0]); |
137 | normal = normal_matrix * vin.normal; |
143 | normal = normal_matrix * vin.normal; |
138 | lightvec = xyz (ctx.pass_data->l->lightpos - model_view_matrix * vin.vertex); |
|
|
139 | } |
144 | } |
140 | } |
145 | } |
141 | |
146 | |
142 | void test_material::fsh (view &ctx) |
147 | void test_material::fsh (view &ctx) |
143 | { |
148 | { |
… | |
… | |
146 | if (ctx.pass_data->l) |
151 | if (ctx.pass_data->l) |
147 | { |
152 | { |
148 | temp_3f lc; |
153 | temp_3f lc; |
149 | temp_1f fac; |
154 | temp_1f fac; |
150 | |
155 | |
151 | lc = (*ctx.pass_data->l)(); |
|
|
152 | |
|
|
153 | temp_3f rot1, rot2, rot3; |
156 | temp_3f rot1, rot2, rot3; |
154 | |
157 | |
155 | yxz (rot1) = (texture_2d (normvar, texcoord) * 2.F - 1.F); |
158 | yxz (rot1) = (texture_2d (normvar, texcoord) * 2.F - 1.F); |
156 | |
159 | |
157 | //rot1 = normal_matrix * rot1; |
160 | //rot1 = normal_matrix * rot1; |
… | |
… | |
159 | rot2 = float3 (x(rot1), z(rot1), -y(rot1)); |
162 | rot2 = float3 (x(rot1), z(rot1), -y(rot1)); |
160 | rot3 = float3 (y(rot1), -x(rot1), z(rot1)); |
163 | rot3 = float3 (y(rot1), -x(rot1), z(rot1)); |
161 | |
164 | |
162 | normal = mat3 (rot1, rot2, rot3) * normal; |
165 | normal = mat3 (rot1, rot2, rot3) * normal; |
163 | |
166 | |
164 | fac = dot (normalize (normal), normalize (lightvec)); |
167 | fac = dot (normalize (normal), normalize (ctx.pass_data->l->sh_lightvec)); |
165 | fac = max (pow (max (fac, 0.0), 6), 0.3); |
168 | fac = max (pow (max (fac, 0.0), 6), 0.3); |
166 | xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * lc * fac; |
169 | xyz (fout.frag_color) = (texture_2d (texvar, texcoord) + 0.2F) * fac |
|
|
170 | * ctx.pass_data->l->sh_colour; |
167 | //xyz (fout.frag_color) = lc * fac; |
171 | //xyz (fout.frag_color) = lc * fac; |
168 | } |
172 | } |
169 | } |
173 | } |
170 | |
174 | |
171 | void test_material::enable (view &ctx) |
175 | void test_material::enable (view &ctx) |