Sign in to follow this  

Multiple Texture Coordinates

This topic is 3664 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 have a terrain of, for agument's sake, 65 x 65 vertices and I'd like to texture splate that terrain. My base texture is fairly small (64x64) and needs to be wrapped a few times, my second texture is bigger (128x128) and so needs to be wrapped slightly less and my alpha texture (256x256) is to be stretched over the complete terrain, so no wrapping at all. If I use a pixel shader to splat this, do I need 3 seperate texture coordinates or just the one stretched alpha map tex coords? In the pixel shader, in order to get the two base texture coordinates, can I just mul() up and modulo the stretched coordinates to get the other two sets? Does anyone know if this is possible before I rip out 2 sets of text coords from my terrain vertex declaration? If it is possible, is it going to slow things down drastically? Or would it be just better to have the tex coords in the vertex declaration? My vertices with the 3 texcoords (4 in fact), come out at 60bytes per vertex which, with my geometry requires ~23.8megs. If I can lop off 24 bytes, I'll save myself nearly 10megs of vertex buffer. Thanks

Share this post


Link to post
Share on other sites
Hi,

As input you'll need just one set of texture coordinates. You could set them to go from 0,0 to 1,1 over your terrain patch.

From the vertex shader you can output as many coordinate sets are you desire (up to the limit of the hardware) with the desired scale.



//pseudo shader

Out.texAlpha = In.Tex;
Out.tex1 = In.Tex * 4.0f; //4.0f = tiles 4 times over the patche
Out.tex2 = In.Tex * 16.0f; //





Currently I am using 8 bytes per vertex. 6 bytes for x,y,z and 2 bytes for normal. I am planning to implement a normal map system and do some further bit packing to get 4 bytes per vertex. 2 bytes for x,y and 2 bytes for z.
This system requires drawing the terrain as patches of different sizes with specific scaling matrices.

Of course, you can use vertex texture lookup too.

Best regards!

Share this post


Link to post
Share on other sites
Quote:
Original post by RobMaddison
In the pixel shader, in order to get the two base texture coordinates, can I just mul() up and modulo the stretched coordinates to get the other two sets?
In SM2 and above you can do this, but SM1 has limitations on texture coordinates and samplers.


Quote:
Original post by RobMaddison
If it is possible, is it going to slow things down drastically?
It could have an adverse impact as you're likely to introduce 'dependent reads' into your shader. That is, sampling of a texture depends on some of the shader code being executed. Sampling typically has very high latency on GPU's so theres a lot of optimization effort in hiding this by keeping ALU's busy whilst the TMU's fetch - by making them dependent you lose some parallelism.

Quite what sort of impact this would have is unclear without profiling.

You can use your vertex declaration to create a "view" onto the data with only one texture coordinate, so try it and see before you actually modify the way data is stored in the VB. If performance sucks then it's easy to roll back.

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 3664 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this