PnP TerrainCreator - Forum

The PnP TerrainCreator Forum
It is currently Sun Sep 24, 2017 5:33 pm

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Importing terrain and texturing into a DirectX engine.
PostPosted: Fri Mar 07, 2008 8:27 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
What method should I use to get the texturing imported into my project? Currently, I export the mesh to a .x and can display the non blended terrain just fine inside my engine. ( The texture squares show - just not blends between squares )

What approach should I take to get the blended texturing onto the terrain so that it looks like it does in the Terrain Creator. What else needs to be exported from Terrain Creator to make it work - other than the .x file?

Is there example DX SDK C++ code to make it look like inside the editor available anywhere?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 7:26 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Hi,

the problem is .x files don't support such a feature by default. So as far as I know, there is no easy way to use the blended technique directly in DX. You have to code such alpha blending (splatting) techniques on your own. I don't know of any sample codes in the SDK or anywhere else, sorry. There is a tutorial on the web for implementing splatting http://cbloom.com/3d/techdocs/splatting.txt.

The exporter "Texture Splatting Alphamap Export" can create the alphamaps, which are needed for this splatting technique.

If you want results quickly using x files, you have to use the "texture map" texturing technique instead. Which means baking the detail textures into one big texture which is laid over the terrain surface. This can be done automatically during export from TC. However, the texture quality is not as good as using the splatting technique.

Hope this could help a little.
Ralf


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 08, 2008 9:57 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Thanks for the info!

I've managed to get closer. I have exported the splatted alphamaps, but they're not in a format which actually has an alpha layer, so I'm having to manually convert them to .tga files so that DX can natively see the alpha.

( EDIT - see next post about DDS format )

I'm using the following code to read the alpha:

Code:
// Alphamap: take the alpha from the alphamap, we don't care about the color
device3D->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
device3D->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);

// Texture: take the color from the texture, take the alpha from the previous stage
device3D->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
device3D->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device3D->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
device3D->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);


I'm pretty new to multi-texturing so I'm not sure if I can use a different method to get alpha from a regular .BMP. Am I stuck converting them to .tga's?

I also need to figure out how to stretch the entire exported splat map across the entire exported mesh that comes from Terrain Creator. Currently it's applying the splat blend over each cell. That's my current task. I think it's gonna work out though.

I'm excited that I may have finally found a terrain creator I can use with my project. I haven't wanted to drop $$$ on a terrain creator without getting the code working first, so things are looking good so far!

Thanks!


Last edited by Fordfanboi on Sun Mar 09, 2008 12:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 12:25 am 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Ah-hah - DDS format contains the alpha.

Now, I just need to figure out how to stretch the single splat texture over the mesh. Currently it keeps tiling the splat texture over a single cell. =\


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 09, 2008 8:52 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
For the alpha question... keep in mind, that you don't exclusively have to use the alpha channel for the alphamaps. You can code four alphamaps in the for channels (RGBA) of a texture. This way using shaders, you can blend four textures in one pass and so reduce the number of required render passes and increase performance.

Depending on the "ground texture size" setting, the texture coordinates (UV) repeat multiple times over the lenght of one sector. If you use these UV coordinates to map the alphamaps on the mesh, they will be displayed repeatedly.

If you use "texturemap" as "texture export" option in the x-file exporter instead, the UV coordinates of the terrain will range from 0 to 1. So it would be possible to spread the whole alphamaps over the complete terrain/sector.

However, if you use the same UV coordinates for the detail texture and the alphamaps, the detail textures will too be spread over the whole terrain, which will give you the same visual quality as if you'd used the "texturemap" method. So, you need two sets of texture coordinates. One for the alphamap ranging from 0 to 1 and one for the detail textures, which range from 0 to 32 (for example). As far as I know, this is not possible for the .x file format. So you have to adapt your mesh during loading, use a shader to compute the UVs, or create you own export file format instead.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 3:32 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
I managed to get this going where I used the detail texture exported mesh then blended the sector texturemap over the top, but my blends are no-where near as good as inside the TC. Any hints as to how the detail tiles are blended so well inside TC?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 4:12 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
can you post a screenshot?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 19, 2008 4:22 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Sure - I will set my code back to using detail maps and take a shot for ya.

TY


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 3:10 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Apparently my code is currently too far embedded with the texturemaps to quickly do this. heh

It looks like PNPTC does with no blending - you see square detail textures. I need to figure out code for doing the linear blending like you do in PNPTC.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 06, 2008 3:20 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
I'm using vertex alpha to blend the textures. On page 26 chapter 5 of the manual there is a short description of this method.

However, the alphmap blending method as used in splatting produces even higher quality blends. (http://cbloom.com/3d/techdocs/splatting.txt)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 2:27 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Ralf wrote:
I'm using vertex alpha to blend the textures. On page 26 chapter 5 of the manual there is a short description of this method.

However, the alphmap blending method as used in splatting produces even higher quality blends. (http://cbloom.com/3d/techdocs/splatting.txt)


Alpha blending - so I should be able to use the following to reproduce it I believe?

http://www.gamedev.net/reference/articles/article2238.asp

Which plugin exporters would I want to use to make it work with the above?

TY!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 10:11 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
The "Texture Splatting Alphamap Export" should be a good starting point for this. It will create the alphamaps for you. However, you have to build the geometry and the texturing/blending in your engine by hand. As far as I know, the .x-file format does not support such complex texturing scenarios. So, the x-file exporter will not help you there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 3:00 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Thanks for the info.

So, I should be able to pull the value of each pixel in the Alphamap Export and assign that to a detail texture, correct? ( I haven't looked at that export - is that how that one works? ) Then I would look at the surrounding pixels in the alphamap and create a texture of possibly 4 different textures using the pixel shader listed in the link I gave earlier.

I think I can do that fairly easily.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 7:27 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Yes.

Lets say you have a terrain patch with 256x256 vertices.

To simply get a start, use two texture channels and two pairs of texture coordinates for these channels. Use one channel for the alphamap as it is exported from that PlugIn. The alphamap controls the visibility of one detail texture each; lets say a grass texture for example. This alphamap is spanned over the whole patch, so the texture coordinates for it should go from 0/0 at vertex 0/0 to 1/1 at vertex 255/255.

The second texture channel holds the detail texture, the grass texture for example. In order to have a more detailed texture resolution, the texture coordinates will make the texture be repeated several times on that patch, so for example they range from 0/0 at vertex 0/0 to 16/16 at vertex 255/255, which will repeat the texture 16 times.

The alphamap now controls the opacity of the detail map. A white pixel in the alpha map means opaque while a black pixel means transparent. You have to multiply this value with the transparency used for the detail texture as describe in the articel of your link. So, you render the same complete terrain patch once for every detail texture.


You can later use a couple of improvements, especially if you are using shaders. For example you don't have to store two sets of texture coordinates, they can be easily computed in the shader and so save memory. An you can use the RGBA channels of the alphamap to control the opacity of four detail textures. This way you can render four detail textures in one render pass.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 2:35 pm 
Offline

Joined: Fri Mar 07, 2008 8:21 pm
Posts: 62
Thanks for the details!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron