# HG changeset patch # User John Tsiombikas # Date 1440276921 -10800 # Node ID 35349df5392d52fa110ad52bb20780e692b748b3 # Parent bed0e207acb641adf9a2bc292915a192096341c8 wtf? diff -r bed0e207acb6 -r 35349df5392d sdr/shadow-notex.p.glsl --- a/sdr/shadow-notex.p.glsl Sat Aug 22 23:17:57 2015 +0300 +++ b/sdr/shadow-notex.p.glsl Sat Aug 22 23:55:21 2015 +0300 @@ -1,5 +1,5 @@ /* vi: set ft=glsl */ -uniform sampler2DShadow shadowmap; +//uniform sampler2DShadow shadowmap; varying vec3 vdir, ldir, normal; varying vec4 shadow_tc; @@ -10,10 +10,10 @@ void main() { - float shadow = shadow2DProj(shadowmap, shadow_tc).x; + float shadow = 1.0;//shadow2DProj(shadowmap, shadow_tc).x; vec3 n = normalize(normal); - vec3 v = normalize(vdir); + /*vec3 v = normalize(vdir); vec3 l = normalize(ldir); vec3 h = normalize(l + v); @@ -21,9 +21,12 @@ float ndoth = max(dot(n, h), 0.0); vec3 diffuse = KD * gl_LightSource[0].diffuse.rgb * ndotl; - vec3 specular = KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW); + vec3 specular = vec3(0.0, 0.0, 0.0);//KS * gl_LightSource[0].specular.rgb * pow(ndoth, SPOW); vec3 ambient = gl_LightModel.ambient.rgb * KD; gl_FragColor.rgb = ambient + (diffuse + specular) * shadow; gl_FragColor.a = gl_FrontMaterial.diffuse.a; + */ + gl_FragColor.rgb = n * 0.5 + 0.5; + gl_FragColor.a = 1.0; } diff -r bed0e207acb6 -r 35349df5392d src/game.cc --- a/src/game.cc Sat Aug 22 23:17:57 2015 +0300 +++ b/src/game.cc Sat Aug 22 23:55:21 2015 +0300 @@ -7,6 +7,8 @@ #include "shadow.h" #include "opt.h" +#include "room.h" + static void draw_scene(); int win_width, win_height; @@ -35,7 +37,7 @@ glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); - float amb[] = {0.3, 0.3, 0.3, 1.0}; + float amb[] = {0.1, 0.1, 0.1, 1.0}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); if(glcaps.sep_spec) { @@ -58,6 +60,9 @@ } set_uniform_int(sdr_shadow_notex, "shadowmap", 1); + if(!init_room()) { + return false; + } assert(glGetError() == GL_NO_ERROR); return true; @@ -65,6 +70,7 @@ void game_cleanup() { + cleanup_room(); } void game_update(unsigned long time_msec) @@ -82,9 +88,10 @@ glRotatef(cam_phi, 1, 0, 0); glRotatef(cam_theta, 0, 1, 0); - float lpos[] = {-10, 20, 10, 1}; + float lpos[] = {-0, 0, 0, 1}; glLightfv(GL_LIGHT0, GL_POSITION, lpos); + opt.shadows = false; if(opt.shadows && sdr_shadow) { begin_shadow_pass(Vector3(lpos[0], lpos[1], lpos[2]), Vector3(0, 0, 0), 5); draw_scene(); @@ -100,7 +107,7 @@ glActiveTexture(GL_TEXTURE0); glMatrixMode(GL_MODELVIEW); - set_shader(sdr_shadow_notex); + override_shader(sdr_shadow_notex); draw_scene(); @@ -109,6 +116,7 @@ glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); } else { + override_shader(sdr_shadow_notex); draw_scene(); } } @@ -124,23 +132,15 @@ static void draw_scene() { + draw_room(); + glPushMatrix(); - glTranslatef(0, -1, 0); - - glmaterial(0.5, 0.5, 0.5, 0.8, 40.0); - - glBegin(GL_QUADS); - glNormal3f(0, 1, 0); - glVertex3f(-10, 0, 10); - glVertex3f(10, 0, 10); - glVertex3f(10, 0, -10); - glVertex3f(-10, 0, -10); - glEnd(); - - glPopMatrix(); + glTranslatef(0, 0.75, 0); glmaterial(0.2, 0.3, 1.0, 0.8, 60.0); draw_teapot(); + + glPopMatrix(); } diff -r bed0e207acb6 -r 35349df5392d src/mesh.cc --- a/src/mesh.cc Sat Aug 22 23:17:57 2015 +0300 +++ b/src/mesh.cc Sat Aug 22 23:55:21 2015 +0300 @@ -472,7 +472,7 @@ void Mesh::apply_xform(const Matrix4x4 &xform) { - Matrix4x4 dir_xform = xform; + Matrix4x4 dir_xform;// = xform.inverse().transposed(); dir_xform[0][3] = dir_xform[1][3] = dir_xform[2][3] = 0.0f; dir_xform[3][0] = dir_xform[3][1] = dir_xform[3][2] = 0.0f; dir_xform[3][3] = 1.0f; @@ -982,6 +982,43 @@ } } +void Mesh::dump(FILE *fp) const +{ + if(!has_attrib(MESH_ATTR_VERTEX)) { + return; + } + + fprintf(fp, "VERTEX ATTRIBUTES\n"); + static const char *label[] = { "pos", "nor", "tan", "tex", "col", "bw", "bid" }; + static const char *elemfmt[] = { 0, " %s(%g)", " %s(%g, %g)", " %s(%g, %g, %g)", " %s(%g, %g, %g, %g)", 0 }; + + for(int i=0; i<(int)nverts; i++) { + fprintf(fp, "%5u:", i); + for(int j=0; j #include #include #include "vmath/vmath.h" @@ -231,6 +232,8 @@ void texcoord_apply_xform(const Matrix4x4 &xform); void texcoord_gen_plane(const Vector3 &norm, const Vector3 &tang); void texcoord_gen_box(); + + void dump(FILE *fp) const; }; #endif // MESH_H_ diff -r bed0e207acb6 -r 35349df5392d src/meshgen.cc --- a/src/meshgen.cc Sat Aug 22 23:17:57 2015 +0300 +++ b/src/meshgen.cc Sat Aug 22 23:55:21 2015 +0300 @@ -412,13 +412,14 @@ mesh->clear(); for(int i=0; i<6; i++) { - Matrix4x4 xform; + Matrix4x4 xform, dir_xform; Mesh m; gen_plane(&m, 1, 1, usub, vsub); xform.rotate(Vector3(face_angles[i][1], face_angles[i][0], 0)); + dir_xform = xform; xform.translate(Vector3(0, 0, 0.5)); - m.apply_xform(xform); + m.apply_xform(xform, dir_xform); mesh->append(m); } diff -r bed0e207acb6 -r 35349df5392d src/object.cc --- a/src/object.cc Sat Aug 22 23:17:57 2015 +0300 +++ b/src/object.cc Sat Aug 22 23:55:21 2015 +0300 @@ -1,6 +1,7 @@ #include "object.h" #include "opengl.h" #include "shadow.h" +#include "shader.h" Material::Material() : diffuse(1, 1, 1), specular(0, 0, 0) @@ -102,10 +103,10 @@ if(glcaps.shaders) { if(sdr) { if(!shadow_pass) { - glUseProgram(sdr); + ::set_shader(sdr); } } else { - glUseProgram(0); + ::set_shader(0); } } @@ -140,7 +141,7 @@ } if(sdr) { - glUseProgram(0); + ::set_shader(0); } glMatrixMode(GL_MODELVIEW); @@ -187,6 +188,10 @@ void Object::draw_normals(float len, const Vector4 &col) const { + int cur_sdr; + glGetIntegerv(GL_CURRENT_PROGRAM, &cur_sdr); + glUseProgram(0); + glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); @@ -200,6 +205,8 @@ glPopMatrix(); glPopAttrib(); + + glUseProgram(cur_sdr); } void Object::draw_tangents(float len, const Vector4 &col) const diff -r bed0e207acb6 -r 35349df5392d src/room.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/room.cc Sat Aug 22 23:55:21 2015 +0300 @@ -0,0 +1,38 @@ +#include +#include "opengl.h" +#include "room.h" +#include "game.h" +#include "object.h" +#include "scene.h" +#include "meshgen.h" + +static Scene scn; + +bool init_room() +{ + Matrix4x4 xform; + + // generate room + Mesh *mroom = new Mesh; + gen_box(mroom, 100, 100, 100); + //xform.set_translation(Vector3(0, 12.5, 0)); + mroom->apply_xform(xform); + mroom->flip(); + + Object *oroom = new Object; + oroom->set_mesh(mroom); + oroom->rop.cast_shadows = false; + + scn.add_object(oroom); + return true; +} + +void cleanup_room() +{ + scn.clear(); +} + +void draw_room() +{ + scn.draw(); +} diff -r bed0e207acb6 -r 35349df5392d src/room.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/room.h Sat Aug 22 23:55:21 2015 +0300 @@ -0,0 +1,8 @@ +#ifndef ROOM_H_ +#define ROOM_H_ + +bool init_room(); +void cleanup_room(); +void draw_room(); + +#endif // ROOM_H_ diff -r bed0e207acb6 -r 35349df5392d src/scene.cc --- a/src/scene.cc Sat Aug 22 23:17:57 2015 +0300 +++ b/src/scene.cc Sat Aug 22 23:55:21 2015 +0300 @@ -51,6 +51,7 @@ objects[i]->draw_wire(); } else { objects[i]->draw(); + objects[i]->draw_normals(); } } }