95 lines
3.1 KiB
Plaintext
95 lines
3.1 KiB
Plaintext
Shader "GYGame/CCS/AddTexture"
|
|
{
|
|
Properties
|
|
{
|
|
[MainTexture] _MainTex ("主贴图", 2D) = "white" {}
|
|
[HideInInspector] _AdditionalTex ("附加贴图", 2D) = "black" {}
|
|
[HideInInspector] _Rotation ("旋转", Float) = 0
|
|
[HideInInspector] _Color ("颜色", Color) = (1,1,1,1)
|
|
[HideInInspector] _MaskTex ("遮罩", 2D) = "white" {}
|
|
[HideInInspector] _IsNormalTex ("是否为法线贴图", Float) = 0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags {
|
|
"RenderType"="Opaque"
|
|
"RenderPipeline"="UniversalPipeline"
|
|
}
|
|
LOD 100
|
|
|
|
Pass // index 0
|
|
{
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
|
|
TEXTURE2D(_AdditionalTex); SAMPLER(sampler_linear_clamp_AdditionalTex);
|
|
TEXTURE2D(_MaskTex); SAMPLER(sampler_linear_clamp_MaskTex);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _AdditionalTex_ST;
|
|
float4 _MaskTex_ST;
|
|
float _Rotation;
|
|
half4 _Color;
|
|
float _IsNormalTex;
|
|
CBUFFER_END
|
|
|
|
struct appdata
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float2 uv : TEXCOORD0;
|
|
float4 vertex : SV_POSITION;
|
|
};
|
|
|
|
float2 Rotate2D(float2 UV, float Rotation = 0, float2 Center = float2(0.5, 0.5))
|
|
{
|
|
Rotation = Rotation/360*2*PI;
|
|
UV -= Center;
|
|
float s = sin(Rotation);
|
|
float c = cos(Rotation);
|
|
float2x2 rMatrix = float2x2(c, -s, s, c);
|
|
rMatrix *= 0.5;
|
|
rMatrix += 0.5;
|
|
rMatrix = rMatrix * 2 - 1;
|
|
UV.xy = mul(UV.xy, rMatrix);
|
|
UV += Center;
|
|
return UV;
|
|
}
|
|
|
|
v2f vert(appdata v)
|
|
{
|
|
v2f o;
|
|
o.vertex = TransformObjectToHClip(v.vertex.xyz);
|
|
o.uv = v.uv;
|
|
return o;
|
|
}
|
|
|
|
half4 frag(v2f i) : SV_Target
|
|
{
|
|
//
|
|
float2 uv = Rotate2D((i.uv-_AdditionalTex_ST.zw-0.5)*(1/_AdditionalTex_ST.xy)+0.5, _Rotation);
|
|
float4 additionalColor = SAMPLE_TEXTURE2D(_AdditionalTex, sampler_linear_clamp_AdditionalTex, uv);
|
|
float4 maskColor = SAMPLE_TEXTURE2D(_MaskTex, sampler_linear_clamp_MaskTex, uv);
|
|
//
|
|
additionalColor *= _Color;
|
|
additionalColor.a *= maskColor.r;
|
|
//
|
|
float4 mainColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv);
|
|
float4 finalColor = float4(0, 0, 0, 0);
|
|
finalColor.rgb = lerp(mainColor.rgb, additionalColor.rgb, additionalColor.a);
|
|
finalColor.a = 1;
|
|
return finalColor;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |