Jump to content
  • Advertisement
Sign in to follow this  
pbbm2000

Changing textures while using index buffers

This topic is 4524 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

I'm making a terrian engine which creates an index buffer then renders the whole thing with a single call to DrawIndexedPrimitive. I set the texture using SetTexture and then call DrawIndexedPrimitive and the whole thing renders with a single texture. Is there a way to change the texture so that different height levels have different textures. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You'll need to make multiple calls to DrawIndexedPrimitive using the correnct indexes for the current texture with appropriate SetTexture calls in between.

Share this post


Link to post
Share on other sites
There are a couple of ways:

1) Sort based on height (I assume you mean that you'll support several static heights). Fill an index buffer with all ground height indices and set the ground texture, then draw. Fill the next part of the index buffer with the next level height indices, set the level 1 height texture, then draw. Repeat for all levels. If you're drawing in perspective, you'll also want to have "transition quads" that transition between the levels. You can add these quads to an index buffer, set the transition texture (maybe brown/rocky like a rock wall), then draw those.

2) You can use a shader and multi-texturing. If the card supports it, send 4 textures to the shader with the vertex data. Using the height of the vertex, modulate the textures together. For instance, if your terrain can be 0 to 255 for the y value of the vertex, you would set aside blending information for the 4 textures. Water is the lowest texture, Grass is texture 2, rock is texture 3, and snow is texture 4. A vertex with height between 0 and 25 would be water. Between 25 and 30 would be water and grass mixture. Between 30 and 75 would be all grass. Between 75 and 100 would be rock and grass blended. Between 100 and 200 would be rock, etc...

Good luck,
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by Supernat02
There are a couple of ways:

1) Sort based on height (I assume you mean that you'll support several static heights). Fill an index buffer with all ground height indices and set the ground texture, then draw. Fill the next part of the index buffer with the next level height indices, set the level 1 height texture, then draw. Repeat for all levels. If you're drawing in perspective, you'll also want to have "transition quads" that transition between the levels. You can add these quads to an index buffer, set the transition texture (maybe brown/rocky like a rock wall), then draw those.

2) You can use a shader and multi-texturing. If the card supports it, send 4 textures to the shader with the vertex data. Using the height of the vertex, modulate the textures together. For instance, if your terrain can be 0 to 255 for the y value of the vertex, you would set aside blending information for the 4 textures. Water is the lowest texture, Grass is texture 2, rock is texture 3, and snow is texture 4. A vertex with height between 0 and 25 would be water. Between 25 and 30 would be water and grass mixture. Between 30 and 75 would be all grass. Between 75 and 100 would be rock and grass blended. Between 100 and 200 would be rock, etc...

Good luck,
Chris


Well, that's a very different interpretation of the question than mine and probably the correct one. Please ignore my previous response. :)

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!