ios - Fragment Shader GLSL for texture, color and texture/color -



ios - Fragment Shader GLSL for texture, color and texture/color -

i want accomplish glsl shader, can texture , color vertex objects. in fact, works me in 2 3 cases:

1) if have texture assigned (but no specific color - color "white"), textured object - works

2) if have texture , color assigned, textured object modulated color - works

3) if have color assigned no texture, black object - doesn't work

my shader looks this:

varying lowp vec4 colorvarying; varying mediump vec2 texcoordvarying; uniform sampler2d texture; void main(){ gl_fragcolor = texture2d(texture, texcoordvarying) * colorvarying; }

i guess that, texture2d(...,...) returns 0 if no texture assigned - seems problem. there way in glsl can check, if no texture assigned (in case, want gl_fragcolor = colorvarying;)

"if" isn't alternative in glsl shader, if understanded correctly - ideas accomplish this? or necessary create 2 different shaders both cases?

like i'd picked general advice 'if' avoided on current mobile hardware, previous optimisation give-and-take on stackoverflow seemed suggest wasn't important hurdle. don't write off. in case, glsl compiler reasonably smart , may chose switch code runs depending on values set uniforms, though in case you're getting same if you'd supplied alternative shaders.

that said, if you're absolutely want utilize same shader purposes , want avoid if statements want like:

uniform lowp float textureflag; [...] gl_fragcolor = textureflag * texture2d(texture, texcoordvarying) * colorvarying + (1.0 - textureflag) * colorvarying;

or even:

gl_fragcolor = mix( colorvarying, texture2d(texture, texcoordvarying) * colorvarying, textureflag )

with setting textureflag 1.0 or 0.0 depending on whether want texture values factored in.

i'm not aware of way determine (i) whether sampler2d pointed actual texture unit; , (ii) whether particular texture unit has buffer bound info has been uploaded.

ios glsl

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -