| Author | Topics » Book an abo for this thread |  |
<Roby> unregistried
| Created on 20.09.2005 - 11:21 |  |
Hi Guest(r). You could change the "if...else..." sequence in this way:
//if (kx > 1000.0) gl_FragColor.xyz = c11; else //if (k01 + k21 < 0.25)gl_FragColor.xyz = c11; else //if (k10 + k12 < 0.25)gl_FragColor.xyz = c11; else //gl_FragColor.xyz = (kx1*(c10+c21)+kx2*(c12+c21)+kx3*(c01+c12)+kx4*(c01+c10))/(2.0*kx);
vec3 color = (kx1*(c10+c21)+kx2*(c12+c21)+kx3*(c01+c12)+kx4*(c01+c10))/(2.0*kx);
float ky = k01 + k21; float kz = k10 + k12;
kx = clamp(kx-1000.0,0.0,1.0);//if kx > 1000.0 kx = 1.0 else kx = 0.0 ky = sign(abs(0.25-ky)); //if ky < 0.25 ky = 1.0 else ky = 0.0 kz = sign(abs(0.25-kz)); //if kz < 0.25 kz = 1.0 else kz = 0.0
float a = sign(kx+ky+kz); //if kx+ky+kz > 0.0 a = 1.0 else a = 0.0
gl_FragColor.xyz = c11*(a) + color*(1.0-a); //mix(c11,color,a)
|
|
|
<Guest1.5> unregistried
| Created on 20.09.2005 - 13:12 |  |
sign(abs(..)) does not make sense. abs is too much - without it your suggestion should work. But sign is not (much) faster because internally it branches, too.
|
<Roby> unregistried
| Created on 20.09.2005 - 13:30 |  |
Hi Guest 1.5, if you don't use sign, ky = (abs(0.25-ky)) isn't equal to 1.0... but not all tastes are as a lemon tastes...
1983
|
<Guest1.5> unregistried
| Created on 20.09.2005 - 13:45 |  |
@roby
Please re-read my previous post again! I wrote abs is too much, not sign. 
the term is wrong anyway (with or without abs)
"ky = sign(abs(0.25-ky));" is equal to "if (ky==0.25) ky=0.0; else ky=1.0;" which is NOT equal to "if ky < 0.25 ky = 1.0 else ky = 0.0"
it should be
"ky = 1.0-step(ky,0.25);"
|
<Roby> unregistried
| Created on 20.09.2005 - 13:57 |  |
Ok, Guest1.5, you are right...
|
<Guest1.5> unregistried
| Created on 20.09.2005 - 14:40 |  |
Please note:
"c11*(a) + color*(1.0-a);" is a correct replacement for "mix" (for a in [0,1]) it still uses 1 addition, 1 substraction, 1 constant and 2 multiplications.
"(c11-color)*a+color" does the same with 1 addition, 1 substraction and 1 multiplication - should be even faster. 
but anyway - i don't think it will change much because the shader is not short enough.
|