Terrain texture painting is when your painting a terrain with a specified texture. \u00a0The way this works is that there \u00a0is one blend texture and then three terrain textures. \u00a0The blend texture is sampled by the shader in order to determine the correct texture to apply at this location.<\/p>\n
To get started with the basics of muti-texturing I recommend reading chapter 11.8 in Frank D. Luna’s\u00a0Introduction To 3D Game Programming With DirectX 9.0c A Shader Approach<\/em>. \u00a0This book is definitely one of my favorite Graphics Programming books.<\/p>\n The first thing you have to do is create the custom blending texture. \u00a0For my Terrain Editor I allowed the user to specify the detail that they want to use for the texture. \u00a0I then determined the width and height of the texture by multiplying the width and length of the terrain by the user specified scale. \u00a0The default scale of 1 would produce 1 blend texture pixel to define 1 unit in the 3D space.<\/p>\n Like the terrain mesh, since we are editing the texture we can not use a managed memory pool. \u00a0This means we will want to store a copy of the texture locally. \u00a0The way I did this is to just create a list of\u00a0D3DXCOLOR<\/em>\u00a0values of the same amount of pixels as in the texture.<\/p>\n One of the first questions I was asking when starting this project was\u00a0“How do I edit the texture?”<\/em>\u00a0\u00a0After some research I learned that you can edit a DirectX texture by calling the\u00a0LockRect()<\/em>\u00a0function before the edit and\u00a0UnlockRect()<\/em>\u00a0after the edit.<\/p>\n The next question I was asking was\u00a0“What is the data type stored in this rectangle buffer?”<\/em>\u00a0\u00a0Again some research into some forums proved to be useful as I learned that it was an array of bytes and that you would need to index these bytes in order to edit the correct pixel that you wish to edit. \u00a0The equation for getting the index of a pixel is:<\/p>\n Index = (Y Position) * (LockedRect.Pitch \/ 4) + X Position<\/em><\/p>\n To start off I iterated through the entire texture setting each index to\u00a0D3DXCOLOR(1.0, 0.0, 0.0, 1.0)<\/em>. \u00a0This set all the colors to a solid red, which represented the first texture of my three textures. \u00a0Green was reference to my second texture and blue was a reference to my third texture. \u00a0Using the RGB of my blend texture I can determine the texture to use at the specified position where that blend texture pixel is located.<\/p>\n\u00a0Creating The Blend Texture<\/h3>\n
Editing The Blend Texture<\/h3>\n