298 lines
14 KiB
Plaintext
298 lines
14 KiB
Plaintext
//Created by Wans Wu
|
|
//2025,04,27
|
|
Shader "WansShader/VFX/VertexAttraction"
|
|
{
|
|
Properties
|
|
{
|
|
[Enum(UnityEngine.Rendering.CullMode)]_CullMode("剔除模式", Float) = 2.0
|
|
_Tiliing ("全局Tiliing", vector) = (1, 1, 0, 0)
|
|
|
|
[Main(PBRIntput, _, off, off)] _PBRIntput ("PBR 属性", Float) = 1
|
|
[Tex(PBRIntput,_BaseColor)][MainTexture] _BaseMap("Base贴图", 2D) = "white" {}
|
|
[HideInInspector][MainColor] _BaseColor(" ", Color) = (1,1,1,1)
|
|
[Tex(PBRIntput)] _MRAMap("MSA", 2D) = "white" {}
|
|
[Sub(PBRIntput)]_Metallic("金属度(R通道)",Range(0.0, 1.0)) = 1.0
|
|
[Sub(PBRIntput)]_Smoothness("光滑度(G通道)", Range(0.0, 1.0)) = 1.0
|
|
[Sub(PBRIntput)]_HeightLight("高光度", Range(0.0, 1.0)) = 1.0
|
|
[Sub(PBRIntput)]_OcclusionStrength("AO(B通道)", Range(0.0, 1.0)) = 0.0
|
|
[Tex(PBRIntput,_BumpScale)]_BumpMap("法线贴图", 2D) = "bump" {}
|
|
[HideInInspector]_BumpScale("法线强度", Float) = 1.0
|
|
|
|
[Main(Emission,_EMISSION, off)] _Emission ("发光", Float) = 0
|
|
[Tex(Emission,_EmissionColor)]_EmissionMap("发光贴图", 2D) = "white" {}
|
|
[HideInInspector][HDR]_EmissionColor("发光颜色", Color) = (0,0,0,1)
|
|
[Sub(Emission)]_EmissionStrength("发光强度", Range(0.0, 1.0)) =1.0
|
|
|
|
[Main(Attraction, _, off, off)] _Attraction ("总体", Float) = 1
|
|
[Sub(Attraction)]_Control("总体控制", Float) = 0.0
|
|
[Sub(Attraction)]_Range("范围", Float) = 10.0
|
|
[Sub(Attraction)]_EffectRandom("随机值", Range(0.0, 1.0)) = 0.0
|
|
[Sub(Attraction)]_AttractPoint("吸收点位置", Vector) = (0,0,0,0)
|
|
[Sub(Attraction)]_Pivot("轴心", Vector) = (0,0,0,0)
|
|
|
|
[Main(Twist, _, off, off)] _Twist ("扭转", Float) = 1
|
|
[Sub(Twist)]_TwistScale("大小", Float) = 1.0
|
|
[Sub(Twist)]_TwistAngle("角度", Float) = 1.0
|
|
[Sub(Twist)]_TwistFreq("频率", Float) = 1.0
|
|
[Sub(Twist)]_TwistOffset("偏移", Float) = 0.0
|
|
|
|
[Main(Dispersion,_, off, off)] _Dispersion1 ("Dispersion(向两边扩散的力)", Float) = 0
|
|
[Sub(Dispersion)]_Dispersion("强度", Float) = 1.7
|
|
[Sub(Dispersion)]_DispersionRandom("随机值", Float) = 4.0
|
|
[Sub(Dispersion)]_DispersionCenter("扩散中心", Vector) = (0,0,0,0)
|
|
[Sub(Dispersion)]_DispersionDir("扩散方向", Vector) = (1,0,1,0)
|
|
|
|
[Main(Lighting, _, off, off)] _Lighting ("光照", Float) = 1
|
|
[Sub(Lighting)]_LightIntensitiy("烘培光照强度",Range(0.0, 2.0)) = 1.0
|
|
[SubToggle(Lighting,_ENVIRONMENTREFLECTIONS_OFF)]_EnvironmentReflections("环境反射", Float) = 0.0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags{"RenderType" = "Opaque" "Queue"="Geometry" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit""IgnoreProjector" = "True"}
|
|
Pass
|
|
{
|
|
Tags{"LightMode" = "UniversalForward"}
|
|
Cull[_CullMode]
|
|
HLSLPROGRAM
|
|
#pragma target 3.5
|
|
#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 _ _REFLECTION_PROBE_BLENDING
|
|
#pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
|
|
#pragma shader_feature_local_fragment _ENVIRONMENTREFLECTIONS_OFF
|
|
#pragma shader_feature_local _EMISSIONs
|
|
#pragma multi_compile_fog
|
|
|
|
//realtimeLight
|
|
#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_SOF
|
|
#pragma multi_compile_fragment _ _LIGHT_LAYERS
|
|
#pragma multi_compile_fragment _ _LIGHT_COOKIES
|
|
|
|
#pragma vertex LitPassVertex
|
|
#pragma fragment LitPassFragment
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityInput.hlsl"
|
|
#include "../ShaderLibrary/StandardLighting.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float3 normalOS : NORMAL;
|
|
float4 tangentOS : TANGENT;
|
|
float2 texcoord : TEXCOORD0;
|
|
float2 staticLightmapUV : TEXCOORD1;
|
|
float2 texcoord3 : TEXCOORD2;
|
|
float2 texcoord4 : TEXCOORD3;
|
|
float4 vertexColor :COLOR;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
struct Varyings
|
|
{
|
|
float4 uv : TEXCOORD0;
|
|
float4 positionWS : TEXCOORD1;
|
|
float4 normalWS : TEXCOORD2;
|
|
half4 tangentWS : TEXCOORD3;
|
|
float4 positionCS : SV_POSITION;
|
|
float4 test : TEXCOORD4;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
TEXTURE2D(_BaseMap);
|
|
SAMPLER(sampler_BaseMap);
|
|
TEXTURE2D(_BumpMap);
|
|
SAMPLER(sampler_BumpMap);
|
|
TEXTURE2D(_MRAMap);
|
|
SAMPLER(sampler_MRAMap);
|
|
#if defined (_EMISSION)
|
|
TEXTURE2D(_EmissionMap);
|
|
SAMPLER(sampler_EmissionMap);
|
|
#endif
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _BaseMap_ST;
|
|
half4 _MainTex;
|
|
half4 _NormalMap_ST;
|
|
float4 _DetailAlbedoMap_ST;
|
|
half4 _BaseColor;
|
|
half4 _SpecColor;
|
|
half4 _EmissionColor;
|
|
half _Cutoff;
|
|
float _Smoothness;
|
|
half _Metallic;
|
|
half _BumpScale;
|
|
half _Parallax;
|
|
half _ClearCoatMask;
|
|
half _ClearCoatSmoothness;
|
|
half _DetailAlbedoMapScale;
|
|
half _DetailNormalMapScale;
|
|
half _Surface;
|
|
half _EmissionStrength;
|
|
half _LightIntensitiy;
|
|
half _SpecShininess;
|
|
half4 _Tiliing;
|
|
half _OcclusionStrength;
|
|
half _HeightLight;
|
|
|
|
half _Control;
|
|
half _Range;
|
|
half _EffectRandom;
|
|
half3 _AttractPoint;
|
|
half3 _Pivot;
|
|
|
|
half _Dispersion;
|
|
half _DispersionRandom;
|
|
half3 _DispersionCenter;
|
|
half3 _DispersionDir;
|
|
|
|
half _TwistScale;
|
|
half _TwistAngle;
|
|
half _TwistFreq;
|
|
half _TwistOffset;
|
|
CBUFFER_END
|
|
|
|
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);
|
|
|
|
float customAlpha ;
|
|
float3 Xvextor ;
|
|
float3 PovitPosition ;
|
|
float randomper ;
|
|
GetPivotPainterData_float(input.texcoord3,input.texcoord4,input.vertexColor,customAlpha,randomper,Xvextor,PovitPosition);
|
|
|
|
half Effect = saturate(((PovitPosition.y + (randomper * _EffectRandom)) /_Range + 1) - (_Control * 2 ));
|
|
float3 AttractDir = normalize(_AttractPoint - _Pivot);
|
|
|
|
float3 ScaliingPos = lerp(input.positionOS.xyz,PovitPosition,saturate(Effect + 1));
|
|
|
|
float DispersionRandom = _Dispersion + randomper * _DispersionRandom;
|
|
float3 DispersionOffset = normalize(PovitPosition - _DispersionCenter) * _DispersionDir * DispersionRandom ;
|
|
float3 FinalDispersion = lerp3(half3(0,0,0),DispersionOffset,half3(0,0,0),saturate(Effect-0.1));
|
|
|
|
float3 TwistAngle = sin(Effect * PI * _TwistFreq + _TwistOffset) * _TwistAngle;
|
|
float3 TwistOffset = RotateAroundAxis_Flus(ScaliingPos ,_Pivot,AttractDir,TwistAngle) * _TwistScale;
|
|
float3 finalTwist = lerp3(half3(0,0,0),TwistOffset,half3(0,0,0),saturate(Effect-0.1));
|
|
float3 Attraction = lerp(input.positionOS.xyz + FinalDispersion + finalTwist ,_AttractPoint,Effect);
|
|
float3 finalOffset = Attraction ;
|
|
output.test = float4(finalTwist,1);
|
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(finalOffset.xyz);
|
|
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
|
|
output.uv.xy = input.texcoord;
|
|
output.normalWS.xyz = normalInput.normalWS;
|
|
output.normalWS.w = input.vertexColor.w;
|
|
real sign = input.tangentOS.w * GetOddNegativeScale();
|
|
half4 tangentWS = half4(normalInput.tangentWS.xyz, sign);
|
|
|
|
output.positionCS = vertexInput.positionCS;
|
|
output.tangentWS = tangentWS;
|
|
output.positionWS.xyz = vertexInput.positionWS;
|
|
output.positionWS.w = Effect;
|
|
output.uv.zw = input.staticLightmapUV * unity_LightmapST.xy + unity_LightmapST.zw;
|
|
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.xy * _Tiliing.xy + _Tiliing.zw;
|
|
float3 positionWS = input.positionWS;
|
|
float3 vDirWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
|
|
float3 nDirWS = normalize(input.normalWS);
|
|
half3 tDirWS = normalize(input.tangentWS.xyz);
|
|
half3 bDirWS = normalize(cross(nDirWS,tDirWS) * input.tangentWS.w);
|
|
half3x3 TBN = half3x3(tDirWS,bDirWS,nDirWS);
|
|
float4 ShadowCoord = TransformWorldToShadowCoord(positionWS);
|
|
half4 ShadowMask = float4(1.0,1.0,1.0,1.0);
|
|
Light light = GetMainLight(ShadowCoord,positionWS,ShadowMask);
|
|
float3 LightDir = light.direction;
|
|
|
|
half4 BaseColorAlpha = SAMPLE_TEXTURE2D(_BaseMap,sampler_BaseMap,uv) ;
|
|
half3 BaseColor = BaseColorAlpha.rgb *_BaseColor.rgb ;
|
|
float3 nDirTS = UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap,sampler_BumpMap,uv),_BumpScale);
|
|
nDirWS = normalize(mul(nDirTS,TBN));
|
|
half4 EmissonMap = 0;
|
|
#if defined (_EMISSION)
|
|
EmissonMap = SAMPLE_TEXTURE2D(_EmissionMap,sampler_EmissionMap,uv)* _EmissionColor * _EmissionStrength;
|
|
#else
|
|
EmissonMap = half4(0,0,0,0);
|
|
#endif
|
|
half4 EmissonColor = EmissonMap + (1-input.normalWS.w) * _EmissionColor + _EmissionColor * input.positionWS.w ;
|
|
half3 MRAmap = SAMPLE_TEXTURE2D(_MRAMap,sampler_MRAMap,uv).rgb ;
|
|
float Metallic = saturate(_Metallic * MRAmap.r) ;
|
|
half Occlusion =saturate( lerp( 1,0 + MRAmap.b,_OcclusionStrength ));
|
|
float Roughness = saturate( (1 - _Smoothness * (1-MRAmap.g)));
|
|
|
|
float csz = input.positionCS.z * input.positionCS.w;
|
|
real fogFactor = ComputeFogFactor(csz);
|
|
half3 DiffuseColor = lerp(BaseColor,half3(0.0,0.0,0.0),Metallic);
|
|
half3 SpecularColor = lerp(half3(0.04,0.04,0.04),BaseColor,Metallic);
|
|
Roughness = max(saturate(Roughness),0.1f);
|
|
|
|
half3 DirectLighting = half3(0,0,0);
|
|
DirectLighting_float(DiffuseColor,SpecularColor,Roughness,positionWS,nDirWS,vDirWS,DirectLighting);
|
|
float3 IndirectLighting = float3(0,0,0);
|
|
IndirectLighting_float(DiffuseColor,SpecularColor,Roughness,positionWS,nDirWS,vDirWS,Occlusion,_HeightLight,input.uv.zw,LightDir,_LightIntensitiy ,IndirectLighting);
|
|
float4 color = float4((DirectLighting+IndirectLighting+ EmissonColor.rgb) ,1);
|
|
color.rgb = MixFog(color.rgb,fogFactor);
|
|
return color;
|
|
//return input.test;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
Pass
|
|
{
|
|
Name "Meta"
|
|
Tags
|
|
{
|
|
"LightMode" = "Meta"
|
|
}
|
|
|
|
// -------------------------------------
|
|
// Render State Commands
|
|
Cull Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 2.0
|
|
|
|
// -------------------------------------
|
|
// Shader Stages
|
|
#pragma vertex UniversalVertexMeta
|
|
#pragma fragment UniversalFragmentMetaLit
|
|
|
|
// -------------------------------------
|
|
// Material Keywords
|
|
#pragma shader_feature_local_fragment _SPECULAR_SETUP
|
|
#pragma shader_feature_local_fragment _EMISSION
|
|
#pragma shader_feature_local_fragment _METALLICSPECGLOSSMAP
|
|
#pragma shader_feature_local_fragment _ALPHATEST_ON
|
|
#pragma shader_feature_local_fragment _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
|
|
#pragma shader_feature_local _ _DETAIL_MULX2 _DETAIL_SCALED
|
|
#pragma shader_feature_local_fragment _SPECGLOSSMAP
|
|
#pragma shader_feature EDITOR_VISUALIZATION
|
|
|
|
// -------------------------------------
|
|
// Includes
|
|
#include "../ShaderLibrary/CustomLitInput.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"
|
|
|
|
ENDHLSL
|
|
}
|
|
}
|
|
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
|
CustomEditor "LWGUI.LWGUI"
|
|
|
|
}
|