Files
back_cantanBuilding/LocalPackages/zzwater/shaders/wind_cloth.shader
2026-05-26 16:15:54 +08:00

106 lines
3.1 KiB
Plaintext

Shader "zzwind/WindClothUnlit"
{
Properties
{
[MainTexture] _BaseMap("Texture", 2D) = "white" {}
[MainColor] _BaseColor("Color", Color) = (1, 1, 1, 1)
_Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5
_Wind("Wind params",Vector) = (1,1,1,1)
_WindAmplitude("Wind Amplitude", float) = 0.5
_WindSpeed("Wind Speed",float) = 0.5
}
SubShader
{
Tags
{
"RenderType" = "Opaque"
"IgnoreProjector" = "True"
"UniversalMaterialType" = "Unlit"
"RenderPipeline" = "UniversalPipeline"
}
Pass
{
Name "Unlit"
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
ZWrite On
Cull Back
ZTest LEqual
ZClip On
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/zzwater/shaders/libs/WindAnim.hlsl"
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
float _Cutoff;
half4 _BaseColor;
half4 _BaseMap_ST;
half4 _Wind;
float _WindAmplitude;
float _WindSpeed;
CBUFFER_END
struct Attributes
{
float4 positionOS : POSITION;
float4 tangentOS : TANGENT;
float2 uv : TEXCOORD0;
float3 normalOS : NORMAL;
float4 color : COLOR;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : TEXCOORD2;
};
Varyings vert(Attributes input)
{
Varyings output;
float bendingFact = input.color.a;
float4 wind;
wind.xyz = _Wind.xyz;
wind.w = _Wind.w * bendingFact.x;
float4 windParams = float4(0,_WindAmplitude,bendingFact,0);
float windTime = _Time.y * _WindSpeed;
float4 VertexInWndPos = ClothWindAnim(input.positionOS,input.normalOS,windParams,wind,windTime);
output.positionCS = TransformObjectToHClip(VertexInWndPos);
output.uv = TRANSFORM_TEX(input.uv, _BaseMap);
output.color = input.color;
return output;
}
float4 frag(Varyings input) : SV_Target
{
half2 uv = input.uv;
half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
half3 color = texColor.rgb * _BaseColor.rgb;
half alpha = texColor.a * _BaseColor.a;
clip(alpha - _Cutoff);
return float4(color, alpha);
}
ENDHLSL
}
}
}