(Solved) Smooth LOD dithering implementation

Heyho,

I am working on a project for my school which is a first person Metroidvania based mostly in caverns.

For this i have lots of LOD’s for the rocks and stones.

Currently i am having the problem of the LOD fading lacking my expectations and i have been reading up some stuff on that and searched for sources.

The exact problem i am having is that the default cross fading and unitys enabled dithering in the standart shader are not what i would like to have in the final result.
So i found an example shader with a really good fading between LOD’s (Source: GitHub - keijiro/CrossFadingLod: (Unity) Cross-fading LOD shader example)

Problem is that this is just a simple example with only one input on albedo.
So i tried to implement this fading inside the standart shader. Well, I failed multiple times.
I have a big problem in using any sort of code for anything. I do understand how it works and what it does but can’t get around making it myself what so ever.

So if someone could help me and knows how to implement this fading into the standart shader instead of the unity inbuild dithering which you have to enable, i would be really greatfull.

Here is a comparision between the default fading:

crazylighthaddock

and the smooth fading from the custom shader:

likelyrealboutu

As you can see it is much better compared to the default one.

So as an extra attachement here is the code from the custom shader which has the lines containing what i need. At least i guess that these lines are the ones.

            #ifdef LOD_FADE_CROSSFADE
            float2 vpos = IN.screenPos.xy / IN.screenPos.w * _ScreenParams.xy;
            UnityApplyDitherCrossFade(vpos);
            #endif

So what i tried, was to just insert these lines but it didnt work.

            #pragma multi_compile_fwdbase
            #pragma multi_compile_fog
            #pragma multi_compile_instancing
            // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
            //#pragma multi_compile _ LOD_FADE_CROSSFADE
            #ifdef LOD_FADE_CROSSFADE
            float2 vpos = IN.screenPos.xy / IN.screenPos.w * _ScreenParams.xy;
            UnityApplyDitherCrossFade(vpos);
            #endif

            #pragma vertex vertBase
            #pragma fragment fragBase
            #include "UnityStandardCoreForward.cginc"

            ENDCG

so, in the end again, if someone could help me out on this it would be awesome.

The default standard shader doesn’t support LOD fading out of the box. Keijiro’s shaders simply add support to the standard shader :slight_smile: So I would just use his shader, if that’s what you’re looking for!

The problem is it doesn’t add cross fading to the standard shader, it adds it to a simple surface shader that only has a diffuse map. Oddly, the built-in Standard shader actually has full support for cross fading, but it’s disabled in the .shader file. You can make a copy of the built in shader, rename it, uncomment out those lines, and it’ll all magically work.

You’ll find this text in a couple of places throughout the shader. Remove the two // in front of the #pragma and you’re done.

// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
//#pragma multi_compile _ LOD_FADE_CROSSFADE
1 Like

oh yes sorry! I meant it adds it to a surface shader, not standard shader. Not sure how I got mixed up like that

Hey thanks for your answer, yes i tried that but it is ugly. The Meshes keep disapearing and appearing when they do the transition.

So how would i be able to put this into another custom shader? could you show me an example.
What i could do is: changing the standart shader of bakery for example.

Alright after more research i found these tutorials, which helped me.