Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 Account settings
  Posted by: igthorn
  When: 21/04/2014 at 10:20:00

 Pavtube 2014 Easter Deals with 20% off
  Posted by: igthorn
  When: 21/04/2014 at 10:16:23

 20% off on iMedia Converter for Mac
  Posted by: VIKIVannessa
  When: 20/04/2014 at 01:35:54

 Pavtube Video Converter Ultimate Deal
  Posted by: VIKIVannessa
  When: 20/04/2014 at 01:35:50

 Easter Day Deals
  Posted by: Applefly
  When: 19/04/2014 at 22:18:14

 40% OFF Pavtube DVD Ripper for Mac
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:54

 DVD Ripper with 40% off
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:22

 Get DVD Ripper Wind/Mac + $14 Coupon
  Posted by: VIKIVannessa
  When: 19/04/2014 at 02:02:03

 Backup DVD Escape Plan
  Posted by: Applefly
  When: 17/04/2014 at 06:00:12

 Disney DVDs to MP4
  Posted by: Applefly
  When: 17/04/2014 at 05:56:07

 DVD movies through media streamer
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:25:09

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 16/04/2014 at 02:20:51

 Blu-ray to Apple ProRes
  Posted by: Applefly
  When: 12/04/2014 at 00:47:46

 HD H.264 MP4 format
  Posted by: Applefly
  When: 12/04/2014 at 00:43:23

 DVD collection to computer
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:13:33

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:11:27

 DVD movies to play on Galaxy Tab 3 10.1
  Posted by: VIKIVannessa
  When: 04/04/2014 at 07:11:27

 DVD Ripper to populate
  Posted by: Applefly
  When: 04/04/2014 at 05:01:35

 kids and family watch DVD
  Posted by: Applefly
  When: 04/04/2014 at 04:59:21

 Blu-ray movie for your lovely kids
  Posted by: VIKIVannessa
  When: 02/04/2014 at 05:47:49




Topic: Question on texturing Terrain



  
Goto parent category
  
Create a new user account


   Question on texturing Terrain
 Poster : reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by reiko on 21/07/2008 at 21:39:07
Hello riemer , i have a question about texturing terrain , i have 64 x 64 Terrain and I want to texture it with Different Textures ,
for each 4 x 4 i need to use different texture
how i can solve this ?

i folowed your tutorial in the 4th series but the example but it dosn't fix my problem thanks
:) thanks
 Poster : Reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by Reiko on 23/07/2008 at 14:58:26
help any one ? :s

the problem is that i want to texture every 4X4

but a different texture ; than the other one , in the example of textured terrain , we use only 1 Texture , how i can use multiple textures on single terrain in that way ..
 Poster : Serendipity
 Posts: 27
 Country : Pakistan
 City: Rawalpindi

  
Posted by Serendipity on 24/07/2008 at 00:18:32
Hi!

I also want to do something like you mentioned and I'm new to this. So I haven't yet looked into it but my idea is that I'll achieve this using meshes. I guess in your case it could be something like:
First converting the terrain into a mesh and by defining each 4x4 block as a different subset of the mesh. Meshes make things very easy, infact they are for this very purpose as I have come to understand them. U can assign different textures and material to different subsets of the mesh.

Serendipity
 Poster : Serendipity
 Posts: 27
 Country : Pakistan
 City: Rawalpindi

  
Posted by Serendipity on 24/07/2008 at 00:25:23
http://www.riemers.net/eng/Tutorials/DirectX/Csharp/Series2/tut5.php

take a look at this page ...
 Poster : radulph
 Posts: 225
 Country : germany
 City: hamburg

  
Posted by radulph on 24/07/2008 at 08:06:20
for(int x = 0; x < terrainWidth; x++)
  for(int y = 0; y < terrainHeight; y++)
    vertices[x + y * terrainWidth].texture =
      ((x - x % 4) / 4) + ((y - y % 4) / 4) *
        (terrainWidht / 4);

The code above maps an integer from 0 to 15 to each vertex, where every 4x4 block of your terrain gets the same value.

Now you can pass all your 256 textures ( (64 / 4) * (64 / 4) ) to your shader and switch which one you want to use for each vertex, dependent on its texture index.

If, what I expect, you don't want to set all the 256 textures explicitly, you can pass a smaller nubmer of textures to your shader and downscale the indices with the modulo funtion.
 Poster : reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by reiko on 24/07/2008 at 10:41:22
Hi again :)

thanks for the help , i tryed to use the code that u wrote above , but the VertexPositionNormalTexture
does not contain definition " texture" , so i get error when Compiling , can u explain me more please .
i am also new in this and i really need make it work . thanks alot :)

here is what i want to do on screen , every texture represent 4x4 on the terrain .

http://img367.imageshack.us/my.php?image=terrainuc7.jpg

i also have another problem on texturing , here is screenshot

the Textures are mirrored in clock wise , how i can make it texture it Right please , thanks alot for these tutorials riemer and thanks for the Helpful community

 Poster : radulph
 Posts: 225
 Country : germany
 City: hamburg

  
Posted by radulph on 24/07/2008 at 12:21:44
I'm not sure, if I understand you problem correctly. (the screenshot confused me :-p)

As I know Riemer uses Multitexturing in the 4th part of his tutorials. He determines which texture to choose, dependent on the height of the particular vertex.

It sounds, as if you would like to subdivide your 64x64 terrain in 4x4-blocks (which would result in 256 blocks). Then you would like to assign an individual (or at least some different) textures to each block (to all the blocks) - is that correct?
(You can imagine of this, like having a huge terrain with different "worlds", like in WOW)

If you would like to do, what I just described, you would have to add a field "texture" to your VertexPositionNormalTexture struct, of type float for example. This leads to the need of changing the array "VertexElements" as well es the "SizeInBytes" - Field.

You should be able to figure out the needed changes on the struct by the tutorials.

Now you have your terrain subdivided in 256 4x4-blocks enumarated from 0 to 255 (from left to right and top to bottom) and can assign textures to each block dependent on this index.

The tiling problem could come from assigning a wrong address mode. Check out your effect file for the definition of the texture samplers and see, if you find something like this:
... = sampler_state { ... AddressU/V = mirror ... }

Greets.
 Poster : reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by reiko on 24/07/2008 at 12:57:23
Hi ,radulph

yes you are correct , but , *The terrain is 64x64  and i want to devide it by 4x4 Blocks so there will be   16 x 16 Blocks of tiles  not 256 :)

as it is in the screenshot by the "X" ( i wrote The Letter T on the texture so i can check if its mirorred or no )

thats i didn't understand well your explanation , can u add me in msn and help me so i can explain you more what i want to do :  lodgun@hotmail.com

,
for the textures yes checked again the *.fx file

sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};

the addressU and V are mirror what should i put there instead of mirror to make it texture corectly
 Poster : Archenon
 Posts: 428
 Country : Romania
 City: Oradea

  
Posted by Archenon on 25/07/2008 at 00:57:01
16 X 16 = 256
 Poster : Reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by Reiko on 25/07/2008 at 06:21:31
yea yea 256 , i was Thinking about Other Thing thats why i said 64 :] , 16 x 4  

well i Have changed the
address U and V in the texture sampler to "Warp" and it works fine now , Blut still gotta make Terrain Blocks :s
 Poster : radulph
 Posts: 225
 Country : germany
 City: hamburg

  
Posted by radulph on 25/07/2008 at 06:34:57
Hi Reiko,

I'm glad to hear, that you solved your tiling problem.

You have all you need to subdivide yout terrain in 4x4 blocks.

Use the code I posted earlier. As you mentioned correctly, it doesn't compile since your VertexPositionNormalTexture struct is missing the field "texture".

That's why I explained you the needed changes to your struct some posts later.

Just try it out.

Anyway, I'll see, what I can do(msn)

greets.
 Poster : reiko
 Posts: 10
 Country : UK
 City: london

  
Posted by reiko on 17/11/2008 at 06:39:56
hello i have relooked into the project searching an easy way to render it , and i found out that Serendipity idea is the easyest way  ( at least for me).
the problem is that i don't know how to convert my terrain into a mesh and set each 4x4 as new mesh Subset .
it will be easy to draw everything with a simple method like this , a help will be appreciated .
thanks for the great tutorials and great Book .

  
Post a new reply
 





Google
 
Web www.riemers.net
If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !
- Website design & DirectX code : Riemer Grootjans -
©2006 Riemer Grootjans


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)