]> git.tdb.fi Git - libs/gl.git/commitdiff
Convert desertpillars to use the new shader customization
authorMikko Rasa <tdb@tdb.fi>
Mon, 23 Dec 2013 16:22:19 +0000 (18:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 23 Dec 2013 16:22:19 +0000 (18:22 +0200)
demos/desertpillars.cpp

index a10b7832c1e50e463ccab8902dd00fe8a1bec9a3..c0ba0c6cec34617242800392a3af6e960be2fe36 100644 (file)
@@ -118,7 +118,6 @@ private:
        std::vector<ObjectData> pillar_data;
        std::vector<GL::AnimatedObject *> pillars;
 
-       GL::VertexShader cube_transform;
        GL::Program cube_shprog;
        GL::Program cube_shadow_shprog;
        GL::Material cube_material;
@@ -151,9 +150,8 @@ private:
        static const char texture_fragment_src[];
        static const char skybox_vertex_src[];
        static const char skybox_fragment_src[];
-       static const char ground_transform_src[];
-       static const char ground_colorify_src[];
-       static const char cube_transform_src[];
+       static const char ground_variables[];
+       static const char cube_variables[];
        static const float cube_shapes[];
 
 public:
@@ -230,54 +228,20 @@ const char DesertPillars::skybox_fragment_src[] =
        "       frag_color = textureCube(sky, v_texcoord);\n"
        "}";
 
-// This exists only to transfer the ground type to fragment shader
-const char DesertPillars::ground_transform_src[] =
-       "#version 130\n"
-       "uniform mat4 eye_obj_matrix;\n"
-       "uniform mat3 eye_obj_normal_matrix;\n"
-       "in float ground_type;\n"
-       "out float v_ground_type;\n"
-       "vec4 transform_vertex(vec4 vertex)\n"
-       "{\n"
-       "       v_ground_type = ground_type;\n"
-       "       return eye_obj_matrix*vertex;\n"
-       "}\n"
-       "vec3 transform_normal(vec3 normal)\n"
-       "{\n"
-       "       return mat3(eye_obj_normal_matrix)*normal;\n"
-       "}\n";
-
-const char DesertPillars::ground_colorify_src[] =
-       "#version 130\n"
+const char DesertPillars::ground_variables[] =
        "uniform sampler2D texture1;\n"
        "uniform sampler2D normalmap1;\n"
        "uniform sampler2D texture2;\n"
        "uniform sampler2D normalmap2;\n"
-       "in float v_ground_type;\n"
-       "in vec3 v_shd_vertex;\n"
-       "vec4 sample_texture(vec2 coord)\n"
-       "{\n"
-       "       return mix(texture2D(texture1, coord*3.0), texture2D(texture2, coord), v_ground_type);\n"
-       "}\n"
-       "vec3 sample_normalmap(vec2 coord)\n"
-       "{\n"
-       "       return mix(texture2D(normalmap1, coord*3.0).rgb, texture2D(normalmap2, coord).rgb, v_ground_type);\n"
-       "}\n";
+       "attribute float ground_type;\n"
+       "fragment vec4 tex_sample = mix(texture2D(texture1, texture_coord*3.0), texture2D(texture2, texture_coord), ground_type);\n"
+       "fragment vec3 normal_sample = mix(texture2D(normalmap1, texture_coord*3.0).rgb, texture2D(normalmap2, texture_coord).rgb, ground_type);\n";
 
-const char DesertPillars::cube_transform_src[] =
-       "#version 130\n"
-       "uniform mat4 eye_obj_matrix;\n"
-       "uniform mat3 eye_obj_normal_matrix;\n"
+const char DesertPillars::cube_variables[] =
        "uniform float spherify;\n"
-       "in vec3 sphere_coord;\n"
-       "vec4 transform_vertex(vec4 vertex)\n"
-       "{\n"
-       "       return eye_obj_matrix*vec4(mix(vertex.xyz, sphere_coord, spherify), 1.0);\n"
-       "}\n"
-       "vec3 transform_normal(vec3 normal)\n"
-       "{\n"
-       "       return eye_obj_normal_matrix*normalize(mix(normal, normalize(sphere_coord), spherify));\n"
-       "}\n";
+       "attribute vec3 sphere_coord;\n"
+       "vertex vec3 eye_normal = eye_obj_normal_matrix*normalize(mix(normal, normalize(sphere_coord), spherify));\n"
+       "vertex vec4 eye_vertex = eye_obj_matrix*vec4(mix(vertex.xyz, sphere_coord, spherify), 1.0);\n";
 
 const float DesertPillars::cube_shapes[] = { -0.4, 0.5, 1.0, 0.3 };
 
@@ -614,11 +578,8 @@ void DesertPillars::create_ground()
        features.shadow = true;
        features.texture = true;
        features.normalmap = true;
-       features.transform = true;
-       features.colorify = true;
+       features.custom = ground_variables;
        GL::ProgramBuilder(features).add_shaders(ground_shprog);
-       ground_shprog.attach_shader_owned(new GL::VertexShader(ground_transform_src));
-       ground_shprog.attach_shader_owned(new GL::FragmentShader(ground_colorify_src));
        ground_shprog.bind_attribute(7, "ground_type");
        ground_shprog.link();
 
@@ -787,14 +748,10 @@ void DesertPillars::create_cube()
        cube_material.set_specular(GL::Color(1.0));
        cube_material.set_shininess(150);
 
-       cube_transform.source(cube_transform_src);
-       cube_transform.compile();
-
        // First create a simplified shader for rendering the shadow map
        GL::ProgramBuilder::StandardFeatures features;
-       features.transform = true;
+       features.custom = cube_variables;
        GL::ProgramBuilder(features).add_shaders(cube_shadow_shprog);
-       cube_shadow_shprog.attach_shader(cube_transform);
        cube_shadow_shprog.bind_attribute(7, "sphere_coord");
        cube_shadow_shprog.link();
 
@@ -805,7 +762,6 @@ void DesertPillars::create_cube()
        features.shadow = true;
        features.reflection = true;
        GL::ProgramBuilder(features).add_shaders(cube_shprog);
-       cube_shprog.attach_shader(cube_transform);
        cube_shprog.bind_attribute(7, "sphere_coord");
        cube_shprog.link();