PDA

View Full Version : noise texture



wwwq
05-04-2005, 05:05 AM
I want to get a noise in GLSL
But NVIDIA haven't implment noise() now.

So I want to load a pixel from a noise texture like this
//==========
uniform sampler2D noiseTexture;
uniform float ran1,ran2;
//==========
float mynoise()
{
vec2 rrr = vec2(gl_TexCoord[0].s, gl_TexCoord[0].t);
rrr.x += ran1;
rrr.y += ran2;
if( rrr.x > 1.0 )
rrr.x -= 1.0;
if( rrr.y > 1.0 )
rrr.y -= 1.0;

return vec4(texture2D(noiseTexture, rrr)).x;
}
===============
The ran1 and ran1 are make by main function.
I am sure ran1 and ran2 are diffirent random every time.
But I check the result.
It seems the ran1 and ran2 do not make the result change....anyone some advise ?? thx.

Relic
05-05-2005, 10:23 PM
Your ran1 and ran2 are uniforms. They keep constant over the whole rasterization of the current primitive. What that does in your case is to offset the texture coordinates, nothing more. If they happen to be integers this won't have an effect.
Other hints:
Your code does not use the vector capabilities of the GPU. There's no need to do the arithmetic on the individual components.
With texture wrap mode GL_REPEAT, you wouldn't even need to pseudo-clamp them.

Do a forum search with "simplex noise" in the topics. There are two threads with implementations of really nice noise.