Files
grass-cutters/Assets/Shaders/Ghost.shader
NiemandKG d1c3761e58 Grass Cutters Together: the project as of moon-sweepers f3666f0
A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and
Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date.
Images, audio, models and binaries go through Git LFS (.gitattributes).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 18:44:40 +06:00

85 lines
3.1 KiB
Plaintext

// What a piece will look like before it's built: one see-through shell with a lit rim and a line of light climbing it.
// _Flat is for lines on the ground, which have no normals to make a rim from.
Shader "GrassCutter/Ghost"
{
Properties
{
_BaseColor ("Colour", Color) = (0.3, 1, 0.55, 0.45)
_Flat ("Flat", Float) = 0
}
SubShader
{
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True" }
// depth first: only the outer shell gets colour, not the tangle of parts inside it
Pass
{
Name "GhostDepth"
Tags { "LightMode" = "SRPDefaultUnlit" }
ZWrite On
ColorMask 0
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;
float _Flat;
CBUFFER_END
float4 vert(float4 positionOS : POSITION) : SV_POSITION
{
if (_Flat > 0.5) return float4(0, 0, -1, 1);
return TransformObjectToHClip(positionOS.xyz);
}
float4 frag() : SV_Target { return 0; }
ENDHLSL
}
Pass
{
Name "Ghost"
Tags { "LightMode" = "UniversalForward" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _BaseColor;
float _Flat;
CBUFFER_END
struct Attributes { float4 positionOS : POSITION; float3 normalOS : NORMAL; };
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 normalWS : TEXCOORD0;
float3 positionWS : TEXCOORD1;
float height : TEXCOORD2;
};
Varyings vert(Attributes v)
{
Varyings o;
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.positionCS = TransformWorldToHClip(o.positionWS);
o.normalWS = TransformObjectToWorldNormal(v.normalOS);
o.height = v.positionOS.y;
return o;
}
float4 frag(Varyings i) : SV_Target
{
if (_Flat > 0.5) return float4(_BaseColor.rgb * 1.3, saturate(_BaseColor.a + 0.45));
float3 view = normalize(GetCameraPositionWS() - i.positionWS);
float rim = pow(1 - saturate(dot(normalize(i.normalWS), view)), 2.2);
float climb = smoothstep(0.86, 1, frac(i.height * 1.2 - _Time.y * 0.6));
float alpha = saturate(_BaseColor.a * 0.6 + rim * 0.65 + climb * 0.22);
return float4(_BaseColor.rgb * (1 + rim * 1.1 + climb * 0.5), alpha);
}
ENDHLSL
}
}
}