From a482029babea3210840d8c62e9df9ece4342b2b9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 13 Aug 2021 13:54:33 +0300 Subject: [PATCH] Allow materials to return per-texture samplers --- source/materials/material.h | 2 +- source/materials/pbrmaterial.cpp | 11 ++++++++++- source/materials/pbrmaterial.h | 2 ++ source/materials/renderpass.cpp | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/materials/material.h b/source/materials/material.h index 43da2542..23f40857 100644 --- a/source/materials/material.h +++ b/source/materials/material.h @@ -105,7 +105,7 @@ public: virtual const Tag *get_texture_tags() const = 0; virtual const Texture *get_texture(Tag) const = 0; - const Sampler *get_sampler() const { return sampler; } + virtual const Sampler *get_sampler(Tag) const { return sampler; } void set_debug_name(const std::string &); diff --git a/source/materials/pbrmaterial.cpp b/source/materials/pbrmaterial.cpp index 08221816..f50baf9b 100644 --- a/source/materials/pbrmaterial.cpp +++ b/source/materials/pbrmaterial.cpp @@ -23,7 +23,8 @@ 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("_linear_clamp.samp")) { set_base_color(0.8f); set_metalness(0.0f); @@ -94,6 +95,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; diff --git a/source/materials/pbrmaterial.h b/source/materials/pbrmaterial.h index dadda9b5..0204451b 100644 --- a/source/materials/pbrmaterial.h +++ b/source/materials/pbrmaterial.h @@ -32,6 +32,7 @@ private: Property occlusion; Property emission; const Texture2D &fresnel_lookup; + const Sampler &fresnel_sampler; static const Tag texture_tags[]; @@ -47,6 +48,7 @@ protected: public: virtual const Tag *get_texture_tags() const { return texture_tags; } virtual const Texture *get_texture(Tag) const; + virtual const Sampler *get_sampler(Tag) const; void set_base_color(const Color &); void set_base_color_map(const Texture *); diff --git a/source/materials/renderpass.cpp b/source/materials/renderpass.cpp index 475f3ed8..70143e96 100644 --- a/source/materials/renderpass.cpp +++ b/source/materials/renderpass.cpp @@ -30,7 +30,7 @@ void RenderPass::set_material_textures() { const Tag *material_texture_tags = material->get_texture_tags(); for(const Tag *tag=material_texture_tags; tag->id; ++tag) - set_texture(*tag, material->get_texture(*tag), material->get_sampler()); + set_texture(*tag, material->get_texture(*tag), material->get_sampler(*tag)); } void RenderPass::maybe_create_material_shader() -- 2.43.0