113 lines
4.2 KiB
GLSL
113 lines
4.2 KiB
GLSL
Shader "Boke/Addmul" {
|
||
Properties {
|
||
[HideInInspector] _AlphaCutoff ("Alpha Cutoff ", Range(0, 1)) = 0.5
|
||
[HideInInspector] _EmissionColor ("Emission Color", Vector) = (1,1,1,1)
|
||
[ASEBegin] _Color ("Color", Vector) = (1,1,1,1)
|
||
_MainTex ("Main Tex", 2D) = "white" {}
|
||
_qd ("qd", Float) = 1
|
||
[ASEEnd] _opacity ("opacity", Float) = 0.5
|
||
[HideInInspector] _texcoord ("", 2D) = "white" {}
|
||
[Enum(Off,0,Front,1,Back,2)] __CullMode ("CullMode(Back时背面看不见,Off时双面可见)", Float) = 0
|
||
[Enum(Off,0,On,1)] __ZWrite ("ZWrite(开启时,会写入深度)", Float) = 0
|
||
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp ("StencilComp(模板测试的比较方法)", Float) = 0
|
||
// --- UI 遮罩:uGUI MaskableGraphic / UIParticle 依赖以下属性名,勿改名 ---
|
||
_Stencil ("Stencil ID", Float) = 0
|
||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilOp ("Stencil Operation", Float) = 0
|
||
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
||
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||
_ColorMask ("Color Mask", Float) = 15
|
||
// --- 兼容旧的模板测试命名(保留声明,避免旧材质缺属性)---
|
||
_StencilRef ("StencilRef(模板测试时的参考值)", Float) = 0
|
||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilPassOp ("StenciPassOp(模板测试成功时的操作)", Float) = 0
|
||
[Enum(UnityEngine.Rendering.StencilOp)] _StencilFailOp ("StenciFailOp(模板测试失败时的操作)", Float) = 0
|
||
}
|
||
SubShader {
|
||
Tags {
|
||
"RenderType" = "Transparent"
|
||
"Queue" = "Transparent"
|
||
"RenderPipeline" = "UniversalPipeline"
|
||
"IgnoreProjector" = "True"
|
||
}
|
||
LOD 100
|
||
|
||
Cull [__CullMode]
|
||
ZWrite [__ZWrite]
|
||
Blend SrcAlpha One
|
||
ColorMask [_ColorMask]
|
||
ZTest LEqual
|
||
|
||
Stencil {
|
||
Ref [_Stencil]
|
||
Comp [_StencilComp]
|
||
Pass [_StencilOp]
|
||
ReadMask [_StencilReadMask]
|
||
WriteMask [_StencilWriteMask]
|
||
}
|
||
|
||
Pass {
|
||
Name "ForwardLit"
|
||
Tags { "LightMode" = "UniversalForward" }
|
||
|
||
HLSLPROGRAM
|
||
#pragma target 2.0
|
||
#pragma vertex vert
|
||
#pragma fragment frag
|
||
#pragma multi_compile_instancing
|
||
|
||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||
|
||
struct Attributes {
|
||
float4 positionOS : POSITION;
|
||
float2 uv : TEXCOORD0;
|
||
float4 color : COLOR;
|
||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||
};
|
||
|
||
struct Varyings {
|
||
float4 positionCS : SV_POSITION;
|
||
float2 uv : TEXCOORD0;
|
||
float4 color : COLOR;
|
||
UNITY_VERTEX_OUTPUT_STEREO
|
||
};
|
||
|
||
TEXTURE2D(_MainTex);
|
||
SAMPLER(sampler_MainTex);
|
||
|
||
CBUFFER_START(UnityPerMaterial)
|
||
float4 _MainTex_ST;
|
||
half4 _Color;
|
||
half _qd;
|
||
half _opacity;
|
||
CBUFFER_END
|
||
|
||
Varyings vert(Attributes input) {
|
||
Varyings output = (Varyings)0;
|
||
UNITY_SETUP_INSTANCE_ID(input);
|
||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||
output.uv = TRANSFORM_TEX(input.uv, _MainTex);
|
||
output.color = input.color;
|
||
return output;
|
||
}
|
||
|
||
half4 frag(Varyings input) : SV_Target {
|
||
half4 mainTexCol = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||
|
||
half3 finalRGB = mainTexCol.rgb * _Color.rgb * input.color.rgb;
|
||
finalRGB *= _qd;
|
||
|
||
// 加深:补偿 Additive 混合带来的发白,提升色彩饱和度
|
||
half luma = dot(finalRGB, half3(0.299, 0.587, 0.114));
|
||
finalRGB = lerp(luma.xxx, finalRGB, 1.2);
|
||
|
||
half finalAlpha = mainTexCol.a * _opacity * input.color.a;
|
||
|
||
clip(finalAlpha - 0.001h);
|
||
|
||
return half4(finalRGB, finalAlpha);
|
||
}
|
||
ENDHLSL
|
||
}
|
||
}
|
||
} |