Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emission calculation for spatial shader #10441

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions scene/resources/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,11 @@ void SpatialMaterial::_update_shader() {
}

if (features[FEATURE_EMISSION]) {

code += "uniform sampler2D texture_emission : hint_black_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";
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion scene/resources/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
Expand Down