From 2bf5645d38492c5ef829478f3e04e78f31802fe6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 20 Mar 2021 15:37:12 +0200 Subject: [PATCH] Adjust uniform organization for UnlitMaterial Its only property are now stored in a struct to match other material types. This allows using the name "color" without conflicting with the vertex attribute. The texture uniform was also renamed in order to avoid clashing with the texture() function. --- shaderlib/unlit.glsl | 19 ++++++++++++++----- source/materials/unlitmaterial.cpp | 12 ++++++------ source/materials/unlitmaterial.h | 4 ++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/shaderlib/unlit.glsl b/shaderlib/unlit.glsl index 57be8b1b..85275558 100644 --- a/shaderlib/unlit.glsl +++ b/shaderlib/unlit.glsl @@ -1,19 +1,28 @@ import msp_interface; import common; -uniform sampler2D texture; -uniform vec4 tint; +struct UnlitMaterialParameters +{ + vec4 color; +}; + +uniform UnlitMaterial +{ + UnlitMaterialParameters unlit_material; +}; + +uniform sampler2D color_tex; layout(constant_id=auto) const bool use_texture = false; layout(constant_id=auto) const bool use_vertex_color = false; layout(constant_id=auto) const bool use_fog = false; #pragma MSP stage(fragment) -vec4 get_color() +virtual vec4 get_color() { - vec4 result = tint; + vec4 result = unlit_material.color; if(use_texture) - result *= texture(texture, texcoord.xy); + result *= texture(color_tex, texcoord.xy); if(use_vertex_color) result *= color; return result; diff --git a/source/materials/unlitmaterial.cpp b/source/materials/unlitmaterial.cpp index 9aded252..e81be8ae 100644 --- a/source/materials/unlitmaterial.cpp +++ b/source/materials/unlitmaterial.cpp @@ -9,7 +9,7 @@ UnlitMaterial::UnlitMaterial(): texture(0), vertex_color(false) { - set_tint(Color(1.0f)); + set_color(Color(1.0f)); } void UnlitMaterial::fill_program_info(string &module_name, map &spec_values) const @@ -21,7 +21,7 @@ void UnlitMaterial::fill_program_info(string &module_name, map &spe void UnlitMaterial::attach_textures_to(Texturing &texturing, ProgramData &tex_shdata) const { - attach_texture_to(texture, texturing, tex_shdata, "texture"); + attach_texture_to(texture, texturing, tex_shdata, "color_tex"); } void UnlitMaterial::set_texture(const Texture *tex) @@ -29,10 +29,10 @@ void UnlitMaterial::set_texture(const Texture *tex) texture = tex; } -void UnlitMaterial::set_tint(const Color &t) +void UnlitMaterial::set_color(const Color &c) { - tint = t; - shdata.uniform("tint", tint); + color = c; + shdata.uniform("unlit_material.color", color); } void UnlitMaterial::set_vertex_color(bool vc) @@ -59,7 +59,7 @@ void UnlitMaterial::Loader::init_actions() { Material::PropertyLoader::init_actions(); add("texture", &Loader::property_texture, &UnlitMaterial::set_texture); - add_property("tint", &UnlitMaterial::set_tint, 0, true); + add_property("color", &UnlitMaterial::set_color, 0, true); add("vertex_color", &UnlitMaterial::vertex_color); } diff --git a/source/materials/unlitmaterial.h b/source/materials/unlitmaterial.h index 22e22691..a98b1284 100644 --- a/source/materials/unlitmaterial.h +++ b/source/materials/unlitmaterial.h @@ -26,7 +26,7 @@ public: private: const Texture *texture; - Color tint; + Color color; bool vertex_color; public: @@ -39,7 +39,7 @@ public: virtual void attach_textures_to(Texturing &, ProgramData &) const; void set_texture(const Texture *); - void set_tint(const Color &); + void set_color(const Color &); void set_vertex_color(bool); }; -- 2.43.0