Jump to content
  • Advertisement
Sign in to follow this  

arbitrary texture coordinates

This topic is 976 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'm trying inside a loop accessing a texture color using arbitrary coodinates. 


My texture can map properly to a mesh but I can't seem to sample them without using the mesh uv coodinate. 

while (count <= size)
	int x = (int)(count % w);
	int y = (int)(count / w);
	float2 uv = float2(x, y);
	float3 = col.Sample(texturesampler, uv).rgb;

the color output is always wrong. like its only sampling one color


this is my sampler description 

                AddressU = TextureAddressMode.Clamp,
                AddressV = TextureAddressMode.Clamp,
                AddressW = TextureAddressMode.Clamp,
                BorderColor = new Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter = Filter.MinLinearMagMipPoint,
                MaximumLod = float.MaxValue,
                MinimumLod = 0,
                MipLodBias = 0.0f

so I'm wondering if there it can be done or if I have to use something like sampleGrad. 




Share this post

Link to post
Share on other sites
What exactly are you trying to do ?

There are several pitfalls in your shader code.
1. float3 = col.Sample(texturesampler, uv).rgb;
This will not compile, will it (ok, I'm not familiar with hlsl) ? Do you want to sum it up, average it or get the last color ?

2. float2 uv = float2(x, y);
This will always contains integers, that is 0,1,2,3...
So, using clamp this will always sample the border of the texture ! You should apply an offset/scale accordingly, depending on what your goal is.

Share this post

Link to post
Share on other sites

ok It actually compile. but I realize I totally forgot how uv coordinates were mapped. So there I just need to subdivide by height and width. 



Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!