Texture tinting or alpha?

BlitzMax Forums/MiniB3D Module/Texture tinting or alpha?

AdamRedwoods(Posted 2011) [#1]
Is there any way in miniB3d, hacks included, to tint a texture or change the alpha of an OpenGL texture? I've tried inserting the glColor4f() function, but it had no effect. I think it requires a little more effort, but I am not coming up with solutions.

Thanks.


Kryzon(Posted 2011) [#2]
All textures by default are loaded with the Multiply blend. This means every mapped texel of this texture is multiplied with the underlying pixel "below" it, be it from another texture or the mesh itself.

Therefore, to tint a texture you can either have a texture layer below it having a flat-color OR use the EntityColor function to color your mesh. The latter is prefered, as you get the tinting for free instead of having to resort to multitexturing.
Note that every mesh starts with an entity color of 255,255,255.


ima747(Posted 2011) [#3]
Not sure what you're going for exactly but if you color and entity it affects whites in the textures (and sort of warps other colors as well). When I need a flexible texture I make it grayscale and then just color the entities as needed.


AdamRedwoods(Posted 2011) [#4]
Thanks, the tinting makes sense, but what about fading a texture out:

scenario: have a fake light texture that you want to fade out, but you want the mesh to remain. I think EntityAlpha fades the mesh, too?


ima747(Posted 2011) [#5]
You can control the alpha of vertexes which could Might be used to get the effect you want... I don't know of any way to easily fade the texture itself... Another concept might be to put the text you want to fade on its own surface or even entity for simplicitys sake, and then fade that out, but you will have to position it carefully...


Kryzon(Posted 2011) [#6]
You could use a pixel-shader for that, if you care to implement all the necessary functionality (klepto2's made a shader interface for MiniB3D, seems to work). The Fixed-Function doesn't have a real-time alpha property for textures, so there's no easy way to do that.
With a shader you could then input the desired float for the texture's alpha and you would take care of setting it up:
gl_FragColor = vec4(red, green, blue, inputtedAlpha)
It's as easy as that. you would have to rewrite the fixed-function lighting, though, to keep the same appearance as when not using shaders.
I think it's worth it if you're ever going to implement it later on; might as well create a stable shader engine now and be done with it.

There is however a way to implement it with fixed-function, albeit somewhat hacky.
I described it some time ago and I would still recommend it if you need to use Fixed-Function only.
http://blitzbasic.com/Community/posts.php?topic=88867#1009390 (some other ideas in that thread too)
To make a texture use the alpha channel from another one with OpenGL, you can read here:
http://www.gamedev.net/topic/372568-multipass-texture-splatting/page__view__findpost__p__3456662


AdamRedwoods(Posted 2011) [#7]
I wasn't sure if the opengl FF pipeline allowed this. Now I know, thanks for the tips.

I was experimenting with Fragment_ARB functions, which seem to work with varied openGL versions-- but I don't need to go that far just yet.

Using alpha multitexture operands WAS something I was looking into, but decided not to go there just yet.