同步主题包
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
Shader "Soullies/DTM_RandomGridFloor"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[HDR]_Color0("Color0", Color) = (1, 1, 1, 0)
|
||||
|
||||
[Header(Pattern Settings)]
|
||||
_PatternSize("Pattern Size (X, Y)", Vector) = (2.0, 2.0, 0, 0)
|
||||
_GridDensity("Grid Density (Quantity Multiplier)", Float) = 1.0
|
||||
|
||||
_TimeAngle("Time Angle (Speed)", Float) = 1.0
|
||||
|
||||
[Header(Edge Settings)]
|
||||
_StepA("Step A", Range(0, 1)) = 0.293
|
||||
_StepB("Step B", Range(0, 1)) = 0.345
|
||||
|
||||
[Header(Outer Enclosing Border)]
|
||||
[Toggle(_OUTER_BORDER_ON)] _EnableOuterBorder("Enable Outer Border", Float) = 0
|
||||
[HDR] _OuterBorderColor("Outer Border Color", Color) = (1, 1, 1, 1)
|
||||
_OuterBorderWidth("Outer Border Width", Range(0.0, 0.5)) = 0.02
|
||||
|
||||
[Header(Render State)]
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 5 // SrcAlpha
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 10 // OneMinusSrcAlpha
|
||||
[Enum(Off, 0, On, 1)] _ZWrite("Z Write", Float) = 0
|
||||
[Enum(Front, Back, Off)] _CullMode("Cull Mode", Float) = 2 // Off
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"RenderType" = "Transparent"
|
||||
"Queue" = "Transparent-300"
|
||||
"UniversalMaterialType" = "Unlit"
|
||||
"IgnoreProjector" = "True"
|
||||
}
|
||||
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
ZWrite [_ZWrite]
|
||||
Cull [_CullMode]
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ForwardOnly"
|
||||
Tags { "LightMode" = "UniversalForwardOnly" }
|
||||
|
||||
HLSLPROGRAM
|
||||
// -------------------------------------
|
||||
// Target Config
|
||||
#pragma target 4.5
|
||||
#pragma prefer_hlslcc gles
|
||||
// DOTS and Instancing
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_fog
|
||||
// Feature Flags
|
||||
#pragma shader_feature_local _OUTER_BORDER_ON
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 positionWS : TEXCOORD0;
|
||||
float2 uv : TEXCOORD1;
|
||||
half fogFactor : TEXCOORD2;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
half4 _Color0;
|
||||
float4 _PatternSize;
|
||||
float _GridDensity;
|
||||
float _TimeAngle;
|
||||
float _StepA;
|
||||
float _StepB;
|
||||
half4 _OuterBorderColor;
|
||||
float _OuterBorderWidth;
|
||||
CBUFFER_END
|
||||
|
||||
// -------------------------------------
|
||||
// Custom Helper Functions
|
||||
float2 VoronoiHash(float2 p)
|
||||
{
|
||||
p = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3)));
|
||||
return frac(sin(p) * 43758.5453);
|
||||
}
|
||||
|
||||
// Manhattan-based Voronoi optimized for Mobile URP
|
||||
float VoronoiDistance(float2 v, float t)
|
||||
{
|
||||
float2 n = floor(v);
|
||||
float2 f = frac(v);
|
||||
float minDist = 8.0;
|
||||
|
||||
UNITY_UNROLL
|
||||
for (int j = -1; j <= 1; j++)
|
||||
{
|
||||
UNITY_UNROLL
|
||||
for (int i = -1; i <= 1; i++)
|
||||
{
|
||||
float2 g = float2((float)i, (float)j);
|
||||
float2 o = VoronoiHash(n + g);
|
||||
// Oscillating movement
|
||||
o = sin(t + o * 6.2831853) * 0.5 + 0.5;
|
||||
float2 r = f - g - o;
|
||||
// Manhattan distance for rectangular frames
|
||||
float d = 0.5 * (abs(r.x) + abs(r.y));
|
||||
minDist = min(minDist, d);
|
||||
}
|
||||
}
|
||||
return minDist;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Vertex Shader
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
output.uv = input.uv;
|
||||
output.fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Fragment Shader
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// ==========================================
|
||||
// 1. inner Grid Pattern Calculation
|
||||
// ==========================================
|
||||
float2 worldUV = input.positionWS.xz;
|
||||
|
||||
// Density Multiplier: Higher density = smaller frames = more quantity
|
||||
float density = max(_GridDensity, 0.0001);
|
||||
float2 sizeDivisor = max(_PatternSize.xy, float2(0.0001, 0.0001)) / density;
|
||||
|
||||
float2 scaledUV = worldUV / sizeDivisor;
|
||||
|
||||
// Rotate 45 degrees
|
||||
float c = 0.707106;
|
||||
float s = 0.707106;
|
||||
float2 rotatedUV = mul(scaledUV, float2x2(c, -s, s, c));
|
||||
|
||||
// Time driven animation
|
||||
float t = _TimeAngle * _TimeParameters.x;
|
||||
|
||||
// Voronoi mathematical noise
|
||||
float v = VoronoiDistance(rotatedUV, t);
|
||||
|
||||
// Anti-aliased border mask computation
|
||||
float fw = fwidth(v);
|
||||
float edge1 = smoothstep(_StepA - fw, _StepA + fw, v);
|
||||
float edge2 = smoothstep(_StepB - fw, _StepB + fw, v);
|
||||
float gridAlphaMask = edge2 - edge1;
|
||||
|
||||
half3 gridColor = _Color0.rgb;
|
||||
half gridAlpha = gridAlphaMask * _Color0.a;
|
||||
|
||||
// ==========================================
|
||||
// 2. Outer Enclosing Border
|
||||
// ==========================================
|
||||
half3 finalColor = gridColor;
|
||||
half finalAlpha = gridAlpha;
|
||||
|
||||
#if defined(_OUTER_BORDER_ON)
|
||||
// Calculate distance to nearest UV edge
|
||||
float2 edgeDist = min(input.uv, 1.0 - input.uv);
|
||||
float closestEdge = min(edgeDist.x, edgeDist.y);
|
||||
|
||||
// Uses fwidth for clean smoothstep transition at the edge
|
||||
float borderfw = fwidth(closestEdge);
|
||||
|
||||
// Creates a solid border with a smooth antialiased inner falloff
|
||||
float borderMask = 1.0 - smoothstep(_OuterBorderWidth - borderfw, _OuterBorderWidth + borderfw, closestEdge);
|
||||
|
||||
// Lerp grid to border
|
||||
finalColor = lerp(gridColor, _OuterBorderColor.rgb, borderMask);
|
||||
finalAlpha = lerp(gridAlpha, _OuterBorderColor.a, borderMask);
|
||||
#endif
|
||||
|
||||
// Apply URP Fog
|
||||
finalColor = MixFog(finalColor, input.fogFactor);
|
||||
|
||||
return half4(finalColor, finalAlpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e848b97478df7c4db397a15a343be4e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,234 @@
|
||||
Shader "Soullies/DTM_RandomGridTube"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[HDR]_Color0("Color0", Color) = (1, 1, 1, 0)
|
||||
|
||||
[Header(Pattern Settings)]
|
||||
_PatternSize("Pattern Size (X, Y)", Vector) = (2.0, 2.0, 0, 0)
|
||||
_GridDensity("Grid Density (Quantity Multiplier)", Float) = 1.0
|
||||
_TimeAngle("Time Angle (Speed)", Float) = 1.0
|
||||
|
||||
[Header(Edge Settings)]
|
||||
_StepA("Step A", Range(0, 1)) = 0.293
|
||||
_StepB("Step B", Range(0, 1)) = 0.345
|
||||
|
||||
[Header(Seam Hiding)]
|
||||
_SeamRotation("Seam Angle Offset", Range(-180, 180)) = -90.0
|
||||
_SeamFadeWidth("Seam Cut Width", Range(0.0, 1.0)) = 0.2
|
||||
_SeamFadeSmoothness("Seam Softness", Range(0.0, 1.0)) = 1.0
|
||||
|
||||
[Header(Tube Specific Settings)]
|
||||
_FadeFar("Fade Far (Fully Transparent)", Float) = 100.0
|
||||
_FadeNear("Fade Near (Fully Opaque)", Float) = 20.0
|
||||
_TubeRadius("Virtual Tube Radius", Float) = 10.0
|
||||
|
||||
[Header(Render State)]
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 5 // SrcAlpha
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 10 // OneMinusSrcAlpha
|
||||
[Enum(Off, 0, On, 1)] _ZWrite("Z Write", Float) = 0
|
||||
[Enum(Front, Back, Off)] _CullMode("Cull Mode", Float) = 1 // Front (Inside)
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"RenderType" = "Transparent"
|
||||
"Queue" = "Transparent-300"
|
||||
"UniversalMaterialType" = "Unlit"
|
||||
"IgnoreProjector" = "True"
|
||||
}
|
||||
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
ZWrite [_ZWrite]
|
||||
Cull [_CullMode] // Default Cull Front to see inside the tube
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ForwardOnly"
|
||||
Tags { "LightMode" = "UniversalForwardOnly" }
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
#pragma prefer_hlslcc gles
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 positionWS : TEXCOORD0;
|
||||
float3 positionOS : TEXCOORD1;
|
||||
half fogFactor : TEXCOORD3;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
half4 _Color0;
|
||||
float4 _PatternSize;
|
||||
float _GridDensity;
|
||||
float _TimeAngle;
|
||||
float _StepA;
|
||||
float _StepB;
|
||||
float _SeamRotation;
|
||||
float _SeamFadeWidth;
|
||||
float _SeamFadeSmoothness;
|
||||
float _FadeFar;
|
||||
float _FadeNear;
|
||||
float _TubeRadius;
|
||||
CBUFFER_END
|
||||
|
||||
// -------------------------------------
|
||||
// Custom Helper Functions
|
||||
float2 VoronoiHash(float2 p)
|
||||
{
|
||||
p = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3)));
|
||||
return frac(sin(p) * 43758.5453);
|
||||
}
|
||||
|
||||
// Manhattan-based Voronoi optimized for Mobile URP
|
||||
float VoronoiDistance(float2 v, float t)
|
||||
{
|
||||
float2 n = floor(v);
|
||||
float2 f = frac(v);
|
||||
float minDist = 8.0;
|
||||
|
||||
UNITY_UNROLL
|
||||
for (int j = -1; j <= 1; j++)
|
||||
{
|
||||
UNITY_UNROLL
|
||||
for (int i = -1; i <= 1; i++)
|
||||
{
|
||||
float2 g = float2((float)i, (float)j);
|
||||
float2 o = VoronoiHash(n + g);
|
||||
// Oscillating movement
|
||||
o = sin(t + o * 6.2831853) * 0.5 + 0.5;
|
||||
float2 r = f - g - o;
|
||||
// Manhattan distance for rectangular frames
|
||||
float d = 0.5 * (abs(r.x) + abs(r.y));
|
||||
minDist = min(minDist, d);
|
||||
}
|
||||
}
|
||||
return minDist;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Vertex Shader
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
output.positionOS = input.positionOS.xyz;
|
||||
output.fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Fragment Shader
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// ==========================================
|
||||
// 1. Cylindrical Mapping & Seam Control
|
||||
// ==========================================
|
||||
// Calculate angle around the Z-axis in object space. atan2 returns [-PI, PI].
|
||||
float rawAngle = atan2(input.positionOS.y, input.positionOS.x);
|
||||
|
||||
// Rotate the seam mechanically
|
||||
float angleOffset = _SeamRotation * (3.14159265 / 180.0);
|
||||
float angle = rawAngle + angleOffset;
|
||||
|
||||
// Wrap angle to [-PI, PI] to keep math bounded
|
||||
if(angle > 3.14159265) angle -= 6.2831853;
|
||||
if(angle < -3.14159265) angle += 6.2831853;
|
||||
|
||||
// Derive distance to the seam (seam is at absolute PI or -PI)
|
||||
float distToSeam = 3.14159265 - abs(angle);
|
||||
|
||||
// Seam alpha fading calculation
|
||||
float endFade = _SeamFadeWidth * 3.14159265;
|
||||
float startFade = endFade * (1.0 - _SeamFadeSmoothness);
|
||||
float seamFadeMask = smoothstep(startFade, endFade + 0.0001, distToSeam);
|
||||
|
||||
// Convert adjusted angle to U coordinate
|
||||
float u = angle * _TubeRadius;
|
||||
|
||||
// V is driven by World Z to maintain seamless tiling
|
||||
float v = input.positionWS.z;
|
||||
|
||||
float2 cylindricalUV = float2(u, v);
|
||||
|
||||
// Density Multiplier
|
||||
float density = max(_GridDensity, 0.0001);
|
||||
float2 sizeDivisor = max(_PatternSize.xy, float2(0.0001, 0.0001)) / density;
|
||||
|
||||
float2 scaledUV = cylindricalUV / sizeDivisor;
|
||||
|
||||
// Rotate 45 degrees
|
||||
float c = 0.707106;
|
||||
float s = 0.707106;
|
||||
float2 rotatedUV = mul(scaledUV, float2x2(c, -s, s, c));
|
||||
|
||||
// Time driven animation
|
||||
float t = _TimeAngle * _TimeParameters.x;
|
||||
|
||||
// Voronoi mathematical noise
|
||||
float voronoiV = VoronoiDistance(rotatedUV, t);
|
||||
|
||||
// Anti-aliased border mask computation
|
||||
float fw = fwidth(voronoiV);
|
||||
float edge1 = smoothstep(_StepA - fw, _StepA + fw, voronoiV);
|
||||
float edge2 = smoothstep(_StepB - fw, _StepB + fw, voronoiV);
|
||||
float gridAlphaMask = edge2 - edge1;
|
||||
|
||||
half3 gridColor = _Color0.rgb;
|
||||
half gridAlpha = gridAlphaMask * _Color0.a;
|
||||
|
||||
// ==========================================
|
||||
// 2. Distance Fade (Far = Transparent, Near = Opaque)
|
||||
// ==========================================
|
||||
float distToCam = distance(GetCameraPositionWS(), input.positionWS);
|
||||
|
||||
// If distToCam is between _FadeFar and _FadeNear, smoothly transition
|
||||
// When dist = _FadeFar, fadeMask = 0 (Transparent)
|
||||
// When dist = _FadeNear, fadeMask = 1 (Opaque)
|
||||
float rawFade = (distToCam - _FadeFar) / (_FadeNear - _FadeFar + 0.0001);
|
||||
float fadeMask = saturate(rawFade);
|
||||
|
||||
// Multiply the alpha by our camera distance fade AND seam smooth fade
|
||||
gridAlpha *= fadeMask * seamFadeMask;
|
||||
|
||||
// Apply URP Fog
|
||||
gridColor = MixFog(gridColor, input.fogFactor);
|
||||
|
||||
return half4(gridColor, gridAlpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1b3dbaa8a5fce64fa762faa07d98c26
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,175 @@
|
||||
Shader "Soullies/DTM_RegularGridFloor"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[HDR]_Color0("Color0", Color) = (1, 1, 1, 0)
|
||||
|
||||
[Header(Grid Settings)]
|
||||
_GridSize("Grid Size (X, Y)", Vector) = (1.0, 1.0, 0, 0)
|
||||
_GridDensity("Grid Density (Quantity Multiplier)", Float) = 1.0
|
||||
|
||||
_LineThickness("Line Thickness", Range(0.001, 0.5)) = 0.05
|
||||
|
||||
_EdgeSoftness("Edge Softness", Range(0.0, 0.5)) = 0.01
|
||||
|
||||
[Header(Animation Settings)]
|
||||
_MoveVector("Movement Vector (X, Y)", Vector) = (0.0, 1.0, 0, 0)
|
||||
|
||||
[Header(Outer Enclosing Border)]
|
||||
[Toggle(_OUTER_BORDER_ON)] _EnableOuterBorder("Enable Outer Border", Float) = 0
|
||||
[HDR] _OuterBorderColor("Outer Border Color", Color) = (1, 1, 1, 1)
|
||||
_OuterBorderWidth("Outer Border Width", Range(0.0, 0.5)) = 0.02
|
||||
|
||||
[Header(Render State)]
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 5 // SrcAlpha
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 10 // OneMinusSrcAlpha
|
||||
[Enum(Off, 0, On, 1)] _ZWrite("Z Write", Float) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"RenderType" = "Transparent"
|
||||
"Queue" = "Transparent-300"
|
||||
"UniversalMaterialType" = "Unlit"
|
||||
"IgnoreProjector" = "True"
|
||||
}
|
||||
|
||||
Blend [_SrcBlend] [_DstBlend]
|
||||
ZWrite [_ZWrite]
|
||||
Cull Back
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ForwardOnly"
|
||||
Tags { "LightMode" = "UniversalForwardOnly" }
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma target 4.5
|
||||
#pragma prefer_hlslcc gles
|
||||
#pragma multi_compile_instancing
|
||||
#pragma multi_compile_fog
|
||||
#pragma shader_feature_local _OUTER_BORDER_ON
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 positionWS : TEXCOORD0;
|
||||
float2 uv : TEXCOORD1;
|
||||
half fogFactor : TEXCOORD2;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
half4 _Color0;
|
||||
float4 _GridSize;
|
||||
float _GridDensity;
|
||||
float _LineThickness;
|
||||
float _EdgeSoftness;
|
||||
float4 _MoveVector;
|
||||
half4 _OuterBorderColor;
|
||||
float _OuterBorderWidth;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
|
||||
|
||||
VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
|
||||
output.positionCS = vertexInput.positionCS;
|
||||
output.positionWS = vertexInput.positionWS;
|
||||
output.uv = input.uv;
|
||||
output.fogFactor = ComputeFogFactor(vertexInput.positionCS.z);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
|
||||
|
||||
// ==========================================
|
||||
// 1. Regular Grid Pattern (World Space UV)
|
||||
// ==========================================
|
||||
float2 worldUV = input.positionWS.xz;
|
||||
|
||||
// Direct Linear Movement Animation
|
||||
float t = _Time.y; // Standard time in seconds
|
||||
worldUV -= _MoveVector.xy * t;
|
||||
|
||||
// Density Multiplier
|
||||
float density = max(_GridDensity, 0.0001);
|
||||
float2 sizeDivisor = max(_GridSize.xy, float2(0.0001, 0.0001)) / density;
|
||||
|
||||
// Scale UV
|
||||
float2 scaledUV = worldUV / sizeDivisor;
|
||||
|
||||
// Generate pure regular grid lines mathematically
|
||||
// frac() maps to [0,1], we subtract 0.5 and take absolute to get a pyramid [0, 0.5]
|
||||
float2 cellUV = abs(frac(scaledUV) - 0.5);
|
||||
|
||||
// Distance to the closest grid edge
|
||||
float2 distToLine = 0.5 - cellUV;
|
||||
float closestLine = min(distToLine.x, distToLine.y);
|
||||
|
||||
// Hardware screen-space derivative + Software Softness for AA
|
||||
float fw = fwidth(closestLine);
|
||||
float halfThickness = _LineThickness * 0.5;
|
||||
float edgeSoft = max(_EdgeSoftness, fw); // ensures it never hard aliases
|
||||
|
||||
// Solid line with anti-aliased trailing edge
|
||||
float gridAlphaMask = smoothstep(halfThickness + edgeSoft, halfThickness - edgeSoft, closestLine);
|
||||
|
||||
half3 gridColor = _Color0.rgb;
|
||||
half gridAlpha = gridAlphaMask * _Color0.a;
|
||||
|
||||
// ==========================================
|
||||
// 2. Outer Enclosing Border
|
||||
// ==========================================
|
||||
half3 finalColor = gridColor;
|
||||
half finalAlpha = gridAlpha;
|
||||
|
||||
#if defined(_OUTER_BORDER_ON)
|
||||
// Calculate distance to nearest Mesh UV edge [0, 1]
|
||||
float2 edgeDist = min(input.uv, 1.0 - input.uv);
|
||||
float closestEdge = min(edgeDist.x, edgeDist.y);
|
||||
|
||||
float borderfw = fwidth(closestEdge);
|
||||
|
||||
// Creates a solid border with a smooth antialiased inner falloff
|
||||
float borderMask = 1.0 - smoothstep(_OuterBorderWidth - borderfw, _OuterBorderWidth + borderfw, closestEdge);
|
||||
|
||||
// Lerp grid to border
|
||||
finalColor = lerp(gridColor, _OuterBorderColor.rgb, borderMask);
|
||||
finalAlpha = lerp(gridAlpha, _OuterBorderColor.a, borderMask);
|
||||
#endif
|
||||
|
||||
// Apply URP Fog
|
||||
finalColor = MixFog(finalColor, input.fogFactor);
|
||||
|
||||
return half4(finalColor, finalAlpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack "Hidden/Universal Render Pipeline/FallbackError"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c746f87d0d9cc824f824b0ee15f4cf06
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 105ff62446f29024392a522239de7a2c
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bc0f501e70ad4348b2fb34717767f5e
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}
|
||||
useAsTemplate: 0
|
||||
exposeTemplateAsShader: 0
|
||||
template:
|
||||
name:
|
||||
category:
|
||||
description:
|
||||
icon: {instanceID: 0}
|
||||
thumbnail: {instanceID: 0}
|
||||
Reference in New Issue
Block a user