Jump to content
  • Advertisement
Sign in to follow this  
Barrett

Render huge user indexed primitive with multi textures

This topic is 1360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

 

I'm generating a huge terrain from my random-generated height map (based on perlin noise).

Map divided into squares. Each square must have its own texture (texture distribution based on biome and some render parameters).

All textures packed in atlas. Each square (which consists from two triangles) must be drawn with specified texture, taken from atlas

 

Question is how to set the atlas source rectangle for this squares?

 

Here is the fragment of code, where I'm setting texture position for each vertex.

 

Vector2 texturePosition;
for (int x = 0; x < width; x++)
{
    for (int y = 0; y < height; y++)
    {
        texturePosition = new Vector2((float)x / 32, (float)y / 32);
        VertexPositionTexture texture = new VertexPositionTexture(new Vector3(x, heightMapData[x, y], -y), texturePosition);
        vertices[x + y*width] = texture;
    }
}

As expected, texture atlas layed and looped on whole terrain.

What do I need to change in order to achieve my goal?

 

Thanks in advance,

Denis

Edited by Barrett

Share this post


Link to post
Share on other sites
Advertisement
Use X and Y to look up which biome should be used at that position.
Look up where that biome is on your atlas.
Use that section of the atlas when setting up your texturePosition.

Neighboring squares will have discontinuous texture coordinates*, so you will need to change your loop so that you make all four vertices of each square. You will not be able to share vertices among four touching squares like you are now.

*Unless you have neighboring squares in the same biome AND use even-odd mirrored tiling. But that might be too much of a pain to set up just to share vertices occasionally. Edited by Nypyren

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!