]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/pbrmaterial.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / materials / pbrmaterial.cpp
index 783a8bed2c37eab456e2283e5274d97394fc2075..4a5f0a419d370ef1bc935bdf15fc3ff0cd0929d5 100644 (file)
@@ -23,9 +23,11 @@ const Tag PbrMaterial::texture_tags[] =
 };
 
 PbrMaterial::PbrMaterial():
-       fresnel_lookup(get_or_create_fresnel_lookup())
+       fresnel_lookup(get_or_create_fresnel_lookup()),
+       fresnel_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
 {
        set_base_color(0.8f);
+       set_tint(1.0f);
        set_metalness(0.0f);
        set_roughness(0.5f);
        set_emission(0.0f);
@@ -35,7 +37,7 @@ const Texture2D &PbrMaterial::get_or_create_fresnel_lookup()
 {
        Resources &resources = Resources::get_global();
 
-       static const string name = "_pbr_env_fresnel_lookup.tex2d";
+       static const string name = "_pbr_fresnel_lookup.tex";
        Texture2D *fresnel_lookup = resources.find<Texture2D>(name);
        if(fresnel_lookup)
                return *fresnel_lookup;
@@ -47,21 +49,25 @@ const Texture2D &PbrMaterial::get_or_create_fresnel_lookup()
        const Program &shprog = resources.get<Program>("_pbr_fresnel_lookup.glsl.shader");
        ProgramData shdata;
        shdata.uniform("n_samples", 1024);
+       // Not actually used here, but put it in to satisfy the interface
+       shdata.uniform("roughness", 0.0f);
 
        const Mesh &mesh = resources.get<Mesh>("_fullscreen_quad.mesh");
-       Framebuffer fresnel_lookup_fbo;
-       fresnel_lookup_fbo.attach(COLOR_ATTACHMENT0, *fresnel_lookup);
-       Bind bind_fbo(fresnel_lookup_fbo);
+       Framebuffer fresnel_lookup_fbo((COLOR_ATTACHMENT,RG8));
+       fresnel_lookup_fbo.attach(COLOR_ATTACHMENT, *fresnel_lookup);
        Renderer renderer;
+       renderer.begin();
+       renderer.set_framebuffer(&fresnel_lookup_fbo);
        renderer.set_shader_program(&shprog, &shdata);
        mesh.draw(renderer);
+       renderer.end();
 
        return *fresnel_lookup;
 }
 
 void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_values) const
 {
-       module_name = "cooktorrance.glsl";
+       module_name = "pbr_material.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);
@@ -72,19 +78,6 @@ void PbrMaterial::fill_program_info(string &module_name, map<string, int> &spec_
        spec_values["use_emission_map"] = (emission.texture!=0);
 }
 
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-void PbrMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const
-{
-       attach_texture_to(base_color.texture, texturing, tex_shdata, "base_color_map");
-       attach_texture_to(metalness.texture, texturing, tex_shdata, "metalness_map");
-       attach_texture_to(roughness.texture, texturing, tex_shdata, "roughness_map");
-       attach_texture_to(normal.texture, texturing, tex_shdata, "normal_map");
-       attach_texture_to(occlusion.texture, texturing, tex_shdata, "occlusion_map");
-       attach_texture_to(emission.texture, texturing, tex_shdata, "emission_map");
-}
-#pragma GCC diagnostic pop
-
 const Texture *PbrMaterial::get_texture(Tag tag) const
 {
        if(tag==texture_tags[0])
@@ -105,6 +98,14 @@ const Texture *PbrMaterial::get_texture(Tag tag) const
                return 0;
 }
 
+const Sampler *PbrMaterial::get_sampler(Tag tag) const
+{
+       if(tag==texture_tags[6])
+               return &fresnel_sampler;
+       else
+               return sampler;
+}
+
 void PbrMaterial::set_base_color(const Color &color)
 {
        base_color.value = color;
@@ -116,6 +117,12 @@ void PbrMaterial::set_base_color_map(const Texture *tex)
        base_color.texture = tex;
 }
 
+void PbrMaterial::set_tint(const Color &color)
+{
+       tint.value = color;
+       shdata.uniform("pbr_material.tint", color);
+}
+
 void PbrMaterial::set_normal_map(const Texture *tex)
 {
        normal.texture = tex;
@@ -162,12 +169,6 @@ void PbrMaterial::set_emission_map(const Texture *tex)
 
 DataFile::Loader::ActionMap PbrMaterial::Loader::shared_actions;
 
-PbrMaterial::Loader::Loader(PbrMaterial &m):
-       DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m)
-{
-       set_actions(shared_actions);
-}
-
 PbrMaterial::Loader::Loader(PbrMaterial &m, Collection &c):
        DerivedObjectLoader<PbrMaterial, Material::PropertyLoader<PbrMaterial> >(m, c)
 {
@@ -183,6 +184,7 @@ void PbrMaterial::Loader::init_actions()
        add_property("roughness", &PbrMaterial::set_roughness, &PbrMaterial::set_roughness_map);
        add_property("occlusion", &PbrMaterial::set_occlusion_map);
        add_property("emission", &PbrMaterial::set_emission, &PbrMaterial::set_emission_map, false);
+       add_property("tint", &PbrMaterial::set_tint, 0, true);
 }
 
 } // namespace GL