I have encounter a very strange problem, I was building a cel shader with varies function and everything works exactly that it should but, when i tried to switch the alpha
eg. making it use alpha or alpha scissor
i have encounter a very strange issue.
The very strange thing happens is if i only put the following code in one file:
However, the issue arises when i combined it using an if else statement and a Boolean or anything that can makes a switch between 2 style, only alpha scissor works and the alpha makes the mesh straight up disapear if the value is less than 1.0
May I what is the best course of action how to tackle this problem or how do I solve it? Preferably, i would like to have a single file instead of 2 shader file.
the part that doesn’t works is the one that i posted earlier, it was strange enough when by itself, the code works, however when I combine it into a if else statement with a boolean check, when it switched to the
the one with alpha scissor can make the transparent part of the image transparent while the one with just alpha, it just make the whole mesh being transparent.
however when combine them both using an if else statement, from my understanding i believe only one of them will work at a time, the one with just alpha, just straight up disappear when the value is less than 1.0
Shader’s transparency mode is decided prior to compilation. You cant branch it. If you write to ALPHA anywhere in the shader, the mode will be alpha. Ditto for ALPHA_SCISSOR_THRESHOLD. This is determined pre-compilation so it doesn’t matter if your code branches in a way that never reaches those assignments.
So it’ll have to be either two shaders or compiler preprocessor switching using #define and #ifdef.
can you please explain how can I use #define and #ifdefine ?
I am not very sure how does that works, also which one do you this is more cheap in terms of processing? i heard to have the game optimize, having the less material and the less shadercode file is better isn’t it?
It works prior to compilation, same as C preprocessor, look that up. The thing is, you can’t switch at runtime with this. If you need runtime switching, use two shaders.