118 lines
4.1 KiB
Plaintext
118 lines
4.1 KiB
Plaintext
Shader "Custom/URP_PureDistortion"
|
|
{
|
|
Properties
|
|
{
|
|
[Header(Distortion)]
|
|
_NormalMap("Normal Map", 2D) = "bump" {}
|
|
_Distortion("Distortion Strength", Range(0, 0.5)) = 0.1
|
|
_NormalStrength("Normal Strength", Range(0, 5)) = 1.0
|
|
|
|
[Header(Animation)]
|
|
_ScrollSpeedX("Scroll Speed X", Float) = 0.1
|
|
_ScrollSpeedY("Scroll Speed Y", Float) = 0.2
|
|
|
|
[Header(Color)]
|
|
_TintColor("Tint Color", Color) = (1, 1, 1, 0.5)
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
"Queue" = "Transparent"
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "PureDistortion"
|
|
|
|
ZWrite Off
|
|
Cull Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_fog
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
|
|
|
TEXTURE2D(_NormalMap);
|
|
SAMPLER(sampler_NormalMap);
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _NormalMap_ST;
|
|
float4 _TintColor;
|
|
float _Distortion;
|
|
float _NormalStrength;
|
|
float _ScrollSpeedX;
|
|
float _ScrollSpeedY;
|
|
CBUFFER_END
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float4 color : COLOR;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float4 color : COLOR;
|
|
float4 screenPos : TEXCOORD1;
|
|
float fogFactor : TEXCOORD2;
|
|
};
|
|
|
|
Varyings vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
|
|
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
|
|
|
output.positionCS = vertexInput.positionCS;
|
|
output.uv = TRANSFORM_TEX(input.uv, _NormalMap);
|
|
output.color = input.color;
|
|
output.screenPos = ComputeScreenPos(vertexInput.positionCS);
|
|
output.fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
|
|
|
return output;
|
|
}
|
|
|
|
half4 frag(Varyings input) : SV_Target
|
|
{
|
|
// Animated normal map sampling
|
|
float2 scrolledUV = input.uv + float2(_ScrollSpeedX, _ScrollSpeedY) * _Time.y;
|
|
float3 normalMap = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, scrolledUV));
|
|
normalMap.xy *= _NormalStrength;
|
|
|
|
// Calculate screen UV
|
|
float2 screenUV = input.screenPos.xy / input.screenPos.w;
|
|
|
|
// Apply normal-based distortion to screen UV
|
|
float2 distortedScreenUV = screenUV + normalMap.xy * _Distortion * input.color.a;
|
|
|
|
// Sample the background/opaque texture with distortion
|
|
half3 sceneColor = SampleSceneColor(distortedScreenUV);
|
|
|
|
// Apply tint color
|
|
sceneColor *= _TintColor.rgb * input.color.rgb;
|
|
|
|
// Apply fog
|
|
sceneColor = MixFog(sceneColor, input.fogFactor);
|
|
|
|
// Calculate final alpha
|
|
float finalAlpha = _TintColor.a * input.color.a;
|
|
|
|
return half4(sceneColor, finalAlpha);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
|
|
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
|
} |