Files
valheim/Assets/_Valheim/Shaders/MRGround.shader
2025-07-04 14:16:14 +08:00

122 lines
4.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Shader "MR/MRGround" {
Properties
{
_Color("Color",COLOR)=(1,1,1,1)
}
SubShader
{
Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Transparent" "Queue"="Transparent" "UniversalMaterialType"="Lit" }
Pass //主Pass
{
Name "Forward"
Tags { "LightMode"="UniversalForward" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On
ZTest LEqual
Offset 0 , 0
ColorMask RGBA
HLSLPROGRAM
#pragma shader_feature_local _RECEIVE_SHADOWS_OFF
#pragma shader_feature_local_fragment _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
#pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
#pragma multi_compile_fragment _ _SHADOWS_SOFT
#pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
#pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
#pragma multi_compile_fragment _ _LIGHT_LAYERS
#pragma multi_compile_fragment _ _LIGHT_COOKIES
#pragma multi_compile _ _CLUSTERED_RENDERING
#pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
#pragma multi_compile _ SHADOWS_SHADOWMASK
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DYNAMICLIGHTMAP_ON
#pragma multi_compile_fragment _ DEBUG_DISPLAY
//定义顶点着色器
#pragma vertex vert
//定义片段着色器
#pragma fragment frag
#define SHADERPASS SHADERPASS_FORWARD
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
//顶点着色器的输入模型的数据信息类似于appdate
struct Attributes
{
float3 positionOS : POSITION;
};
//顶点着色器输出
struct Varyings
{
float3 positionWS: TEXCOORD1;
float4 shadowCoords:TEXCOORD6;
};
CBUFFER_START(UnityPerMaterial)
half4 _Color;
float4 _MainTex_ST;
TEXTURE2D(_MainTex);//纹理的定义如果是编译到GLES2.0平台则相当于sampler2D _MainTex;否则就相当于Texture2D _MainTex
SAMPLER(sampler_MainTex);//采样器的定义如果是编译到GLES2.0平台,就相当于空否则就相当于SamplerState sampler_MainTex
// SAMPLER(SamplerState_Point_Repeat);根据传入的名称选择采样模式,比如该传入的名称代表贴图采样的Wrap Mode为Repeat,Fiter Mode为Point
CBUFFER_END
//v2f vert(appdata v)
//顶点着色器
Varyings vert(Attributes v)
{
Varyings o;
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
return o;
}
//片断着色器
half4 frag(Varyings i) : SV_TARGET
{
half4 color = half4(0,0,0,0);
float4 shadowCoords = TransformWorldToShadowCoord(i.positionWS);
// 获取主光源
Light light = GetMainLight(shadowCoords);
// 获取阴影衰减值
half shadow_attenuation = light.shadowAttenuation;
// 使用阴影衰减值来计算软阴影
float soft_shadow = 1.0 - saturate(shadow_attenuation * 2.0 - 0.5);
// 添加固定的边缘模糊
float blur_amount = 0.1; // 调整此值以控制模糊的程度
// 使用软阴影效果和固定的边缘模糊值来混合颜色
return float4(color.rgb, 1);
}
ENDHLSL
}
}
FallBack "Hidden/Shader Graph/FallbackError"
}