Added light affect parameter to baked AO

This commit is contained in:
Juan Linietsky 2017-09-23 23:10:34 -03:00
parent 3c857033df
commit 81c9cfdc1b
5 changed files with 34 additions and 0 deletions

View file

@ -787,6 +787,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength"; actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength";
actions[VS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission"; actions[VS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission";
actions[VS::SHADER_SPATIAL].renames["AO"] = "ao"; actions[VS::SHADER_SPATIAL].renames["AO"] = "ao";
actions[VS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect";
actions[VS::SHADER_SPATIAL].renames["EMISSION"] = "emission"; actions[VS::SHADER_SPATIAL].renames["EMISSION"] = "emission";
//actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2; //actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2;
actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord"; actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord";
@ -806,6 +807,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n"; actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n";
actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY"; actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY";
actions[VS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n"; actions[VS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n";
actions[VS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n";
actions[VS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n"; actions[VS::SHADER_SPATIAL].usage_defines["UV"] = "#define ENABLE_UV_INTERP\n";
actions[VS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n"; actions[VS::SHADER_SPATIAL].usage_defines["UV2"] = "#define ENABLE_UV2_INTERP\n";
actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n"; actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP"] = "#define ENABLE_NORMALMAP\n";

View file

@ -1536,6 +1536,7 @@ void main() {
#if defined(ENABLE_AO) #if defined(ENABLE_AO)
float ao=1.0; float ao=1.0;
float ao_light_affect=0.0;
#endif #endif
float alpha = 1.0; float alpha = 1.0;
@ -1920,9 +1921,13 @@ FRAGMENT_SHADER_CODE
#if defined(ENABLE_AO) #if defined(ENABLE_AO)
ambient_light*=ao; ambient_light*=ao;
ao_light_affect = mix(1.0,ao,ao_light_affect);
specular_light*=ao_light_affect;
diffuse_light*=ao_light_affect;
#endif #endif
//energu conservation //energu conservation
diffuse_light=mix(diffuse_light,vec3(0.0),metallic); diffuse_light=mix(diffuse_light,vec3(0.0),metallic);
ambient_light=mix(ambient_light,vec3(0.0),metallic); ambient_light=mix(ambient_light,vec3(0.0),metallic);

View file

@ -268,6 +268,8 @@ void SpatialMaterial::init_shaders() {
shader_names->grow = "grow"; shader_names->grow = "grow";
shader_names->ao_light_affect = "ao_light_affect";
shader_names->proximity_fade_distance = "proximity_fade_distance"; shader_names->proximity_fade_distance = "proximity_fade_distance";
shader_names->distance_fade_min = "distance_fade_min"; shader_names->distance_fade_min = "distance_fade_min";
shader_names->distance_fade_max = "distance_fade_max"; shader_names->distance_fade_max = "distance_fade_max";
@ -462,6 +464,7 @@ void SpatialMaterial::_update_shader() {
if (features[FEATURE_AMBIENT_OCCLUSION]) { if (features[FEATURE_AMBIENT_OCCLUSION]) {
code += "uniform sampler2D texture_ambient_occlusion : hint_white;\n"; code += "uniform sampler2D texture_ambient_occlusion : hint_white;\n";
code += "uniform vec4 ao_texture_channel;\n"; code += "uniform vec4 ao_texture_channel;\n";
code += "uniform float ao_light_affect;\n";
} }
if (features[FEATURE_DETAIL]) { if (features[FEATURE_DETAIL]) {
@ -796,6 +799,8 @@ void SpatialMaterial::_update_shader() {
code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n"; code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n";
} }
} }
code += "\tAO_LIGHT_AFFECT = ao_light_affect;\n";
} }
if (features[FEATURE_SUBSURACE_SCATTERING]) { if (features[FEATURE_SUBSURACE_SCATTERING]) {
@ -1012,6 +1017,16 @@ float SpatialMaterial::get_rim_tint() const {
return rim_tint; return rim_tint;
} }
void SpatialMaterial::set_ao_light_affect(float p_ao_light_affect) {
ao_light_affect = p_ao_light_affect;
VS::get_singleton()->material_set_param(_get_material(), shader_names->ao_light_affect, p_ao_light_affect);
}
float SpatialMaterial::get_ao_light_affect() const {
return ao_light_affect;
}
void SpatialMaterial::set_clearcoat(float p_clearcoat) { void SpatialMaterial::set_clearcoat(float p_clearcoat) {
clearcoat = p_clearcoat; clearcoat = p_clearcoat;
@ -1745,6 +1760,9 @@ void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_grow", "amount"), &SpatialMaterial::set_grow); ClassDB::bind_method(D_METHOD("set_grow", "amount"), &SpatialMaterial::set_grow);
ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow); ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow);
ClassDB::bind_method(D_METHOD("set_ao_light_affect", "amount"), &SpatialMaterial::set_ao_light_affect);
ClassDB::bind_method(D_METHOD("get_ao_light_affect"), &SpatialMaterial::get_ao_light_affect);
ClassDB::bind_method(D_METHOD("set_alpha_scissor_threshold", "threshold"), &SpatialMaterial::set_alpha_scissor_threshold); ClassDB::bind_method(D_METHOD("set_alpha_scissor_threshold", "threshold"), &SpatialMaterial::set_alpha_scissor_threshold);
ClassDB::bind_method(D_METHOD("get_alpha_scissor_threshold"), &SpatialMaterial::get_alpha_scissor_threshold); ClassDB::bind_method(D_METHOD("get_alpha_scissor_threshold"), &SpatialMaterial::get_alpha_scissor_threshold);
@ -1853,6 +1871,7 @@ void SpatialMaterial::_bind_methods() {
ADD_GROUP("Ambient Occlusion", "ao_"); ADD_GROUP("Ambient Occlusion", "ao_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao_light_affect", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao_light_affect", "get_ao_light_affect");
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_on_uv2"), "set_flag", "get_flag", FLAG_AO_ON_UV2); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_on_uv2"), "set_flag", "get_flag", FLAG_AO_ON_UV2);
ADD_PROPERTY(PropertyInfo(Variant::INT, "ao_texture_channel", PROPERTY_HINT_ENUM, "Red,Green,Blue,Alpha,Gray"), "set_ao_texture_channel", "get_ao_texture_channel"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ao_texture_channel", PROPERTY_HINT_ENUM, "Red,Green,Blue,Alpha,Gray"), "set_ao_texture_channel", "get_ao_texture_channel");
@ -2036,6 +2055,8 @@ SpatialMaterial::SpatialMaterial()
set_distance_fade_min_distance(0); set_distance_fade_min_distance(0);
set_distance_fade_max_distance(10); set_distance_fade_max_distance(10);
set_ao_light_affect(0.0);
set_metallic_texture_channel(TEXTURE_CHANNEL_RED); set_metallic_texture_channel(TEXTURE_CHANNEL_RED);
set_roughness_texture_channel(TEXTURE_CHANNEL_RED); set_roughness_texture_channel(TEXTURE_CHANNEL_RED);
set_ao_texture_channel(TEXTURE_CHANNEL_RED); set_ao_texture_channel(TEXTURE_CHANNEL_RED);

View file

@ -315,6 +315,7 @@ private:
StringName proximity_fade_distance; StringName proximity_fade_distance;
StringName distance_fade_min; StringName distance_fade_min;
StringName distance_fade_max; StringName distance_fade_max;
StringName ao_light_affect;
StringName metallic_texture_channel; StringName metallic_texture_channel;
StringName roughness_texture_channel; StringName roughness_texture_channel;
@ -358,6 +359,7 @@ private:
float point_size; float point_size;
float alpha_scissor_threshold; float alpha_scissor_threshold;
bool grow_enabled; bool grow_enabled;
float ao_light_affect;
float grow; float grow;
int particles_anim_h_frames; int particles_anim_h_frames;
int particles_anim_v_frames; int particles_anim_v_frames;
@ -443,6 +445,9 @@ public:
void set_rim_tint(float p_rim_tint); void set_rim_tint(float p_rim_tint);
float get_rim_tint() const; float get_rim_tint() const;
void set_ao_light_affect(float p_ao_light_affect);
float get_ao_light_affect() const;
void set_clearcoat(float p_clearcoat); void set_clearcoat(float p_clearcoat);
float get_clearcoat() const; float get_clearcoat() const;

View file

@ -105,6 +105,7 @@ ShaderTypes::ShaderTypes() {
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_STRENGTH"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_STRENGTH"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["TRANSMISSION"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["TRANSMISSION"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["AO"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["AO"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["AO_LIGHT_AFFECT"] = ShaderLanguage::TYPE_FLOAT;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["EMISSION"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["EMISSION"] = ShaderLanguage::TYPE_VEC3;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D;
shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["DEPTH_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["DEPTH_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D;