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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines