From 94e20e0adf6f4027760bf90e9b9aaefbbcd8ca91 Mon Sep 17 00:00:00 2001 From: Maxim Sheronov Date: Tue, 29 Aug 2017 21:50:09 +0300 Subject: [PATCH] Add ability to select multiplication --- scene/resources/material.cpp | 15 ++++++++++++--- scene/resources/material.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index cd2ee03d9b67..f9ff81579b1f 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -417,8 +417,11 @@ void SpatialMaterial::_update_shader() { } if (features[FEATURE_EMISSION]) { - - code += "uniform sampler2D texture_emission : hint_white_albedo;\n"; + if (flags[FLAG_EMISSION_MULTIPLY]) { + code += "uniform sampler2D texture_emission : hint_white_albedo;\n"; + } else { + code += "uniform sampler2D texture_emission : hint_black_albedo;\n"; + } code += "uniform vec4 emission : hint_color;\n"; code += "uniform float emission_energy;\n"; } @@ -708,7 +711,11 @@ void SpatialMaterial::_update_shader() { } else { code += "\tvec3 emission_tex = texture(texture_emission,base_uv).rgb;\n"; } - code += "\tEMISSION = emission.rgb*emission_tex*emission_energy;\n"; + if (flags[FLAG_EMISSION_MULTIPLY]) { + code += "\tEMISSION = emission.rgb*emission_tex*emission_energy;\n"; + } else { + code += "\tEMISSION = (emission.rgb+emission_tex)*emission_energy;\n"; + } } if (features[FEATURE_REFRACTION] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //refraction not supported with triplanar @@ -1722,6 +1729,7 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::COLOR, "emission", PROPERTY_HINT_COLOR_NO_ALPHA), "set_emission", "get_emission"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "emission_energy", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_emission_energy", "get_emission_energy"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "emission_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_EMISSION); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "emission_multiply"), "set_flag", "get_flag", FLAG_EMISSION_MULTIPLY); ADD_GROUP("NormalMap", "normal_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "normal_enabled"), "set_feature", "get_feature", FEATURE_NORMAL_MAPPING); @@ -1856,6 +1864,7 @@ void SpatialMaterial::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_AO_ON_UV2); BIND_ENUM_CONSTANT(FLAG_USE_ALPHA_SCISSOR); BIND_ENUM_CONSTANT(FLAG_TRIPLANAR_USE_WORLD); + BIND_ENUM_CONSTANT(FLAG_EMISSION_MULTIPLY); BIND_ENUM_CONSTANT(FLAG_MAX); BIND_ENUM_CONSTANT(DIFFUSE_LAMBERT); diff --git a/scene/resources/material.h b/scene/resources/material.h index fdb11982a8f0..a37b78f15012 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -181,6 +181,7 @@ class SpatialMaterial : public Material { FLAG_TRIPLANAR_USE_WORLD, FLAG_AO_ON_UV2, FLAG_USE_ALPHA_SCISSOR, + FLAG_EMISSION_MULTIPLY, FLAG_MAX }; @@ -224,7 +225,7 @@ class SpatialMaterial : public Material { uint64_t blend_mode : 2; uint64_t depth_draw_mode : 2; uint64_t cull_mode : 2; - uint64_t flags : 12; + uint64_t flags : 13; uint64_t detail_blend_mode : 2; uint64_t diffuse_mode : 3; uint64_t specular_mode : 2;