]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/pbrmaterial.cpp
Use specialization constants in the builtin material shaders
[libs/gl.git] / source / materials / pbrmaterial.cpp
index bc7104cc652d485350614b5737b32e6a42771f80..16c287b4e40f6ad97987ac517ba57315646dc711 100644 (file)
@@ -14,28 +14,18 @@ PbrMaterial::PbrMaterial():
        set_emission(0.0f);
 }
 
-string PbrMaterial::create_program_source() const
-{
-       string source = "import cooktorrance;\n";
-       if(base_color.texture)
-               source += "const bool use_base_color_map = true;\n";
-       if(normal.texture)
-               source += "const bool use_normal_map = true;\n";
-       if(metalness.texture)
-               source += "const bool use_metalness_map = true;\n";
-       if(roughness.texture)
-               source += "const bool use_roughness_map = true;\n";
-       if(occlusion.texture)
-               source += "const bool use_occlusion_map = true;\n";
-       if(emission.texture || emission.value.r || emission.value.g || emission.value.b)
-       {
-               source += "const bool use_emission = true;\n";
-               if(emission.texture)
-                       source += "const bool use_emission_map = true;\n";
-       }
-       if(receive_shadows)
-               source += "const bool use_shadow_map = true;\n";
-       return source;
+void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
+{
+       module_name = "cooktorrance.glsl";
+       spec_values["use_base_color_map"] = (base_color.texture!=0);
+       spec_values["use_normal_map"] = (normal.texture!=0);
+       spec_values["use_metalness_map"] = (metalness.texture!=0);
+       spec_values["use_roughness_map"] = (roughness.texture!=0);
+       spec_values["use_occlusion_map"] = (occlusion.texture!=0);
+       bool use_emission = (emission.texture || emission.value.r || emission.value.g || emission.value.b);
+       spec_values["use_emission"] = use_emission;
+       spec_values["use_emission_map"] = (emission.texture!=0);
+       spec_values["use_shadow_map"] = receive_shadows;
 }
 
 void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const