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.20 by root, Sat Oct 30 00:17:28 2004 UTC vs.
Revision 1.24 by root, Sun Oct 31 22:55:23 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 vout.tex_coord[1] = model_view_matrix * shader::compile::vec4 (x(vin.normal), y(vin.normal), z(vin.normal), 0);
104 vout.tex_coord[2] = lightpos - model_view_matrix * vin.vertex;
100 105
101 p.vsh->end (); 106 p.vsh->end ();
102 p.vsh->compile (); 107 p.vsh->compile ();
103 108
104 p.fsh->start (); 109 p.fsh->start ();
105 110
106 temp_1f fac; 111 temp_1f fac;
107 112
108 fac = max (dot (fin.tex_coord[1], lightpos), 0.0); 113 temp_2f disp;
109 fac = pow (fac, 3); 114
115 temp_1f dx, dy;
116
117 temp_1f bumpnormal;
118 dx = dFdx (texture_2d (normvar, fin.tex_coord[0]));
119 dy = dFdy (texture_2d (normvar, fin.tex_coord[0]));
120
121 disp = shader::compile::vec2 (dx, dy) * 0.1;
122
123 fac = dot (normalize (fin.tex_coord[1]), normalize (fin.tex_coord[2]));
124 //fac = dot (shader::compile::vec3 (normalize (fin.tex_coord[1]) + normalize (fin.tex_coord[2])) * 0.5, bumpnormal);
125 //fac = dot (bumpnormal, normalize (fin.tex_coord[2]));
126 //fac = pow (max (fac, 0.0), 8);
110 xyz (fout.frag_color) = texture_2d (texvar, fin.tex_coord[0]) * (fac + 0.3); 127 xyz (fout.frag_color) = (texture_2d (texvar, fin.tex_coord[0] - disp) + 0.1) * max (fac, 0.0);
111 128
112 p.fsh->end (); 129 p.fsh->end ();
113 p.fsh->compile (); 130 p.fsh->compile ();
114 p.link (); 131 p.link ();
115} 132}
116 133
117void test_material::enable (view &ctx) 134void test_material::enable (view &ctx)
118{ 135{
119 p.enable (); 136 p.enable ();
120 lightpos->set (-ctx.d); 137 lightpos->set (vec3 (0, 0, 0));
121 texvar->enable (); 138 texvar->enable ();
139 normvar->enable ();
122} 140}
123 141
124void test_material::disable (view &ctx) 142void test_material::disable (view &ctx)
125{ 143{
144 normvar->disable ();
126 texvar->disable (); 145 texvar->disable ();
127 p.disable (); 146 p.disable ();
128} 147}
129 148

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines