Add disable ambient light flag to shaders and materials

This commit is contained in:
Alex Roman 2018-07-17 21:30:43 +02:00
parent f1970e15b9
commit 2ce1118faa
5 changed files with 37 additions and 33 deletions

View File

@ -913,6 +913,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n";
actions[VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
/* PARTICLES SHADER */

View File

@ -571,11 +571,6 @@ in vec3 normal_interp;
/* PBR CHANNELS */
//used on forward mainly
uniform bool no_ambient_light;
#ifdef USE_RADIANCE_MAP
@ -1752,9 +1747,9 @@ FRAGMENT_SHADER_CODE
#ifdef USE_RADIANCE_MAP
if (no_ambient_light) {
#ifdef AMBIENT_LIGHT_DISABLED
ambient_light=vec3(0.0,0.0,0.0);
} else {
#else
{
{ //read radiance from dual paraboloid
@ -1779,15 +1774,16 @@ FRAGMENT_SHADER_CODE
//ambient_light=vec3(0.0,0.0,0.0);
}
#endif
}
#endif //AMBIENT_LIGHT_DISABLED
#else
if (no_ambient_light){
#ifdef AMBIENT_LIGHT_DISABLED
ambient_light=vec3(0.0,0.0,0.0);
} else {
#else
ambient_light=ambient_light_color.rgb;
}
#endif //AMBIENT_LIGHT_DISABLED
#endif
ambient_light*=ambient_energy;

View File

@ -404,6 +404,9 @@ void SpatialMaterial::_update_shader() {
if (flags[FLAG_DONT_RECEIVE_SHADOWS]) {
code += ",shadows_disabled";
}
if (flags[FLAG_DISABLE_AMBIENT_LIGHT]) {
code += ",ambient_light_disabled";
}
if (flags[FLAG_ENSURE_CORRECT_NORMALS]) {
code += ",ensure_correct_normals";
}
@ -1866,6 +1869,7 @@ void SpatialMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_fixed_size"), "set_flag", "get_flag", FLAG_FIXED_SIZE);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_albedo_tex_force_srgb"), "set_flag", "get_flag", FLAG_ALBEDO_TEXTURE_FORCE_SRGB);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_do_not_receive_shadows"), "set_flag", "get_flag", FLAG_DONT_RECEIVE_SHADOWS);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_disable_ambient_light"), "set_flag", "get_flag", FLAG_DISABLE_AMBIENT_LIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_ensure_correct_normals"), "set_flag", "get_flag", FLAG_ENSURE_CORRECT_NORMALS);
ADD_GROUP("Vertex Color", "vertex_color");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_use_as_albedo"), "set_flag", "get_flag", FLAG_ALBEDO_FROM_VERTEX_COLOR);
@ -2057,6 +2061,7 @@ void SpatialMaterial::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_TRIPLANAR_USE_WORLD);
BIND_ENUM_CONSTANT(FLAG_ALBEDO_TEXTURE_FORCE_SRGB);
BIND_ENUM_CONSTANT(FLAG_DONT_RECEIVE_SHADOWS);
BIND_ENUM_CONSTANT(FLAG_DISABLE_AMBIENT_LIGHT);
BIND_ENUM_CONSTANT(FLAG_ENSURE_CORRECT_NORMALS);
BIND_ENUM_CONSTANT(FLAG_MAX);

View File

@ -192,6 +192,7 @@ public:
FLAG_ALBEDO_TEXTURE_FORCE_SRGB,
FLAG_DONT_RECEIVE_SHADOWS,
FLAG_ENSURE_CORRECT_NORMALS,
FLAG_DISABLE_AMBIENT_LIGHT,
FLAG_MAX
};
@ -240,7 +241,7 @@ private:
uint64_t blend_mode : 2;
uint64_t depth_draw_mode : 2;
uint64_t cull_mode : 2;
uint64_t flags : 16;
uint64_t flags : 17;
uint64_t detail_blend_mode : 2;
uint64_t diffuse_mode : 3;
uint64_t specular_mode : 2;

View File

@ -176,6 +176,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].modes.push_back("ensure_correct_normals");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("shadows_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("ambient_light_disabled");
shader_modes[VS::SHADER_SPATIAL].modes.push_back("vertex_lighting");