From ea9ff6dc084178bc39c5f7ba593f504078232fb5 Mon Sep 17 00:00:00 2001 From: ksh999000 <740612340@qq.com> Date: Mon, 6 Jul 2026 16:26:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=B0=83=E6=95=B4shader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shaders/IndianOcean_DarknessOverlay.mat | 2 +- .../Light/shaders/SpriteWithGroundClip.shader | 27 ++++++++++++++++--- .../Light/shaders/WaterReflection.shader | 2 +- .../Assets/Materials/cloud1_GroundClipMat.mat | 9 +++++++ unity/Assets/Scenes/Gameplay.unity | 2 +- unity/UserSettings/EditorUserSettings.asset | 4 +-- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/unity/Assets/Light/shaders/IndianOcean_DarknessOverlay.mat b/unity/Assets/Light/shaders/IndianOcean_DarknessOverlay.mat index 2abee3a..93efba6 100644 --- a/unity/Assets/Light/shaders/IndianOcean_DarknessOverlay.mat +++ b/unity/Assets/Light/shaders/IndianOcean_DarknessOverlay.mat @@ -31,7 +31,7 @@ Material: - _EchoRadius: 39.41617 - _EchoWidth: 2.5 - _LightSoftness: 1 - - _MinBrightness: 0 + - _MinBrightness: 1 m_Colors: - _DarknessColor: {r: 0.01, g: 0.01, b: 0.02, a: 1} - _EchoCenter: {r: -2.4399998, g: -1.5000057, b: 0, a: 0} diff --git a/unity/Assets/Light/shaders/SpriteWithGroundClip.shader b/unity/Assets/Light/shaders/SpriteWithGroundClip.shader index a3616d5..615eacc 100644 --- a/unity/Assets/Light/shaders/SpriteWithGroundClip.shader +++ b/unity/Assets/Light/shaders/SpriteWithGroundClip.shader @@ -18,6 +18,11 @@ Shader "Custom/SpriteWithGroundClip" // 颜色 _Color ("颜色", Color) = (1, 1, 1, 1) + + // 光照设置 + _LightIntensity ("光照强度", Range(0, 2)) = 1.0 + _AmbientColor ("环境光颜色", Color) = (0.3, 0.3, 0.3, 1.0) + [MaterialToggle] _ReceiveLighting ("接受光照", Float) = 1.0 } SubShader { @@ -68,6 +73,9 @@ Shader "Custom/SpriteWithGroundClip" float _GroundHeight; float _EnableClip; float _ClipSoftness; + float _LightIntensity; + float4 _AmbientColor; + float _ReceiveLighting; CBUFFER_END TEXTURE2D(_MainTex); @@ -94,9 +102,19 @@ Shader "Custom/SpriteWithGroundClip" half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv); half4 color = texColor * input.color * _Color; - // 直接接受 Directional Light 的颜色和强度(color 已包含 intensity) - Light mainLight = GetMainLight(); - color.rgb *= mainLight.color; + // 光照计算 + if (_ReceiveLighting > 0.5) + { + // 获取主光源(颜色已包含强度) + Light mainLight = GetMainLight(); + half3 lightColor = mainLight.color; + + // Sprite无网格法线,直接用光源颜色作为受光亮度 + // 环境光提供基础亮度,漫反射光叠加方向光颜色 + half3 ambient = _AmbientColor.rgb; + half3 diffuse = lightColor * _LightIntensity; + color.rgb *= (ambient + diffuse); + } // 地面裁剪逻辑 if (_EnableClip > 0.5) @@ -168,6 +186,9 @@ Shader "Custom/SpriteWithGroundClip" float _ShadowOpacity; float _ShadowOffset; float4 _ShadowColor; + float _LightIntensity; + float4 _AmbientColor; + float _ReceiveLighting; CBUFFER_END TEXTURE2D(_MainTex); diff --git a/unity/Assets/Light/shaders/WaterReflection.shader b/unity/Assets/Light/shaders/WaterReflection.shader index 62c592d..07b5091 100644 --- a/unity/Assets/Light/shaders/WaterReflection.shader +++ b/unity/Assets/Light/shaders/WaterReflection.shader @@ -192,7 +192,7 @@ Shader "IndianOcean/WaterReflection" // UI 裁剪矩形裁剪 #ifdef UNITY_UI_CLIP_RECT - float2 clipPos = positionCS.xy; + float2 clipPos = input.positionCS.xy; float clip = 1.0; clip *= step(0.0, clipPos.x - _ClipRect.x); clip *= step(0.0, clipPos.y - _ClipRect.y); diff --git a/unity/Assets/Materials/cloud1_GroundClipMat.mat b/unity/Assets/Materials/cloud1_GroundClipMat.mat index 90fb413..fa20b6c 100644 --- a/unity/Assets/Materials/cloud1_GroundClipMat.mat +++ b/unity/Assets/Materials/cloud1_GroundClipMat.mat @@ -13,7 +13,9 @@ Material: m_ModifiedSerializedProperties: 0 m_ValidKeywords: [] m_InvalidKeywords: + - _CASTSHADOW_ON - _ENABLECLIP_ON + - _RECEIVELIGHTING_ON m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -30,9 +32,16 @@ Material: m_Offset: {x: 0, y: 0} m_Ints: [] m_Floats: + - _CastShadow: 1 - _ClipSoftness: 0.05 - _EnableClip: 1 - _GroundHeight: 0 + - _LightIntensity: 1 + - _ReceiveLighting: 1 + - _ShadowOffset: -0.1 + - _ShadowOpacity: 0.5 m_Colors: + - _AmbientColor: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1} + - _ShadowColor: {r: 0, g: 0, b: 0, a: 0.5} m_BuildTextureStacks: [] diff --git a/unity/Assets/Scenes/Gameplay.unity b/unity/Assets/Scenes/Gameplay.unity index e95f137..5c815ce 100644 --- a/unity/Assets/Scenes/Gameplay.unity +++ b/unity/Assets/Scenes/Gameplay.unity @@ -371,7 +371,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: darknessMaterial: {fileID: 2100000, guid: 6dd18d2379aff3040813ab8005b1898a, type: 2} - debugShowAll: 0 + debugShowAll: 1 minBrightness: 0 darknessColor: {r: 0.01, g: 0.01, b: 0.02, a: 1} lightSoftness: 1 diff --git a/unity/UserSettings/EditorUserSettings.asset b/unity/UserSettings/EditorUserSettings.asset index 0e02cd4..3f9c886 100644 --- a/unity/UserSettings/EditorUserSettings.asset +++ b/unity/UserSettings/EditorUserSettings.asset @@ -30,10 +30,10 @@ EditorUserSettings: value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a flags: 0 RecentlyUsedSceneGuid-8: - value: 5a55515156575a0b0f56592346260f444f16197c7e7f24697d2a4a32b1b0353e + value: 0209025f575750595c57092149765d444e4e49727e7c7068757b1c65b6e36c3b flags: 0 RecentlyUsedSceneGuid-9: - value: 0209025f575750595c57092149765d444e4e49727e7c7068757b1c65b6e36c3b + value: 5a55515156575a0b0f56592346260f444f16197c7e7f24697d2a4a32b1b0353e flags: 0 UnityEditor.ShaderGraph.Blackboard: value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba75e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1bf968e93e2ffcbc3e7e2f0b3ffe0e8b0be9af8ffaeffff8e85dd8390e3949c8899daa7