Files
PrinceOfGlory/Assets/D5VR/Shader/VFX/Partcle_Base.shader
kridoo 6e91a0c7f0 111
2025-09-15 17:32:08 +08:00

159 lines
7.5 KiB
GLSL
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.

//Created by Wans Wu
//2025,04,28
Shader "WansShader/Partcle/Base"
{
Properties
{
[Enum(UnityEngine.Rendering.CullMode)]_CullMode("", Float) = 0.0
[Main(Base, _, off, off)] _Base ("Base", Float) = 1
[Space(10)]
[Sub(Base)][MainTexture]_BaseMap("Base Map", 2D) = "white" {}
//_NoiseMap("Noise Map", 2D) = "white" {}
[Sub(Base)][MainColor][HDR]_BaseColor("Base Color", Color) = (1,1,1,1)
// _Alpha("Alpha", Range( 0 , 1)) = 0
[Sub(Base)]_Emission("Emission", Float) = 10
[Main(VertColor, _VERTCOLOR, off)] _VertColor ("VertColor", Float) = 1
[Main(Depth, _DEPTH, off)] _Depth ("Depth(", Float) = 0
//[Sub(Depth)]_Fade("Fade", Range(0.0, 1.0)) = 0
//[Sub(Depth)]_SoftParticle("SoftParticle", Float) = 0
[Sub(Depth)]_Near("Near", Float) = 0
[Sub(Depth)]_Far2("Far", Float) = 2
[Main(Orientation, _, off, off)] _Orientation ("", Float) = 1
[KWEnum(Orientation,Regular,_REGULAR,FacingCamera,_FACINGCAMERA,FacingCameraLock,_FACINGCAMERALOCK)] _OrientationMode("", Float) = 0
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent+50" "RenderPipeline" = "UniversalPipeline"}
Pass
{
Tags{"LightMode" = "UniversalForward"}
Blend SrcAlpha OneMinusSrcAlpha
Cull [_CullMode]
ZWrite Off
HLSLPROGRAM
#pragma target 3.0
#pragma vertex LitPassVertex
#pragma fragment LitPassFragment
#pragma shader_feature_local _DEPTH
#pragma shader_feature_local _VERTCOLOR
#pragma shader_feature_local _REGULAR _FACINGCAMERA _FACINGCAMERALOCK
#pragma multi_compile_instancing
#pragma multi_compile _ DOTS_INSTANCING_ON
#pragma instancing_options renderinglayer
//#pragma instancing_options procedural:vertInstancingSetups
#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/DeclareDepthTexture.hlsl"
#include "../ShaderLibrary/LightingCommon.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 texcoord : TEXCOORD0;
float4 vertexColor : COLOR;
#if UNITY_ANY_INSTANCING_ENABLED
uint instanceID : INSTANCEID_SEMANTIC;
#endif
};
struct Varyings
{
float2 uv : TEXCOORD0;
float3 positionOS : TEXCOORD4;
float4 positionCS : SV_POSITION;
float4 vertexColor : TEXCOORD5;
UNITY_VERTEX_OUTPUT_STEREO
#if UNITY_ANY_INSTANCING_ENABLED
uint instanceID : CUSTOM_INSTANCE_ID;
#endif
};
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
half _Alpha;
float _SoftParticle;
float _Emission;
half _Near;
half _Far2;
CBUFFER_END
float4 NormalizedScreenPos( float4 screenPos )
{
float4 ase_screenPosNorm = screenPos / screenPos.w;
ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;
return ase_screenPosNorm;
}
Varyings LitPassVertex(Attributes input)
{
Varyings output = (Varyings)0;
UNITY_SETUP_INSTANCE_ID(input);
//UNITY_TRANSFER_INSTANCE_ID(input, output);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
//billibord
float3 positionOS = float3(0,0,0);
float3 objectScale = float3(length(float3(UNITY_MATRIX_M[0].x, UNITY_MATRIX_M[1].x, UNITY_MATRIX_M[2].x)),
length(float3(UNITY_MATRIX_M[0].y, UNITY_MATRIX_M[1].y, UNITY_MATRIX_M[2].y)),
length(float3(UNITY_MATRIX_M[0].z, UNITY_MATRIX_M[1].z, UNITY_MATRIX_M[2].z)));
float3 objectPos = GetAbsolutePositionWS(UNITY_MATRIX_M._m03_m13_m23);
#if defined (_REGULAR)
positionOS = input.positionOS;
#elif defined (_FACINGCAMERA)
positionOS = mul(GetWorldToObjectMatrix(), float4(mul(UNITY_MATRIX_I_V,float4(input.positionOS.xyz * objectScale,0)).xyz + objectPos,1));
#elif defined(_FACINGCAMERALOCK)
float3 Camera_Direction = -1 * mul(UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz);
float2 Camera_DirectionXZ = normalize(float2(Camera_Direction.x,Camera_Direction.z));
float RotationAngle = atan2(Camera_DirectionXZ.x , Camera_DirectionXZ.y);
float3 RotationPos = input.positionOS * objectScale;
float3 RotationAxis = float3(0,1,0);
positionOS = RotateAroundAxis(half3(0,0,0),RotationPos,half3(0,1,0),RotationAngle)/objectScale;
#endif
VertexPositionInputs vertexInput = GetVertexPositionInputs(positionOS);
output.uv = input.texcoord;
output.positionCS = vertexInput.positionCS;
output.positionOS = input.positionOS;
output.vertexColor = input.vertexColor;
return output;
}
float4 LitPassFragment (Varyings input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
float2 uv = input.uv;
float4 baseMap = SAMPLE_TEXTURE2D(_BaseMap,sampler_BaseMap,uv);
float4 baseColor = baseMap * _BaseColor;
#if defined (_VERTCOLOR)
float3 finalColor = baseColor.rgb * _BaseColor.rgb * input.vertexColor.rgb ;
float alpha = baseMap.a * _BaseColor.a * input.vertexColor.w;
#else
float3 finalColor = baseColor.rgb * _BaseColor.rgb;
float alpha = baseMap.a * _BaseColor.a;
#endif
#if defined (_DEPTH)
float3 postionOS = input.positionOS;
float4 positionCS = TransformObjectToHClip(float4(postionOS,0));
float4 screenPos = NormalizedScreenPos(ComputeScreenPos(float4((positionCS.xyz/positionCS.w),1.0)));
float screenDepth = (LinearEyeDepth(SampleSceneDepth(screenPos),_ZBufferParams) );
float thisDepth = LinearEyeDepth(screenPos.z , _ZBufferParams);
screenDepth = clamp(_Far2 * (screenDepth - _Near) -thisDepth,0,1);
half finalAlpha = finalColor.r * screenDepth;
finalColor = finalColor * screenDepth + _Emission * finalColor * screenDepth;
#else
finalColor = finalColor + _Emission * finalColor;
#endif
return float4(finalColor ,alpha * (1-_Alpha));
}
ENDHLSL
}
}
FallBack "Hidden/Universal Render Pipeline/FallbackError"
CustomEditor "LWGUI.LWGUI"
}