diff --git a/drivers/gles3/shader_compiler_gles3.cpp b/drivers/gles3/shader_compiler_gles3.cpp index 54cbc07f59b..206f270f687 100644 --- a/drivers/gles3/shader_compiler_gles3.cpp +++ b/drivers/gles3/shader_compiler_gles3.cpp @@ -796,6 +796,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() { actions[VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n"; actions[VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n"; 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"; /* PARTICLES SHADER */ diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 545c7b2605b..6fbfeeff6c7 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -777,7 +777,7 @@ LIGHT_SHADER_CODE #elif defined(DIFFUSE_TOON) - diffuse += smoothstep(-roughness,roughness,dot(N,L)) * light_color * diffuse_color; + diffuse += smoothstep(-roughness,max(roughness,0.01),dot(N,L)) * light_color * diffuse_color; #elif defined(DIFFUSE_BURLEY) @@ -817,23 +817,26 @@ LIGHT_SHADER_CODE vec3 H = normalize(V + L); float dotNH = max(dot(N,H), 0.0 ); float intensity = pow( dotNH, (1.0-roughness) * 256.0); - specular += light_color * intensity; + specular += light_color * intensity * specular_blob_intensity; #elif defined(SPECULAR_PHONG) vec3 R = normalize(-reflect(L,N)); float dotNV = max(0.0,dot(R,V)); float intensity = pow( dotNV, (1.0-roughness) * 256.0); - specular += light_color * intensity; + specular += light_color * intensity * specular_blob_intensity; #elif defined(SPECULAR_TOON) vec3 R = normalize(-reflect(L,N)); float dotNV = dot(R,V); float mid = 1.0-roughness; - float intensity = smoothstep(mid-roughness*0.5,mid+roughness*0.5,dotNV); - diffuse += light_color * intensity; //write to diffuse, as in toon shading you generally want no reflection + mid*=mid; + float intensity = smoothstep(mid-roughness*0.5,mid+roughness*0.5,dotNV) * mid; + diffuse += light_color * intensity * specular_blob_intensity; //write to diffuse, as in toon shading you generally want no reflection +#elif defined(SPECULAR_DISABLED) + //none.. #else // shlick+ggx as default @@ -966,7 +969,7 @@ vec3 light_transmittance(float translucency,vec3 light_vec, vec3 normal, vec3 po } #endif -void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,inout vec3 diffuse_light, inout vec3 specular_light) { +void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 binormal, vec3 tangent, vec3 albedo, float roughness, float rim, float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,float p_blob_intensity,inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = omni_lights[idx].light_pos_inv_radius.xyz-vertex; float light_length = length( light_rel_vec ); @@ -1017,11 +1020,11 @@ void light_process_omni(int idx, vec3 vertex, vec3 eye_vec,vec3 normal,vec3 bino light_attenuation*=mix(omni_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } - light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,omni_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,omni_lights[idx].light_color_energy.rgb*light_attenuation,albedo,omni_lights[idx].light_params.z*p_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } -void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy, inout vec3 diffuse_light, inout vec3 specular_light) { +void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 binormal, vec3 tangent,vec3 albedo, float roughness, float rim,float rim_tint, float clearcoat, float clearcoat_gloss,float anisotropy,float p_blob_intensity, inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = spot_lights[idx].light_pos_inv_radius.xyz-vertex; float light_length = length( light_rel_vec ); @@ -1050,7 +1053,7 @@ void light_process_spot(int idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 bi light_attenuation*=mix(spot_lights[idx].shadow_color_contact.rgb,vec3(1.0),shadow); } - light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,spot_lights[idx].light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,normalize(light_rel_vec),eye_vec,binormal,tangent,spot_lights[idx].light_color_energy.rgb*light_attenuation,albedo,spot_lights[idx].light_params.z*p_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); } @@ -1509,6 +1512,11 @@ FRAGMENT_SHADER_CODE ambient_light*=ambient_energy; + float specular_blob_intensity=1.0; +#if defined(SPECULAR_TOON) + specular_blob_intensity*=specular * 2.0; +#endif + #ifdef USE_LIGHT_DIRECTIONAL vec3 light_attenuation=vec3(1.0); @@ -1648,7 +1656,7 @@ FRAGMENT_SHADER_CODE #endif //LIGHT_DIRECTIONAL_SHADOW - light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); + light_compute(normal,-light_direction_attenuation.xyz,eye_vec,binormal,tangent,light_color_energy.rgb*light_attenuation,albedo,light_params.z*specular_blob_intensity,roughness,rim,rim_tint,clearcoat,clearcoat_gloss,anisotropy,diffuse_light,specular_light); #endif //#USE_LIGHT_DIRECTIONAL @@ -1664,8 +1672,6 @@ FRAGMENT_SHADER_CODE highp vec4 reflection_accum = vec4(0.0,0.0,0.0,0.0); highp vec4 ambient_accum = vec4(0.0,0.0,0.0,0.0); - - for(int i=0;i 0.5) { diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 22c7744c848..705702b8be7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -325,6 +325,7 @@ void SpatialMaterial::_update_shader() { case SPECULAR_BLINN: code += ",specular_blinn"; break; case SPECULAR_PHONG: code += ",specular_phong"; break; case SPECULAR_TOON: code += ",specular_toon"; break; + case SPECULAR_DISABLED: code += ",specular_disabled"; break; } if (flags[FLAG_UNSHADED]) { @@ -1458,7 +1459,7 @@ void SpatialMaterial::_bind_methods() { ADD_GROUP("Parameters", "params_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_diffuse_mode", PROPERTY_HINT_ENUM, "Lambert,Lambert Wrap,Oren Nayar,Burley,Toon"), "set_diffuse_mode", "get_diffuse_mode"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "params_specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Blinn,Phong,Toon"), "set_specular_mode", "get_specular_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "params_specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Blinn,Phong,Toon,Disabled"), "set_specular_mode", "get_specular_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul"), "set_blend_mode", "get_blend_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_cull_mode", PROPERTY_HINT_ENUM, "Back,Front,Disabled"), "set_cull_mode", "get_cull_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "params_depth_draw_mode", PROPERTY_HINT_ENUM, "Opaque Only,Always,Never,Opaque Pre-Pass"), "set_depth_draw_mode", "get_depth_draw_mode"); @@ -1621,6 +1622,7 @@ void SpatialMaterial::_bind_methods() { BIND_CONSTANT(SPECULAR_BLINN); BIND_CONSTANT(SPECULAR_PHONG); BIND_CONSTANT(SPECULAR_TOON); + BIND_CONSTANT(SPECULAR_DISABLED); BIND_CONSTANT(BILLBOARD_DISABLED); BIND_CONSTANT(BILLBOARD_ENABLED); diff --git a/scene/resources/material.h b/scene/resources/material.h index 1a9822a1c8f..276064bce46 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -179,6 +179,7 @@ public: SPECULAR_BLINN, SPECULAR_PHONG, SPECULAR_TOON, + SPECULAR_DISABLED, }; enum BillboardMode { diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 9cd7a3faeb7..599a6419a79 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -142,6 +142,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_blinn"); shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_phong"); shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_toon"); + shader_modes[VS::SHADER_SPATIAL].modes.insert("specular_disabled"); shader_modes[VS::SHADER_SPATIAL].modes.insert("skip_vertex_transform"); shader_modes[VS::SHADER_SPATIAL].modes.insert("world_vertex_coords");