tex_0

Hi! In a shader, what’s the value of tex_0 if the model has no textures?

Claudio

Undefined. Try it yourself to see what the result is, but you’re probably reading arbitrary data from texture memory, so the results will be unpredictable.

Mmmm I see… do I have any way to know if a model is textured or not?

Claudio

I think within the shader is too late to make that determination. Better to have two different shaders, one to apply to textured models, and a different one to apply to non-textured models.

David

hi Claudio,

I think you wouldn’t want to do such logic in the shader itself - even if possible, as it would slow down your shader.

What you probably want to do is check when you load your model if it has any textures and then attach the correct shader to it.
(i.e. have a shader that doesn’t need a texture and one that does simply use a vertex colour)

Sure… I’m a shaders noob guys, thanks for the tip. I made a modified version of the lightingGen.sha you find in the cartoon shading tutorial, that can use the model flat color only if available (otherwise it backups on the vertex color). Do you suggest to have two separate shaders also in this case? The flat color is white when unset.

Claudio