Some noob question about shaderlab

What is multicompile and how to use it?
and How to use “if” command?
Do i have to define the condition from script? Can’t I create the condition directly from shader?
Can anyone give some snippet example please

Tx

As far as i know, multicompile is small differences per platform.
i.e.
#if defined(SHADER_API_D3D9) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PS3)
#define UNITY_UV_STARTS_AT_TOP 1
#else
#define UNITY_UV_STARTS_AT_TOP 0
#endif

You can use if command as a conditional as how you use it in any programming language
i.e.
if (color.a > 0) do something fancy
or you can use it to condition a custom define of yours.

Oh…sweet tx for the help Aubergine.
But somehow i’m still can’t use the if conditional correctly, I’m always ended up with pink shader =.=. Umm okay for example (this is from water4 shader)

#ifdef WATER_EDGEBLEND_ON
if (LinearEyeDepth(refrFix) < i.screenPos.z)
rtRefractions = rtRefractionsNoDistort;
#endif

Do i have to always use #ifdef - #endif to using the if conditional? What if i don’t have the Edge_Blend option from the script, but i want to use those conditional?

Ty :slight_smile:

EDIT : Figure it out already, thanks :slight_smile:

The thing about conditionals and for loops, if you have a variable defined outside of them and if you use the same variable inside the conditional and for loop, then you will get a ddx/ddy not initialized error when the shader compiles.
I dont know why.

So, dont use outside variables inside your conditionals and for loops.