ubershaders and path stripping in metascene
[ld37_one_room] / src / app.cc
index db3031f..fbd8609 100644 (file)
@@ -4,6 +4,7 @@
 #include "app.h"
 #include "opengl.h"
 #include "sdr.h"
+#include "ubersdr.h"
 #include "texture.h"
 #include "mesh.h"
 #include "meshgen.h"
@@ -21,6 +22,7 @@
 static void draw_scene();
 static void toggle_flight();
 static void calc_framerate();
+static void prebake_shaders();
 
 long time_msec;
 int win_width, win_height;
@@ -97,10 +99,11 @@ bool app_init(int argc, char **argv)
        glEnable(GL_CULL_FACE);
        glEnable(GL_LIGHTING);
        glEnable(GL_NORMALIZE);
+       glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
 
        Mesh::use_custom_sdr_attr = false;
 
-       float ambient[] = {0.0, 0.0, 0.0, 0.0};
+       float ambient[] = {0.02, 0.02, 0.02, 0.0};
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
 
        glClearColor(0.1, 0.1, 0.1, 1.0);
@@ -123,11 +126,17 @@ bool app_init(int argc, char **argv)
        blobs->node->set_scaling(Vec3(0.1, 0.1, 0.1));
        blobs->node->update(0);
 
+       if(uber_init("sdr/uber.v.glsl", "sdr/uber.p.glsl") == -1) {
+               return false;
+       }
+       prebake_shaders();
+       /*
        if(!(sdr_shadow_notex = create_program_load("sdr/shadow.v.glsl", "sdr/shadow-notex.p.glsl"))) {
                return false;
        }
        set_uniform_int(sdr_shadow_notex, "shadowmap", 1);
        set_uniform_int(sdr_shadow_notex, "envmap", 2);
+       */
 
        if(!fb_srgb) {
                sdr_post_gamma = create_program_load("sdr/post_gamma.v.glsl", "sdr/post_gamma.p.glsl");
@@ -282,6 +291,8 @@ static void set_light(int idx, const Vec3 &pos, const Vec3 &color)
        glLightfv(lt, GL_POSITION, posv);
        glLightfv(lt, GL_DIFFUSE, colv);
        glLightfv(lt, GL_SPECULAR, colv);
+
+       uber_enable_light(idx);
 }
 
 void app_display()
@@ -345,8 +356,8 @@ static void draw_scene()
 {
        static const Vec3 lpos[] = { Vec3(-50, 75, 100), Vec3(100, 0, 30), Vec3(-10, -10, 60) };
        set_light(0, lpos[0], Vec3(1.0, 0.8, 0.7) * 0.8);
-       set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6);
-       set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3);
+       //set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6);
+       //set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3);
 
        mscn->draw();
        if(show_blobs) {
@@ -588,3 +599,24 @@ static void calc_framerate()
                ++nframes;
        }
 }
+
+static void prebake_shaders()
+{
+       /*
+       unsigned int prog;
+
+       uber_clear();
+       uber_enable_light(0);
+       uber_enable_light(1);
+       uber_enable_light(2);
+       if((prog = uber_program())) {
+       }
+
+       uber_enable_texmap();
+       if((prog = uber_program())) {
+               set_uniform_int(prog, "texmap", MTL_TEX_DIFFUSE);
+       }
+
+       uber_clear();
+       */
+}