How do I tell if the active texture is texture id 0 in GLSL?
I have model assets that are untextured and I am tired of rendering them as black without lighting. This is because if texture id 0 is bound and I ask the sampler it tells me its black. Later leading to 0 * lighting making the entire object black without lighting. Ideally I would like it colored, materialed and lit, ( which will happen if we don't multiply it by 0 )
I have considered using a uniform
flag and toggling it per object, but I was hoping for a simpler higher performing way if we need partially textured assets later.
I have also though of binding a white texture pushing a white pixel and setting it to wrap for instance, but this seems like "Chi Ting".
Note. A valid texture may return black so we can't just ignore black texture reads. well, we could, but it wouldn't look good. Currently we aren't using any buffer objects, just the deprecated glBegin()
gl开发者_如何学JAVAEnd()
method with display lists.
Any other ideas would be appreciated.
Use empty white texture. It's going to be as fast as using uniform and you don't have to handle extra cases.
If you really worry about speed, combine your textures into one, leaving small white area for untextured parts. Changing texCoords is much faster than changing textures or uniforms.
In my own attempts at learning openGL, I went with a boolean uniform, as you suggested.
It makes sense that using a texture or having a fixed color is a property of each model object; therefore setting this property on the shader for each object via a uniform seems logical, no 'cheating' involved !
If it makes you feel any better, you can have the texture (if any) as a property of your object and set the uniform based on its presence or absence, instead of duplicating information by having a texture property and a textured/not textured flag.
精彩评论