试图找出导致分支的原因以及在GLSL中没有导致分支的原因。
我在着色器中经常这样做:
float(a==b)
我用它来模拟if语句,没有条件分支...但是有效吗?我现在程序中的任何地方都没有if语句,也没有任何循环。
编辑:为了澄清,我在我的代码中做了这样的事情:
float isTint = float((renderflags & GK_TINT) > uint(0)); // 1 if true, 0 if false
float isNotTint = 1-isTint;//swaps with the other value
float isDarken = float((renderflags & GK_DARKEN) > uint(0));
float isNotDarken = 1-isDarken;
float isAverage = float((renderflags & GK_AVERAGE) > uint(0));
float isNotAverage = 1-isAverage;
//it is none of those if:
//* More than one of them is true
//* All of them are false
float isNoneofThose = isTint * isDarken * isAverage + isNotTint * isAverage * isDarken + isTint * isNotAverage * isDarken + isTint * isAverage * isNotDarken + isNotTint * isNotAverage * isNotDarken;
float isNotNoneofThose = 1-isNoneofThose;
//Calc finalcolor;
finalcolor = (primary_color + secondary_color) * isTint * isNotNoneofThose + (primary_color - secondary_color) * isDarken * isNotNoneofThose + vec3((primary_color.x + secondary_color.x)/2.0,(primary_color.y + secondary_color.y)/2.0,(primary_color.z + secondary_color.z)/2.0) * isAverage * isNotNoneofThose + primary_color * isNoneofThose;
编辑:我知道为什么我不想分支。我知道是什么分支。我很高兴您正在教孩子们关于分支的知识,但我想了解布尔运算符(以及按位运算符,但我很确定它们很好)