Trash maze MVP (#79)
Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Reviewed-on: #79
This commit is contained in:
9
Assets/Shaders/TrashMaze.meta
Normal file
9
Assets/Shaders/TrashMaze.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
10
Assets/Shaders/TrashMaze/BackgroundVisibility.shader.meta
Normal file
10
Assets/Shaders/TrashMaze/BackgroundVisibility.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
91
Assets/Shaders/TrashMaze/ObjectVisibility.shader
Normal file
91
Assets/Shaders/TrashMaze/ObjectVisibility.shader
Normal file
@@ -0,0 +1,91 @@
|
||||
Shader "TrashMaze/ObjectVisibility"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Normal Texture (Color)", 2D) = "white" {}
|
||||
_OutlineTex ("Outline Texture (White)", 2D) = "white" {}
|
||||
[PerRendererData] _IsRevealed ("Is Revealed", Float) = 0
|
||||
[PerRendererData] _IsInVision ("Is In Vision", Float) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"RenderType"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
}
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
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;
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D(_OutlineTex);
|
||||
SAMPLER(sampler_OutlineTex);
|
||||
float4 _MainTex_ST;
|
||||
|
||||
// Per-instance properties (set by RevealableObject component)
|
||||
float _IsRevealed;
|
||||
float _IsInVision;
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.uv = TRANSFORM_TEX(input.uv, _MainTex);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// Three-state logic:
|
||||
// 1. In vision radius -> show normal texture (color)
|
||||
// 2. Revealed but outside vision -> show outline texture (white)
|
||||
// 3. Never revealed -> transparent (hidden)
|
||||
|
||||
if (_IsInVision > 0.5)
|
||||
{
|
||||
// Inside vision radius - show color
|
||||
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
}
|
||||
else if (_IsRevealed > 0.5)
|
||||
{
|
||||
// Revealed but outside vision - show outline
|
||||
return SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, input.uv);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Never revealed - transparent (hidden)
|
||||
return half4(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Transparent/Diffuse"
|
||||
}
|
||||
|
||||
10
Assets/Shaders/TrashMaze/ObjectVisibility.shader.meta
Normal file
10
Assets/Shaders/TrashMaze/ObjectVisibility.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
||||
106
Assets/Shaders/TrashMaze/ObjectVisibilityProgressive.shader
Normal file
106
Assets/Shaders/TrashMaze/ObjectVisibilityProgressive.shader
Normal file
@@ -0,0 +1,106 @@
|
||||
Shader "TrashMaze/ObjectVisibilityProgressive"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Normal Texture (Color)", 2D) = "white" {}
|
||||
_OutlineTex ("Outline Texture (White)", 2D) = "white" {}
|
||||
_RevealMask ("Reveal Mask", 2D) = "black" {}
|
||||
[PerRendererData] _IsInVision ("Is In Vision", Float) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"RenderType"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
}
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
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;
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 positionWS : TEXCOORD1;
|
||||
};
|
||||
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
TEXTURE2D(_OutlineTex);
|
||||
SAMPLER(sampler_OutlineTex);
|
||||
TEXTURE2D(_RevealMask);
|
||||
SAMPLER(sampler_RevealMask);
|
||||
float4 _MainTex_ST;
|
||||
|
||||
// Global shader properties (set by PulverController)
|
||||
float2 _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, _MainTex);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// Sample reveal mask (0 = not revealed, 1 = revealed)
|
||||
float revealAmount = SAMPLE_TEXTURE2D(_RevealMask, sampler_RevealMask, input.uv).r;
|
||||
|
||||
// Binary decision: is this pixel revealed?
|
||||
bool isRevealed = revealAmount > 0.5;
|
||||
|
||||
// If pixel was never revealed, hide it completely
|
||||
if (!isRevealed)
|
||||
{
|
||||
return half4(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Calculate per-pixel distance to player in world space
|
||||
float2 pixelWorldPos = input.positionWS.xy;
|
||||
float distanceToPlayer = distance(pixelWorldPos, _PlayerWorldPos);
|
||||
|
||||
// Three-state logic per pixel:
|
||||
// 1. Never revealed -> hide (handled above)
|
||||
// 2. Revealed + currently in player vision radius -> show color
|
||||
// 3. Revealed + outside player vision radius -> show outline
|
||||
|
||||
if (distanceToPlayer < _VisionRadius)
|
||||
{
|
||||
// Pixel is revealed AND currently in vision - show color
|
||||
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pixel is revealed but NOT currently in vision - show outline
|
||||
return SAMPLE_TEXTURE2D(_OutlineTex, sampler_OutlineTex, input.uv);
|
||||
}
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Transparent/Diffuse"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 732fa975ac924d89bb0078279d2cdb0b
|
||||
timeCreated: 1765358086
|
||||
64
Assets/Shaders/TrashMaze/RevealStamp.shader
Normal file
64
Assets/Shaders/TrashMaze/RevealStamp.shader
Normal file
@@ -0,0 +1,64 @@
|
||||
Shader "Hidden/TrashMaze/RevealStamp"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_StampPos ("Stamp Position", Vector) = (0.5, 0.5, 0, 0)
|
||||
_StampRadius ("Stamp Radius", Float) = 0.2
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Overlay" "RenderType"="Opaque" }
|
||||
|
||||
// Additive blend to accumulate stamps
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
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
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 _StampPos;
|
||||
float _StampRadius;
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.uv = input.uv;
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// Calculate distance from stamp center
|
||||
float dist = distance(input.uv, _StampPos.xy);
|
||||
|
||||
// Binary circle: 1.0 inside radius, 0.0 outside
|
||||
float alpha = dist < _StampRadius ? 1.0 : 0.0;
|
||||
|
||||
// Return white with calculated alpha (additive blend accumulates)
|
||||
return half4(alpha, alpha, alpha, alpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Shaders/TrashMaze/RevealStamp.shader.meta
Normal file
3
Assets/Shaders/TrashMaze/RevealStamp.shader.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33afb80a55e64e53b8552498ad61acfa
|
||||
timeCreated: 1765358067
|
||||
Reference in New Issue
Block a user