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.22 by root, Sat Oct 30 16:40:02 2004 UTC

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{ 88{
89 using namespace shader; 89 using namespace shader::compile;
90 90
91 p.vsh->start (); 91 p.vsh->start ();
92 92
93 temp_4f wpos; 93 temp_4f wpos;
94 94
95 wpos = shader::gl.model_view_projection_matrix * vin.vertex; 95 wpos = model_view_projection_matrix * vin.vertex;
96
97 wpos = wpos / abs (w (wpos));
96 98
97 vout.position = wpos; 99 vout.position = wpos;
98 vout.tex_coord[0] = vin.tex_coord[0]; 100 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); 101 vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0);
102 vout.tex_coord[2] = lightpos - model_view_matrix * vin.vertex;
100 103
101 p.vsh->end (); 104 p.vsh->end ();
102 p.vsh->compile (); 105 p.vsh->compile ();
103 106
104 p.fsh->start (); 107 p.fsh->start ();
105 108
106 temp_1f fac; 109 temp_1f fac;
107 110
108 fac = max (dot (fin.tex_coord[1], lightpos), 0.0); 111 fac = max (dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2])), 0.0);
109 fac = pow (fac, 3); 112 fac = pow (fac, 0.7);
110 xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * (fac + 0.3); 113 xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * max (fac, 0.4);
111 114
112 p.fsh->end (); 115 p.fsh->end ();
113 p.fsh->compile (); 116 p.fsh->compile ();
114 p.link (); 117 p.link ();
115} 118}
116 119
117void test_material::enable (view &ctx) 120void test_material::enable (view &ctx)
118{ 121{
119 p.enable (); 122 p.enable ();
120 lightpos->set (-ctx.d); 123 lightpos->set (vec3 (0, 0, 0));
121 texvar->enable (); 124 texvar->enable ();
122} 125}
123 126
124void test_material::disable (view &ctx) 127void test_material::disable (view &ctx)
125{ 128{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines