orels-Unity-Shaders icon indicating copy to clipboard operation
orels-Unity-Shaders copied to clipboard

Add LOD Cross Fade support to the Cutout shader

Open An00nymushun opened this issue 3 years ago • 1 comments

Unity enables shaders to smoothen the transition between LOD meshes (and during culling) and a good balanced approach is to do it with a cutout shader and dithering.

You just have to make the CutoutFragment() look something like this

sampler2D unity_DitherMask;

void CutoutFragment() {

	float2 vpos = d.screenPos.xy / d.screenPos.w * _ScreenParams.xy;

	vpos /= 4; // the dither mask texture is 4x4
	float mask = tex2D(unity_DitherMask, vpos).a;
	float sgn = unity_LODFade.x > 0 ? 1.0f : -1.0f;
	clip(unity_LODFade.x - mask * sgn);

	#if !defined(_NATIVE_A2C)
	if (o.Alpha < _Cutoff)  {
		clip(-1);
	}
	#endif
}

Code is taken from https://github.com/keijiro/CrossFadingLod and UnityCG.cginc

An00nymushun avatar May 02 '22 18:05 An00nymushun

Yeah, I have LOD fade planned, as I need it for my own WIP world too. Hopefully will be able to push it out together with the current in-progress rework of the shaders

orels1 avatar May 04 '22 04:05 orels1