mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 21:22:48 +00:00
Add disable ambient light flag to shaders and materials
This commit is contained in:
parent
f1970e15b9
commit
2ce1118faa
@ -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 */
|
||||
|
||||
|
@ -571,11 +571,6 @@ in vec3 normal_interp;
|
||||
|
||||
/* PBR CHANNELS */
|
||||
|
||||
//used on forward mainly
|
||||
uniform bool no_ambient_light;
|
||||
|
||||
|
||||
|
||||
#ifdef USE_RADIANCE_MAP
|
||||
|
||||
|
||||
@ -1752,42 +1747,43 @@ FRAGMENT_SHADER_CODE
|
||||
|
||||
#ifdef USE_RADIANCE_MAP
|
||||
|
||||
if (no_ambient_light) {
|
||||
ambient_light=vec3(0.0,0.0,0.0);
|
||||
} else {
|
||||
{
|
||||
#ifdef AMBIENT_LIGHT_DISABLED
|
||||
ambient_light=vec3(0.0,0.0,0.0);
|
||||
#else
|
||||
{
|
||||
|
||||
{ //read radiance from dual paraboloid
|
||||
{ //read radiance from dual paraboloid
|
||||
|
||||
vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n);
|
||||
ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz);
|
||||
vec3 radiance = textureDualParaboloid(radiance_map,ref_vec,roughness) * bg_energy;
|
||||
env_reflection_light = radiance;
|
||||
|
||||
}
|
||||
//no longer a cubemap
|
||||
//vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y);
|
||||
vec3 ref_vec = reflect(-eye_vec,normal); //2.0 * ndotv * normal - view; // reflect(v, n);
|
||||
ref_vec=normalize((radiance_inverse_xform * vec4(ref_vec,0.0)).xyz);
|
||||
vec3 radiance = textureDualParaboloid(radiance_map,ref_vec,roughness) * bg_energy;
|
||||
env_reflection_light = radiance;
|
||||
|
||||
}
|
||||
#ifndef USE_LIGHTMAP
|
||||
{
|
||||
//no longer a cubemap
|
||||
//vec3 radiance = textureLod(radiance_cube, r, lod).xyz * ( brdf.x + brdf.y);
|
||||
|
||||
vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz);
|
||||
vec3 env_ambient=textureDualParaboloid(radiance_map,ambient_dir,1.0) * bg_energy;
|
||||
|
||||
ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution);
|
||||
//ambient_light=vec3(0.0,0.0,0.0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifndef USE_LIGHTMAP
|
||||
{
|
||||
|
||||
vec3 ambient_dir=normalize((radiance_inverse_xform * vec4(normal,0.0)).xyz);
|
||||
vec3 env_ambient=textureDualParaboloid(radiance_map,ambient_dir,1.0) * bg_energy;
|
||||
|
||||
ambient_light=mix(ambient_light_color.rgb,env_ambient,radiance_ambient_contribution);
|
||||
//ambient_light=vec3(0.0,0.0,0.0);
|
||||
}
|
||||
#endif
|
||||
#endif //AMBIENT_LIGHT_DISABLED
|
||||
|
||||
#else
|
||||
|
||||
if (no_ambient_light){
|
||||
ambient_light=vec3(0.0,0.0,0.0);
|
||||
} else {
|
||||
ambient_light=ambient_light_color.rgb;
|
||||
}
|
||||
#ifdef AMBIENT_LIGHT_DISABLED
|
||||
ambient_light=vec3(0.0,0.0,0.0);
|
||||
#else
|
||||
ambient_light=ambient_light_color.rgb;
|
||||
#endif //AMBIENT_LIGHT_DISABLED
|
||||
|
||||
#endif
|
||||
|
||||
ambient_light*=ambient_energy;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user