From: Mikko Rasa Date: Fri, 20 Jan 2012 20:29:11 +0000 (+0200) Subject: Add a standard program feature for custom transforms X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=aee198bb90ed8ad6669e045db2ec4ec5f85e90b0;p=libs%2Fgl.git Add a standard program feature for custom transforms --- diff --git a/source/program.cpp b/source/program.cpp index 6fa14953..64aa7bc5 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -20,11 +20,15 @@ const char *standard_vertex_src[] = "l!n", "varying vec3 v_normal;\n", "l", "varying vec3 v_light_dir;\n", "p", "varying vec3 v_eye_dir;\n", + "r", "vec4 transform_vertex(vec4);\n", + "lr", "vec3 transform_normal(vec3);\n", 0, "void main()\n", 0, "{\n", - 0, "\tvec4 eye_pos = gl_ModelViewMatrix*gl_Vertex;\n", + "r", "\tvec4 eye_pos = transform_vertex(gl_Vertex);\n", + "!r", "\tvec4 eye_pos = gl_ModelViewMatrix*gl_Vertex;\n", 0, "\tgl_Position = gl_ProjectionMatrix*eye_pos;\n", - "l", "\tvec3 eye_normal = gl_NormalMatrix*gl_Normal;\n", + "lr", "\tvec3 eye_normal = transform_normal(gl_Normal);\n", + "l!r", "\tvec3 eye_normal = gl_NormalMatrix*gl_Normal;\n", "l!n", "\tv_normal = eye_normal;\n", "n", "\tvec3 eye_tangent = gl_NormalMatrix*tangent;\n", "n", "\tvec3 eye_binormal = gl_NormalMatrix*binormal;\n", @@ -276,7 +280,8 @@ Program::StandardFeatures::StandardFeatures(): lighting(false), specular(false), normalmap(false), - shadow(false) + shadow(false), + transform(false) { } string Program::StandardFeatures::create_flags() const @@ -296,6 +301,8 @@ string Program::StandardFeatures::create_flags() const } if(shadow) flags += 's'; + if(transform) + flags += 'r'; return flags; } @@ -349,6 +356,7 @@ Program::StandardFeatures::Loader::Loader(StandardFeatures &f): add("shadow", &StandardFeatures::shadow); add("specular", &StandardFeatures::specular); add("texture", &StandardFeatures::texture); + add("transform", &StandardFeatures::transform); } } // namespace GL diff --git a/source/program.h b/source/program.h index b875ec79..c3c6cc03 100644 --- a/source/program.h +++ b/source/program.h @@ -43,6 +43,7 @@ public: bool specular; bool normalmap; bool shadow; + bool transform; StandardFeatures();