error while compiling after using branching in fragment shader code

             bool nearer = (nearestRawDepth < raw_depth);
             nearestRawDepth = nearer ? raw_depth : nearestRawDepth;
             nearestColor = nearer ? neighbour : nearestColor;

I am using this to get nearest color and depth values, however using this makes my project unable to compile. I tried if statements with this too and got the same error.

Severity	Code	Description	Project	File	Line	Suppression State
Error	MSB3073	The command "dotnet mgcb /quiet /@:"D:\monogame_projects\tdpe\TDPEMonogame\TDPEMonogame\Content\Content.mgcb" /platform:Windows /outputDir:"D:/monogame_projects/tdpe/TDPEMonogame/TDPEMonogame/Content/bin/Windows/Content" /intermediateDir:"D:/monogame_projects/tdpe/TDPEMonogame/TDPEMonogame/Content/obj/Windows/net6.0-windows/Content" /workingDir:"D:/monogame_projects/tdpe/TDPEMonogame/TDPEMonogame/Content/"" exited with code 1.	TDPEMonogame	C:\Users\yunus\.nuget\packages\monogame.content.builder.task\\build\MonoGame.Content.Builder.Task.targets	142	

Generally, any conditional statement inside a shader makes me get the same error. Is branching not supported? I dont understand much from the error.

If you open the assets manager and build from there, you’ll get the full error string that will tell you what’s wrong.

That said, avoid if / branching if possible. Its bad for performance (small ifs are usually ok as they are usually not really branching and are optimized out, depending on the case)

Thanks! Will check next time. I didn’t knew i could check the error string. I fixed the issue after some debugging.

The problem was shader being old version (4_0). I changed it to (5_0) and now i can use branching. I didn’t knew it wasnt supported on that version and also didn’t knew i could see the error from assets manager. Also, i learned that i could do the same thing without branching. Like this:

bool nearer = (nearestRawDepth>raw_depth);
nearestRawDepth = (nearer * raw_depth) + ( (!nearer) * nearestRawDepth);
nearestColor = (nearer * neighbour) + ( (!nearer) * nearestColor);