Stash work
This commit is contained in:
82
Assets/Shaders/TrashMaze/BackgroundVisibility.shader
Normal file
82
Assets/Shaders/TrashMaze/BackgroundVisibility.shader
Normal file
@@ -0,0 +1,82 @@
|
||||
Shader "TrashMaze/BackgroundVisibility"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_LitTex ("Lit Texture (Color)", 2D) = "white" {}
|
||||
_UnlitTex ("Unlit Texture (Dark)", 2D) = "white" {}
|
||||
_TransitionSoftness ("Transition Softness", Range(0, 2)) = 0.5
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Background"
|
||||
"RenderType"="Opaque"
|
||||
}
|
||||
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 positionWS : TEXCOORD1;
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
TEXTURE2D(_LitTex);
|
||||
SAMPLER(sampler_LitTex);
|
||||
TEXTURE2D(_UnlitTex);
|
||||
SAMPLER(sampler_UnlitTex);
|
||||
float4 _LitTex_ST;
|
||||
float _TransitionSoftness;
|
||||
|
||||
// Global properties set by PulverController
|
||||
float3 _PlayerWorldPos;
|
||||
float _VisionRadius;
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
output.uv = TRANSFORM_TEX(input.uv, _LitTex);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// Calculate distance from pixel to player
|
||||
float dist = distance(input.positionWS.xy, _PlayerWorldPos.xy);
|
||||
|
||||
// Create smooth transition between lit and unlit
|
||||
float t = smoothstep(_VisionRadius - _TransitionSoftness, _VisionRadius, dist);
|
||||
|
||||
// Sample both textures
|
||||
half4 litColor = SAMPLE_TEXTURE2D(_LitTex, sampler_LitTex, input.uv);
|
||||
half4 unlitColor = SAMPLE_TEXTURE2D(_UnlitTex, sampler_UnlitTex, input.uv);
|
||||
|
||||
// Blend based on distance
|
||||
return lerp(litColor, unlitColor, t);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user