Changeset 238 for trunk/tests/render_test
- Timestamp:
- 05/16/14 05:48:01 (11 years ago)
- Location:
- trunk/tests/render_test
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/render_test/box.frag
r46 r238 4 4 varying vec3 f_material; 5 5 varying float f_diffuse_value; 6 uniform sampler2D tex;6 uniform sampler2D nv_t_diffuse; 7 7 uniform vec3 light; 8 8 … … 16 16 17 17 if (secondary) 18 gl_FragColor = texture2D( tex, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) ) / 16.0);18 gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) ) / 16.0); 19 19 else 20 gl_FragColor = texture2D( tex, vec2((fract(f_coord.z) + modulus ), ( fract(f_coord.x) + remmod) ) / 16.0);20 gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z) + modulus ), ( fract(f_coord.x) + remmod) ) / 16.0); 21 21 gl_FragColor = vec4( gl_FragColor.xyz * (f_diffuse_value + 0.4), 1.0 ); 22 22 } -
trunk/tests/render_test/box.vert
r46 r238 1 1 #version 120 2 attribute vec3 coords; 3 attribute vec3 material; 2 attribute vec3 nv_position; 3 attribute vec3 nv_color; 4 uniform mat4 nv_m_mvp; 5 4 6 varying vec3 f_coord; 5 7 varying vec3 f_normal; 6 8 varying vec3 f_material; 7 9 varying float f_diffuse_value; 8 uniform mat4 matrix_mvp;9 10 uniform vec3 light; 10 11 11 12 void main(void) { 12 13 f_normal = vec3(0,0,0); 13 f_normal[int(abs( material.y)-1)] = sign( material.y );14 f_normal[int(abs(nv_color.y)-1)] = sign( nv_color.y ); 14 15 vec3 vnormal = normalize(f_normal); 15 vec3 vlight = normalize(light - coords);16 vec3 vlight = normalize(light - nv_position); 16 17 float diffuse = max(dot(vlight, vnormal), 0.0); 17 18 f_diffuse_value = diffuse; 18 f_coord = coords;19 f_material = material;20 gl_Position = matrix_mvp * vec4(coords, 1.0);19 f_coord = nv_position; 20 f_material = nv_color; 21 gl_Position = nv_m_mvp * vec4(nv_position, 1.0); 21 22 } -
trunk/tests/render_test/char.frag
r46 r238 2 2 varying vec3 f_coord; 3 3 varying vec3 f_material; 4 uniform sampler2D tex;4 uniform sampler2D nv_t_diffuse; 5 5 6 6 void main(void) { … … 9 9 float modulus = w - remmod * 16; 10 10 11 gl_FragColor = texture2D( tex, vec2((fract(f_coord.x) + modulus ), ( fract(f_coord.z) + remmod) ) / 16.0);11 gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.x) + modulus ), ( fract(f_coord.z) + remmod) ) / 16.0); 12 12 13 // gl_FragColor = texture2D( tex, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) ) / 16.0);13 // gl_FragColor = texture2D(nv_t_diffuse, vec2((fract(f_coord.z - f_coord.x) + modulus ), ( fract(-f_coord.y) + remmod) ) / 16.0); 14 14 } -
trunk/tests/render_test/char.vert
r46 r238 1 1 #version 120 2 attribute vec3 coords; 3 attribute vec3 material; 2 attribute vec3 nv_position; 3 attribute vec3 nv_color; 4 uniform mat4 nv_m_mvp; 5 4 6 varying vec3 f_coord; 5 7 varying vec3 f_material; 6 uniform mat4 matrix_mvp;7 8 uniform vec3 pos; 8 9 9 10 void main(void) { 10 f_coord = coords;11 f_material = material;12 gl_Position = matrix_mvp * vec4(coords+ pos, 1.0);11 f_coord = nv_position; 12 f_material = nv_color; 13 gl_Position = nv_m_mvp * vec4(nv_position + pos, 1.0); 13 14 } -
trunk/tests/render_test/rl.cc
r231 r238 67 67 nv::window* m_window; 68 68 nv::texture2d* m_texture; 69 nv::clear_state m_clear_state; 69 70 nv::clear_state m_clear_state; 70 71 nv::render_state m_render_state; 72 nv::scene_state m_scene_state; 71 73 72 74 nv::program* m_char_program; … … 75 77 nv::vertex_array* m_box_va; 76 78 unsigned int m_count; 79 }; 80 81 struct vtx 82 { 83 nv::i8vec3 position; 84 nv::i8vec3 color; 85 86 vtx( const nv::i8vec3& a_position, const nv::i8vec3& a_color ) 87 : position( a_position ), color( a_color ) {} 77 88 }; 78 89 … … 99 110 { 100 111 { // CHARACTER 101 nv::mesh cmesh; 102 nv::vertex_attribute<nv::i8vec3>::list& vtx = cmesh.add_attribute<nv::i8vec3>("coords")->get(); 103 nv::vertex_attribute<nv::i8vec3>::list& mat = cmesh.add_attribute<nv::i8vec3>("material")->get(); 112 std::vector< vtx > v; 104 113 int m = 16; int x = 0; int y = 0; int h = 0; 105 vtx.emplace_back( x, h, y );106 v tx.emplace_back( x, h, y+1 );107 v tx.emplace_back( x+1, h, y+1);108 v tx.emplace_back( x+1, h, y+1);109 v tx.emplace_back( x+1, h, y );110 v tx.emplace_back( x, h, y);111 mat.insert( mat.end(), 6, nv::i8vec3( m, 1, 0 ) );114 nv::i8vec3 mt( m, 1, 0 ); 115 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 116 v.emplace_back( nv::i8vec3( x, h, y+1 ), mt ); 117 v.emplace_back( nv::i8vec3( x+1, h, y+1 ), mt ); 118 v.emplace_back( nv::i8vec3( x+1, h, y+1 ), mt ); 119 v.emplace_back( nv::i8vec3( x+1, h, y ), mt ); 120 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 112 121 m_char_program = m_device->create_program( nv::slurp( "char.vert" ), nv::slurp( "char.frag" ) ); 113 m_char_va = m_device->create_vertex_array( &cmesh, &(m_char_program->get_attributes()), nv::STATIC_DRAW );122 m_char_va = m_device->create_vertex_array( v, nv::STATIC_DRAW ); 114 123 } 115 124 116 125 { // WORLD 117 nv::mesh wmesh; 118 nv::vertex_attribute<nv::i8vec3>::list& vtx = wmesh.add_attribute<nv::i8vec3>("coords")->get(); 119 nv::vertex_attribute<nv::i8vec3>::list& mat = wmesh.add_attribute<nv::i8vec3>("material")->get(); 120 126 std::vector< vtx > v; 127 nv::i8vec3 mt; 121 128 for (int i = 0; i < size_x * size_y; ++i ) 122 129 { … … 124 131 int y = i / size_x; 125 132 126 vtx.emplace_back( x, height[i], y );127 v tx.emplace_back( x, height[i], y+1 );128 v tx.emplace_back( x+1, height[i], y+1 );129 v tx.emplace_back( x+1, height[i], y+1 );130 v tx.emplace_back( x+1, height[i], y );131 v tx.emplace_back( x, height[i], y );132 mat.insert( mat.end(), 6, nv::i8vec3( map[i], 2, 0 ));133 mt = nv::i8vec3( map[i], 2, 0 ); 134 v.emplace_back( nv::i8vec3( x, height[i], y ), mt ); 135 v.emplace_back( nv::i8vec3( x, height[i], y+1 ), mt ); 136 v.emplace_back( nv::i8vec3( x+1, height[i], y+1 ), mt ); 137 v.emplace_back( nv::i8vec3( x+1, height[i], y+1 ), mt ); 138 v.emplace_back( nv::i8vec3( x+1, height[i], y ), mt ); 139 v.emplace_back( nv::i8vec3( x, height[i], y ), mt ); 133 140 134 141 if (i > 0 && height[i-1] != height[i]) … … 139 146 { 140 147 m_count += 6; 141 vtx.emplace_back( x, h, y );142 v tx.emplace_back( x, h, y+1 );143 v tx.emplace_back( x, h+dir, y+1 );144 v tx.emplace_back( x, h+dir, y+1 );145 v tx.emplace_back( x, h+dir, y );146 v tx.emplace_back( x, h, y );147 mat.insert( mat.end(), 6, nv::i8vec3( m, -dir, 0 ));148 mt = nv::i8vec3( m, -dir, 0 ); 149 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 150 v.emplace_back( nv::i8vec3( x, h, y+1 ), mt ); 151 v.emplace_back( nv::i8vec3( x, h+dir, y+1 ), mt ); 152 v.emplace_back( nv::i8vec3( x, h+dir, y+1 ), mt ); 153 v.emplace_back( nv::i8vec3( x, h+dir, y ), mt ); 154 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 148 155 } 149 156 } … … 155 162 for ( int h = height[i-size_x]; h != height[i]; h = h + dir ) 156 163 { 157 vtx.emplace_back( x, h, y );158 v tx.emplace_back( x, h+dir, y );159 v tx.emplace_back( x+1, h+dir, y );160 161 vtx.emplace_back( x+1, h+dir, y ); 162 v tx.emplace_back( x+1, h, y );163 v tx.emplace_back( x, h, y );164 mat.insert( mat.end(), 6, nv::i8vec3( m, -3*dir, 0 ));164 mt = nv::i8vec3( m, -3*dir, 0 ); 165 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 166 v.emplace_back( nv::i8vec3( x, h+dir, y ), mt ); 167 v.emplace_back( nv::i8vec3( x+1, h+dir, y ), mt ); 168 169 v.emplace_back( nv::i8vec3( x+1, h+dir, y ), mt ); 170 v.emplace_back( nv::i8vec3( x+1, h, y ), mt ); 171 v.emplace_back( nv::i8vec3( x, h, y ), mt ); 165 172 } 166 173 } … … 168 175 } 169 176 170 m_count = v tx.size();177 m_count = v.size(); 171 178 m_box_program = m_device->create_program( nv::slurp( "box.vert" ), nv::slurp( "box.frag" ) ); 172 m_box_va = m_device->create_vertex_array( &wmesh, &(m_box_program->get_attributes()), nv::STATIC_DRAW );179 m_box_va = m_device->create_vertex_array( v, nv::STATIC_DRAW ); 173 180 } 174 181 … … 181 188 182 189 glm::vec3 move( 0, 0, 0 ); 190 m_scene_state.get_camera().set_perspective(25.0f, 1.0f*800.0f/600.0f, 0.1f, 100.0f); 183 191 184 192 while(!keypress) 185 193 { 194 m_scene_state.set_model( glm::translate(glm::mat4(1.0f), glm::vec3(-8.5, 0.0, -8.0)) ); 195 m_scene_state.get_camera().set_lookat(glm::vec3(0.0, 20.0, 5.0) + move, glm::vec3(0.0, 4.0, 0.0) + move, glm::vec3(0.0, 1.0, 0.0)); 196 186 197 m_window->get_context()->clear( m_clear_state ); 187 188 glm::mat4 model = glm::translate(glm::mat4(1.0f), glm::vec3(-8.5, 0.0, -8.0));189 glm::mat4 view = glm::lookAt(glm::vec3(0.0, 20.0, 5.0) + move, glm::vec3(0.0, 4.0, 0.0) + move, glm::vec3(0.0, 1.0, 0.0));190 glm::mat4 projection = glm::perspective(25.0f, 1.0f*800.0f/600.0f, 0.1f, 100.0f);191 glm::mat4 mv = view * model;192 193 198 m_texture->bind( 0 ); 194 m_box_program->set_uniform( "matrix_mvp", projection * mv );195 199 m_box_program->set_uniform( "light", glm::vec3(8.5, 4.5, 6.5) + move ); 196 m_box_program->set_uniform( "tex", 0 ); 197 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_box_program, m_box_va, m_count ); 198 199 m_char_program->set_uniform( "matrix_mvp", projection * mv ); 200 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_box_program, m_box_va, m_count ); 201 200 202 m_char_program->set_uniform( "pos", move + glm::vec3( 8, 4.1, 6 ) ); 201 m_char_program->set_uniform( "tex", 0 ); 202 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_char_program, m_char_va, 6 ); 203 m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_char_program, m_char_va, 6 ); 203 204 m_window->swap_buffers(); 204 205
Note: See TracChangeset
for help on using the changeset viewer.