Hello everyone, I’m currently working on a top down game for mobile and as most top down games do sooner or later, am facing an issue where I hate part of the environment getting in the way of the camera. Now, I’ve built most of my game on the FlatKit Stylized Surface Shader. Now, I’ve used shadergraph every time I needed to make custom shaders but unfortunately this one is not written in shader graph so I’m finding difficulties modifiying someone else’s shader to suit my needs, mostly because I’m not that good at graphics programming. Now the shader has a couple of passes for outlines, shadows and such so I tried adding another pass that does just that
Tags { "Queue"="Transparent" "RenderType"="TransparentCutout" }
LOD 200
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
// Properties
sampler2D _MainTex;
sampler2D _DitherTex;
float4 _MainTex_ST;
float _Threshold;
struct appdata_t
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata_t v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// Sample the main texture
fixed4 mainColor = tex2D(_MainTex, i.uv);
// Sample the dither texture using screen-space coordinates
float2 screenUV = i.vertex.xy / _ScreenParams.xy;
fixed ditherValue = tex2D(_DitherTex, frac(screenUV * float2(8, 8))).r;
// Apply alpha clipping based on dither and threshold
if (mainColor.a < _Threshold + (ditherValue - 0.5))
discard;
return mainColor;
}
ENDCG
}
No luck.
I then narrowed down what I think is my next best bet. The shader references multiple times a certain “StylizedInput.hlsl” which im guessing is their implementation of the SurfaceInput.hlsl by Unity.
Specifically this part of the code:
half4 albedo = SampleAlbedoAlpha(uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap));
outSurfaceData.alpha = albedo.a * _BaseColor.a;
AlphaDiscard(outSurfaceData.alpha, _Cutoff);
outSurfaceData.albedo = albedo.rgb;
I tried replacing AlphaDiscard with a custom function I (and ChatGPT’s help) wrote but well, the model now just disappears completly.
Honestly I’m completely stuck right now and would be eternally grateful is someone could lend me a hand on this issue!
Thanks!