|
|
Re: TexCoord[n] value range?
[Re: Joey]
#128217
05/05/07 14:06
05/05/07 14:06
|
Joined: Jan 2007
Posts: 651 Germany
RedPhoenix
OP
User
|
OP
User
Joined: Jan 2007
Posts: 651
Germany
|
Well look at this:
float2 blscale = Out.BlueCoord.xy; Out.BlueCoord.x -= 0.5f * max(0,sign(blscale.x - 0.5f));
Out.BlueCoord is the TexCOORD from a (before tiled) 512*512 texture. If it were in the range of 0.0f to 1.0f this operation should limit it to 0.5f tiling the texture new, but this doesn't happen, only one time at the beginnig of the terrain to which the texture is assigned.
EDIT: To make it more clear:
I have a multitextureshader for a terrain. I have a texturecoordinate tiled like this: Out.BlueCoord = inTexCoord0.xy * vecSkill1.y;
Now I want only the left part of the texture shown, and the other ignored, so I limit the texcoord to 0.5f as shown above, but this only works right one time (with the first tile) and then in the other tiles on the terrain, also the right part of the texture is visible.
Last edited by RedPhoenix; 05/05/07 14:26.
|
|
|
Re: TexCoord[n] value range?
[Re: RedPhoenix]
#128218
05/05/07 15:40
05/05/07 15:40
|
Joined: Jan 2003
Posts: 4,615 Cambridge
Joey
Expert
|
Expert
Joined: Jan 2003
Posts: 4,615
Cambridge
|
Quote:
Out.BlueCoord.x -= 0.5f * max(0,sign(blscale.x - 0.5f)); If it were in the range of 0.0f to 1.0f
isn't x between -1.0f and 1.0f? well, i don't know much about shaders but i've never heard something different. maybe you should look it up in the msdn.
|
|
|
Re: TexCoord[n] value range?
[Re: Rhuarc]
#128220
05/05/07 21:46
05/05/07 21:46
|
Joined: Jan 2007
Posts: 651 Germany
RedPhoenix
OP
User
|
OP
User
Joined: Jan 2007
Posts: 651
Germany
|
No what I want to do is to limit the texcoord koordinates to a certain value. For example I have a 1024*1024 map and now I want that the texcoords only go from 0-512 of the texture. If the texcoord is above it there will be a substraction of 512 so the newt tile starts. But for this I need to no the middle of the texcoord. Going with a range from 0.0f to 1.0 this would be 0.5f, but this doesn't work and if my calculation isn't wrong this can't be the right range. I also tried it supposing a range of the -1.0 to 1.0 but it doesn't work as well. EDIT: Ok I finally found it in the msdn Quote:
An Texture Coordinate Register (tn) contains four color values (RGBA). The data can also be thought of as vector data (xyzw). texcoord - ps will retrieve three of these values (xyz) from texture coordinate set x, and the fourth component (w) is set to 1. The texture address is copied from the texture coordinate set n. The result is clamped between 0 and 1.
But why doesn't my code work right then?
Last edited by RedPhoenix; 05/05/07 21:53.
|
|
|
Re: TexCoord[n] value range?
[Re: RedPhoenix]
#128221
05/06/07 00:13
05/06/07 00:13
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Some notes I've observed from my experiences with HLSL (May be wrong, but I doubt it...). This only referes to VSPS 2.0!
1) texcoords are NOT clamped. You can define 1-4 vectors each.
2) I'm not sure how the tex2D function handles texture coords. It could either pass a percentage(ex: 0-1) or actuall values (ex: 0-512)...
3) Once you figure out #2, it should be easy to cycle the tex coords on certain areas of the skin.
xXxGuitar511 - Programmer
|
|
|
Re: TexCoord[n] value range?
[Re: xXxGuitar511]
#128222
05/06/07 09:04
05/06/07 09:04
|
Joined: Jan 2007
Posts: 651 Germany
RedPhoenix
OP
User
|
OP
User
Joined: Jan 2007
Posts: 651
Germany
|
Yes xXxGuitar511 seems to be right. They aren't clamped at once in the calculation and because of that my code didn't work.
//2D Texcoord calculation float2 ints = { inTexCoord0.x * vecSkill1.y,inTexCoord0.y * vecSkill1.y }; float2 inn = { 0.5f * max(0,sign(ints.x - int(ints.x) - 0.5f)), 0.5f * max(0,sign(ints.y - int(ints.y) - 0.5f)) }; Out.BlueCoord = inTexCoord0.xy * vecSkill1.y - inn.xy;
This gives nearly the right results, but next to the borders of every tile, there is a small strip of the right part of the texture though it should be limited to the middle. So the calculation seems to be kind of 'inexact'. Do you have any idea why?
EDIT: I can't post a screenshot here so it's may be hard to understand, but I'll try to explain it more precicly: vecSkill1.y has a value of 10 so the hole texture is tiled ten times over the terrain. As you may already know I'm trying to save more than one texture in a single skin. Currently I try to get working it with four textures. Therefore this code above to get out one texture of the skin. This should choose the texture on left top in the skin, and make a tiling of 20 times, because every tile of the ten tiles now contains this texture twice. But it does something else: It creates 30 tiles and after every third tile a small strip of the right textures in the skin.
Last edited by RedPhoenix; 05/06/07 09:51.
|
|
|
Re: TexCoord[n] value range?
[Re: RedPhoenix]
#128223
05/06/07 10:35
05/06/07 10:35
|
Joined: Jan 2007
Posts: 651 Germany
RedPhoenix
OP
User
|
OP
User
Joined: Jan 2007
Posts: 651
Germany
|
float2 ints = { inTexCoord0.x * vecSkill1.y,inTexCoord0.y * vecSkill1.y }; float2 inn = { 0.5f * max(0,sign(frac(ints.x) - 0.5f)), 0.5f * max(0,sign(frac(ints.y) - 0.5f)) }; Out.BlueCoord = frac(ints.xy) - inn.xy;
Ok with this code it only shows the left top texture, but the texture isn't tiled right. It now makes 40 tiles and only every 8 tile it is tiled at the right border, it seems to cut a short part of the texture out now.
EDIT: I got it working. The work had to be done particially on the pixel shader that was the problem. Thanks for helping me with the texcoords, if I finish the hole shader I'll post it.
Last edited by RedPhoenix; 05/06/07 12:23.
|
|
|
Re: TexCoord[n] value range?
[Re: RedPhoenix]
#128224
05/06/07 16:18
05/06/07 16:18
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I would've tried something mith mod operators. here's an example assuming that texcoord holds actuall pixel placement with a 512x512 texture. The TL [top-left], TR [top-right], BL [bottom-left], BR [etc] stand for the position in the skin.
// Texture Scales... float tlScale = 10; float trScale = 5; float blScale = 8; float brScale = 69;
// The math... Out.texcoordTL.x = (In.texcoord.x * tlScale)%256; Out.texcoordTL.y = (In.texcoord.y * tlScale)%256; Out.texcoordBL.x = (In.texcoord.x * tlScale)%256; Out.texcoordBL.y = (In.texcoord.y * tlScale)%256 + 256; Out.texcoordBR.x = (In.texcoord.x * tlScale)%256 + 256; Out.texcoordBR.y = (In.texcoord.y * tlScale)%256 + 256; Out.texcoordTR.x = (In.texcoord.x * tlScale)%256 + 256; Out.texcoordTR.y = (In.texcoord.y * tlScale)%256;
xXxGuitar511 - Programmer
|
|
|
|