4
\$\begingroup\$

I'm representing terrain in my game as a grid with at each node a composition, for example 100% rock, or 50% grass, 50% soil. I'd like to use this composition vector to blend textures together. I'm using a single texture atlas which contains all my terrain textures.

I've tried various ideas but I always seem to stumble on the rasterization part of the pipeline, because the interpolation does not work correctly between coordinates across the texture atlas.

What is the recommended way to accomplish this?

\$\endgroup\$
2
\$\begingroup\$

You don't want to interpolate between coordinates in the texture atlas.

Instead, you want to sample from each of your textures within the texture atlas, and interpolate between the colors that are returned from the sampler.

Typically, you'll do this by specifying a texture coordinate as a vertex attribute (along with 'position', 'normal', and whatever other attributes you need), and treat that texture coordinate as being the coordinate within one of the textures in the atlas, as if that texture wasn't in an atlas at all. Then you put code in your GLSL shader to convert from the "generic" texture coordinate you specified before into atlas coordinates for each of the textures you want to blend together, samples from the atlas at those atlas coordinates, and blends the resulting colors together using the ratios expressed in the composition vector.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.