修改为单独调整shader
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user