• Create Account

## SampleLevel Texture coordinate format

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Naruto-kun  Members

411
Like
0Likes
Like

Posted 09 February 2014 - 08:37 AM

Hi guys

Is the texture coordinate format for SampleLevel the same as the viewport (ie +-1.0 x and y) or is it integer based?

The reason I ask is I need to do a edge check in my pixel shader where I will sample 4 pixels around each point to see if they are black. Not sure how to go about this.

Also, anyone got a efficient solution for a white noise generator in HLSL? I found this: http://www.reedbeta.com/blog/2013/01/12/quick-and-easy-gpu-random-numbers-in-d3d11/

but from the comments I understand it can be rather slow.

Also found this in the comments:

return fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);

But would like to know if there is anything faster out there. I want to noise up the texture for a certain distance within the edges as I locate them.

Thanks

JB

Edited by Naruto-kun, 09 February 2014 - 08:40 AM.

### #2Chris_F  Members

3018
Like
2Likes
Like

Posted 09 February 2014 - 11:14 AM

As far as white noise goes, I'm playing around with this shader at the moment.

layout(location = 0) uniform float time;
out vec4 frag_color;

uint hash(uint x)
{
x = ((x >> 16) ^ x) * 0x85ebca6b;
x = ((x >> 13) ^ x) * 0xc2b2ae35;
x = ((x >> 16) ^ x);
return x;
}

uint hash(uvec2 v) { return hash(v.x ^ hash(v.y)); }
uint hash(uvec3 v) { return hash(v.x ^ hash(v.y) ^ hash(v.z)); }
uint hash(uvec4 v) { return hash(v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w)); }

float floatConstruct(uint m)
{
m &= 0x007FFFFFu;
m |= 0x3F800000u;

float  f = uintBitsToFloat(m);
return f - 1.0;
}

float random(float x) { return floatConstruct(hash(floatBitsToUint(x))); }
float random(vec2 v) { return floatConstruct(hash(floatBitsToUint(v))); }
float random(vec3 v) { return floatConstruct(hash(floatBitsToUint(v))); }
float random(vec4 v) { return floatConstruct(hash(floatBitsToUint(v))); }

void main()
{
frag_color = vec4(random(vec3(gl_FragCoord.xy, time)).xxx, 1.0);
}


It costs 0.28ms @ 1080p on my GTX 760, which is not all that much slower than the fract/sin implementation. The results however are a lot better. The fract/sin implementation produces a lot of noticeable patterns for me, and because of the way trig functions are implemented differently on various GPUs, it can have a lot of variability. This is GLSL by the way, but I'm sure you can modify it if you want to try it.

Edited by Chris_F, 16 February 2014 - 06:11 PM.

### #3MJP  Moderators

18236
Like
1Likes
Like

Posted 09 February 2014 - 02:48 PM

The UV coordinate range for SampleLevel is the same as Sample: (0, 0) is the top left of the texture, and (1, 1) is the bottom right. For the actual mip level parameter the range is [0, N], where N is equal to NumMipLevels - 1.

### #4Naruto-kun  Members

411
Like
0Likes
Like

Posted 10 February 2014 - 03:11 AM

awesome stuff. thanks a bunch.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.