Texture splatting question(s)

Started by
14 comments, last by Phil_321 19 years, 8 months ago
Quote:Original post by Raloth
I wrote a simple texture splatting demo in OpenGL a long time ago. It didn't work very well and wasn't very flexible, but it got the job done.

Demo
Source

There are a lot of things wrong with that code since I was new to OpenGL at the time, but it should at least help you get your render states right. I am currently working on an article about texture splatting in Direct3D. It shouldn't be too hard to be able to understand what it's doing and port it to OpenGL.


looking forward to that article man.
"Let Us Now Try Liberty"-- Frederick Bastiat
Advertisement
That's a very helpful demo alright Raloth.
One thing I didn't have in my code was the glEnable(GL_BLEND) and glBlendFunc(), I really need to brush up on opengl.
Still haven't got it working right but I should be able to sort it out tomorrow with the help of your code.
Never accept failure when dealing with things that are within your control.
Quote:
glTexImage2D(GL_TEXTURE_2D, 0, 1, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);


You might perhaps want to use GL_APHA, and not GL_RED...

Quote:
// Bind rock texture to texture unit 0
glActiveTextureARB(GL_TEXTURE0_ARB);
rockTex.Bind(GL_TEXTURE_2D);

// Bind alpha map to texture unit 1
glActiveTextureARB(GL_TEXTURE1_ARB);
rockAlphaTex.Bind(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);

// Set up the texture environment to combine the two textures so that the rgb of tu0 and the alpha value from tu1 are used when rendering

glActiveTextureARB(GL_TEXTURE0_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ARB, GL_REPLACE);

// This section is probably all wrong!
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ARB, GL_MODULATE);


When I was trying to set up an implementation of texture splatting, this was where I couldn't get it right. It's confusing, and I'm still not sure how to do it. Though the resource which I used the most was the extension registry. Check this out: ARB_texture_env_combine specification.

Good luck figuring it out, and be sure to keep us updated!
Yeah, this glTexEnv() can be confusing.
Here's what I should have done for tu1(courtesy of Raloth's source):

glActiveTextureARB(GL_TEXTURE1_ARB);glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_PREVIOUS);


The GL_RED instead of GL_ALPHA was another error.
I also forgot to use glMultiTexCoord() to specify the texture coords for tu1.
I've got it going now, albeit with fairly rough and ready code. I'm going to move on to making a proper editor now based on what PaulC said about UnrealEd(won't be able to see it in action myself until I upgrade my gfx card).
Never accept failure when dealing with things that are within your control.
Quote:Original post by Phil_321
Yeah, this glTexEnv() can be confusing.
Here's what I should have done for tu1(courtesy of Raloth's source):

*** Source Snippet Removed ***

The GL_RED instead of GL_ALPHA was another error.
I also forgot to use glMultiTexCoord() to specify the texture coords for tu1.
I've got it going now, albeit with fairly rough and ready code. I'm going to move on to making a proper editor now based on what PaulC said about UnrealEd(won't be able to see it in action myself until I upgrade my gfx card).


Damn, the texture unit setup is a like riddle. You realize how simple it really is after you see the solution... Anyway, nice that you got it working. Would it be possible to see a demo anytime soon?
Well, I've already started recoding this into a proper terrain editor so it's not actually running at the moment. Here's two screenshots I took though, and the textures used. This is just using procedural texturing based on height and slope.

1.
2.
Textures.

There was a slight transparency error where the third texture was layed, that's why some of the blends are dark, but I'm going to wait until I've got the terrain editor running before I fix it.
Never accept failure when dealing with things that are within your control.

This topic is closed to new replies.

Advertisement