X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fprogram.cpp;h=7598bf1572adc036f7777fa8e9741c6086102689;hb=f48b68626a98c4a0b8991764d174eb57895e805f;hp=02e0a1b4dea75ca5e3768bac82ab5be5311b01b3;hpb=b85b8b599473a76e055008a2d45432d02848cb42;p=libs%2Fgl.git diff --git a/source/program.cpp b/source/program.cpp index 02e0a1b4..7598bf15 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "arb_shader_objects.h" #include "arb_vertex_shader.h" #include "error.h" @@ -30,8 +32,10 @@ const char *standard_vertex_src[] = "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", + "nr", "\tvec3 eye_tangent = transform_normal(tangent);\n", + "n!r", "\tvec3 eye_tangent = gl_NormalMatrix*tangent;\n", + "nr", "\tvec3 eye_binormal = transform_normal(binormal);\n", + "n!r", "\tvec3 eye_binormal = gl_NormalMatrix*binormal;\n", "l", "\tvec3 eye_light_dir = normalize(gl_LightSource[0].position.xyz-eye_pos.xyz*gl_LightSource[0].position.w);\n", "n", "\tv_light_dir = vec3(dot(eye_tangent, eye_light_dir), dot(eye_binormal, eye_light_dir), dot(eye_normal, eye_light_dir));\n", "l!n", "\tv_light_dir = eye_light_dir;\n", @@ -69,20 +73,27 @@ const char *standard_fragment_src[] = /* XXX This is incorrect with normal mapping, since the vectors are in TBN space but environment map is expected to be in eye space */ "e", "\tvec4 reflection = textureCube(environment, n_normal*(dot(n_normal, v_eye_dir)*2.0)-v_eye_dir);\n", - 0, "\tgl_FragColor = ", - "!t!l!m", "vec4(1.0, 1.0, 1.0, 1.0)", - "t", "texture2D(texture, v_texcoord)", + "t", "\tvec4 tex_sample = texture2D(texture, v_texcoord);\n", + 0, "\tgl_FragColor.rgb = ", + "!t!l!m", "vec3(1.0)", + "t", "tex_sample.rgb", "l|mt", "*", - "!lm", "v_color", + "!lm", "v_color.rgb", "l", "((l_diffuse", - "lm", "*gl_FrontLightProduct[0].diffuse", + "lm", "*gl_FrontLightProduct[0].diffuse.rgb", "p", "+l_specular", - "pm", "*gl_FrontLightProduct[0].specular", + "pm", "*gl_FrontLightProduct[0].specular.rgb", "l", ")", "s", "*l_shadow", - "lm", "+gl_FrontLightModelProduct.sceneColor", + "lm", "+gl_FrontLightModelProduct.sceneColor.rgb", "l", ")", - "e", "+reflection*reflectivity", + "e", "+reflection.rgb*reflectivity", + 0, ";\n", + 0, "\tgl_FragColor.a = ", + "!m", "1.0", + "!lm", "v_color.a", + "lm", "gl_FrontMaterial.diffuse.a", + "t", "*tex_sample.a", 0, ";\n", 0, "}\n", 0, 0 @@ -237,6 +248,16 @@ void Program::link() uniforms[name] = info; } } + + string layout_descriptor; + for(map::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i) + if(i->second.location>=0) + { + if(!layout_descriptor.empty()) + layout_descriptor += '\n'; + layout_descriptor += format("%d:%s:%x", i->second.location, i->second.name, i->second.type); + } + uniform_layout_hash = hash32(layout_descriptor); } string Program::get_info_log() const