From 8452e6cdb35fbb04ee4cccaa9a0c09fa37ef5738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Aires=20Rast=C3=A9n?= Date: Sat, 18 Mar 2023 10:03:07 +0100 Subject: [PATCH] Add SPECULAR_AMOUNT spatial light shader built-in Light3D has a light_specular property which is used to set the intensity of specular contributed by this light source, but it was previously only used by the default material light shader, and not possible to use in a custom light() shader. --- drivers/gles3/shaders/scene.glsl | 2 +- drivers/gles3/storage/material_storage.cpp | 1 + .../forward_clustered/scene_shader_forward_clustered.cpp | 1 + .../renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp | 1 + servers/rendering/shader_types.cpp | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index ac5d0faccf4..37976bb9a01 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -771,7 +771,7 @@ void light_compute(vec3 N, vec3 L, vec3 V, float A, vec3 light_color, bool is_di alpha = min(alpha, clamp(1.0 - attenuation, 0.0, 1.0)); #endif -#endif // LIGHT_CODE_USED +#endif // USE_LIGHT_SHADER_CODE } float get_omni_spot_attenuation(float distance, float inv_range, float decay) { diff --git a/drivers/gles3/storage/material_storage.cpp b/drivers/gles3/storage/material_storage.cpp index 60a8a41abe8..c09a61d6e76 100644 --- a/drivers/gles3/storage/material_storage.cpp +++ b/drivers/gles3/storage/material_storage.cpp @@ -1660,6 +1660,7 @@ MaterialStorage::MaterialStorage() { //for light actions.renames["VIEW"] = "view"; + actions.renames["SPECULAR_AMOUNT"] = "specular_amount"; actions.renames["LIGHT_COLOR"] = "light_color"; actions.renames["LIGHT_IS_DIRECTIONAL"] = "is_directional"; actions.renames["LIGHT"] = "light"; diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index 6c948d3474e..7d2f14ae0b5 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -641,6 +641,7 @@ void SceneShaderForwardClustered::init(const String p_defines) { //for light actions.renames["VIEW"] = "view"; + actions.renames["SPECULAR_AMOUNT"] = "specular_amount"; actions.renames["LIGHT_COLOR"] = "light_color"; actions.renames["LIGHT_IS_DIRECTIONAL"] = "is_directional"; actions.renames["LIGHT"] = "light"; diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp index a93b9944670..0427b7c328c 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp @@ -531,6 +531,7 @@ void SceneShaderForwardMobile::init(const String p_defines) { //for light actions.renames["VIEW"] = "view"; + actions.renames["SPECULAR_AMOUNT"] = "specular_amount"; actions.renames["LIGHT_COLOR"] = "light_color"; actions.renames["LIGHT_IS_DIRECTIONAL"] = "is_directional"; actions.renames["LIGHT"] = "light"; diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index d95caeddc53..4e8057ef8fa 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -187,6 +187,7 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["UV"] = constt(ShaderLanguage::TYPE_VEC2); shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["UV2"] = constt(ShaderLanguage::TYPE_VEC2); shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["VIEW"] = constt(ShaderLanguage::TYPE_VEC3); + shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["SPECULAR_AMOUNT"] = constt(ShaderLanguage::TYPE_FLOAT); shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT_COLOR"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[RS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT_IS_DIRECTIONAL"] = constt(ShaderLanguage::TYPE_BOOL);