ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/material.C
(Generate patch)

Comparing cvsroot/libgender/material.C (file contents):
Revision 1.21 by root, Sat Oct 30 15:59:20 2004 UTC vs.
Revision 1.25 by root, Mon Nov 1 01:57:03 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines