Complicated texture coordinate mapping question

Started by
3 comments, last by Carradine 21 years, 6 months ago
I do not believe that I have coded myself into a corner here, but I would like to know If what I am attempting to do is possible. Lets say I have a 10x10 grid of height data and I wish to display it in D3D. That way I currently do this is by creating an index buffer to display the polygons. So I lock 100 points into the buffer, then draw them by using a DrawIndexedPrimitive() call as one long triangle strip. Somewhat standard coding there. Now what happens is that I want to put a different texture on each of my 100 "squares" I just created. For arguments sake I will say I want to put a random texture on each square. This is a problem now, since I draw the whole grid at once, I cannot define multiple texture coordinates for the same vertices. What I have done for simplicity sake, I have all my different textures, as squares, entered in grid form in a .bmp file. So If I want to access a texture, I just to enter some square coordinates. So if I have a 5x5 = 25 textures in one texture file, I can use the texture coordinates (.2,.2) to (.4,.4) to access a texture "square" 1 over and 1 down. Ok, now lets say at point (2,2) at my terrain grid, I want to place the texture from the example above there. So my texture coordinates at point 2,2 need to be (0.2,0.2). Now here is the problem. at points (3,2), (2,3) and (3,3), my texture coordinates need to be (0.4,0.2), (0.2,0.4), and (0.4,0.4) to create the texture there. BUT NOW I run into this problem. at a point like (3,3) on my height map, I have texture coordinate (0.4,0.4), when I come to draw the texture from point (3,3) to (4,4) how can I? the texture coordinate at (3,3) is already defined! So how I can fix this problem? I know one way may be to enter a second set of coordiantes into my vertex data. Indicating the other coordinates. However I have no way of accessing them since I use an index buffer to draw my 10x10 grid. Unless there is a way to tell the program which set of textures for each ''index'' point I have (which is what I am mainly trying to figure out). The only answer I know of is to take the easy way out, which is to remove the index buffer, and instead of pushing only 100 vertices and using and index buffer, I would need to push in sizeof(index buffer) vertices, and enter new texture information for each point. I was hoping to avoid using the second answer, since that would definately slow down my rendering process by more than half. So, the ''quick'' question is this... Can I create an index list indicating which set of texture coordinates to use, and use that WITH my index list for processing vertices? So that i can say whether to use my first or second set of texture coordinates for each point in my index list. Carradine

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

Advertisement
Hmm - I''ve not absorbed your post in depth (it''s been a long day...).

However if I''m thinking about the right problem, you could:

- put the "which texture" value into a second vertex buffer which contains 1 DWORD per vertex and nothing else.

- put both sets of texture coordinates in your main vertex buffer.

- send both vertex buffers using two streams. Stream0=main VB, Stream1=DWORD VB

- use a vertex shader which looks at the value in the DWORD VB and uses that to decide which tex coord set to use:

oT0.xy = (vSet1.xy * vDW.xx) + (vSet2.xy * vDW.yy)

Then set the DWORD to [1.0, 0.0, 0.0, 0.0] for set 1
Or set the DWORD to [0.0, 1.0, 0.0, 0.0] for set 2


Or maybe use render to texture to assemble the texture as you need it (VRAM source textures onto VRAM dest texture should be fast ish).


However you have to remember that those methods also have costs - whether or not the above will be faster all depends on your particular data etc. Profile & see.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

you could always use another 2d map, taking care to give or take out 2 coordinates and then otherwise incorporate them into the v_buffer (not really sure you''ll get a good result) or use a strided buffer -> one v_buffer holds geometry position, the other v_buffer holds tex coord. This last one is actually recomended for this kind of stuff but I''m not sure how you integrate them seamlessly... all I know is that on rendering you set the geometry v_buffer as the first v_buffer and the tcoord v_buffer as the second v_buffer, probably the same applies for the index buffer, one for geometry and one for t_coords, BUT I really don''t know...
S1CA, that is exactly what I would like to do, which is simply be able to tell the program what texture coordinates to use in that way. My only problem is that I dont understand how to create a vertex shader that can read in a value from one stream, then set the texture coordinates based on that number from anotyher stream. I am not sure if this a simple or complex vertex shading method. Perhaps all I need is an example. If you or someone else knows some examples I can learn from taht would really be helpful.

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

Well I spent the whole day learning vertex shaders, I learned alot and now I believe I know what i need to implement my texture coordinates. Thanks for the help.

--------------------------Vantage: Greenlit on Steam / Independent Games Festival Submission http://www.crystaldragon.com

This topic is closed to new replies.

Advertisement