… | |
… | |
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; |
|
|
97 | varying_3f lightvec; |
94 | |
98 | |
95 | wpos = model_view_projection_matrix * vin.vertex; |
99 | wpos = model_view_projection_matrix * vin.vertex; |
96 | |
100 | |
97 | wpos = wpos / abs (w (wpos)); |
101 | //wpos = wpos / abs (w (wpos)); |
98 | |
102 | |
99 | vout.position = wpos; |
103 | vout.position = wpos; |
100 | vout.tex_coord[0] = vin.tex_coord[0]; |
104 | vout.tex_coord[0] = vin.tex_coord[0]; |
101 | vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0); |
105 | xyz (vout.tex_coord[1]) = normal_matrix * vin.normal; |
102 | vout.tex_coord[2] = lightpos - model_view_matrix * vin.vertex; |
106 | lightvec = xyz (lightpos - model_view_matrix * vin.vertex); |
|
|
107 | camdist = 1 - max (length (xyz (vout.tex_coord[2])) / 10000., 0); |
103 | |
108 | |
104 | p.vsh->end (); |
109 | p.vsh->end (); |
105 | p.vsh->compile (); |
110 | p.vsh->compile (); |
106 | |
111 | |
107 | p.fsh->start (); |
112 | p.fsh->start (); |
108 | |
113 | |
109 | temp_1f fac; |
114 | temp_1f fac; |
110 | |
115 | temp_2f disp; |
|
|
116 | temp_1f dx, dy; |
|
|
117 | temp_1f bumpnormal; |
|
|
118 | temp_1f dist; |
|
|
119 | |
111 | fac = max (dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2])), 0.0); |
120 | fac = dot (normalize (xyz (fin.tex_coord[1])), normalize (lightvec)); |
|
|
121 | //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal); |
|
|
122 | //fac = dot (bumpnormal, normalize (fin.tex_coord[2])); |
112 | fac = pow (fac, 0.7); |
123 | //fac = pow (max (fac, 0.0), 8); |
113 | xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * max (fac, 0.4); |
124 | xyz (fout.frag_color) = (texture_2d (texvar, fin.tex_coord[0] - disp)) * max (fac * (0.4 + 1.F * camdist), 0); |
114 | |
125 | |
115 | p.fsh->end (); |
126 | p.fsh->end (); |
116 | p.fsh->compile (); |
127 | p.fsh->compile (); |
117 | p.link (); |
128 | p.link (); |
118 | } |
129 | } |
… | |
… | |
120 | void test_material::enable (view &ctx) |
131 | void test_material::enable (view &ctx) |
121 | { |
132 | { |
122 | p.enable (); |
133 | p.enable (); |
123 | lightpos->set (vec3 (0, 0, 0)); |
134 | lightpos->set (vec3 (0, 0, 0)); |
124 | texvar->enable (); |
135 | texvar->enable (); |
|
|
136 | normvar->enable (); |
125 | } |
137 | } |
126 | |
138 | |
127 | void test_material::disable (view &ctx) |
139 | void test_material::disable (view &ctx) |
128 | { |
140 | { |
|
|
141 | normvar->disable (); |
129 | texvar->disable (); |
142 | texvar->disable (); |
130 | p.disable (); |
143 | p.disable (); |
131 | } |
144 | } |
132 | |
145 | |