Texture splatting in OpenGL

Started by
4 comments, last by Vanderry 13 years ago
Hey guys !

I'm trying to wrap my head around texture splatting in OpenGL. The way I would like to do this is by using black and white textures as alpha maps (or perhaps masks if it better describes the purpose), and apply this alpha to another, tiled, texture. When several layers are rendered this way I should ideally be able to blend the layers together to get nice texture transitions for terrains without having to use enormous highres textures.

What I can't figure out is the actual implementation. I'm guessing I will have to render the layers one by one, but how would I go about rendering one texture with the color of another one as alpha (no actual alpha channels involved)?

Thanks in advance for any help !

- Dave
Advertisement
Shaders, or fixed pipeline?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I'm not all that familiar with shaders yet so I think fixed pipeline would be a good start.
This kind of example would be a good time to learn shaders if you were so inclined, its much more natural to write this kind of thing as a pixel shader, rather than fuddling around with a bunch of state settings.

However if you do want to do it as the old fixed pipeline, I believe you can still do it. You'll need to setup the entire chain with a bunch of glTexEnv calls. Try studying the documentation page for this function for a while and try to understand how the different arguments work.

Basically you'll bind all your textures at once to different channels, and then setup glTexEnv with the rules from how you'd like to blend them together. You can specify the formulas for blending two textures together, and you can specify the alpha blend value as a third texture. If you search for texture blending tutorials you may find more specific usage examples, but everything you need should be in glTexEnv.

I say its easier as a shader because you can replace that whole mess of functions with a few simple lines in the shader:

vec4 basecolor = texture(baseTex, uv);
float alpha = texture(alphaTex, uv).a;
vec4 layercolor = texture(layerTex, uv);

vec4 fragColor = mix(basecolor, layercolor, alpha);
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
The only problem with using alpha maps is that it can potentially eat up a lot of space (size of terrain, multiplied by number of layers).

Would using vertex alpha be too inaccurate?

D
From the fixed pipeline examples that I have seen, it truly does sound simpler to just learn shaders. I fear that I would lose a lot of those smooth layer transitions if I don't use a more defined alpha map. I wouldn't expect to use more than maybe 2 black-white pngs of 1024x1024 ish size per 100x100 "meters" of terrain, and the tiles are about 512x512 jpgs.

This topic is closed to new replies.

Advertisement