Noise Questions
category: code [glöplog]
https://www.shadertoy.com/view/XsfGzH
how to get the noise texture ? or how about generating it ?
at this time I use another shader random() :
random(vec4 p)
{
i = floor(p);
a.x = dot(i, n1);
a = a.xxxx + n2;
f = cos((p-i)*3.14159);
f = f * medium;
f = medium - f;
f = frac(p);
f = f*f*(3.0-2.0*f);
i = sin( cos( a ) * a );
j = cos((psone + a)) * (psone + a);
j = sin( j );
a = mix(i,j, f.xxxx);
a.xy = mix(a.xz, a.yw, f.yy);
a.x = mix(a.x, a.y, f.z);
a.xyzw = a.xxxx;
a;
};
please help me...
how to get the noise texture ? or how about generating it ?
at this time I use another shader random() :
random(vec4 p)
{
i = floor(p);
a.x = dot(i, n1);
a = a.xxxx + n2;
f = cos((p-i)*3.14159);
f = f * medium;
f = medium - f;
f = frac(p);
f = f*f*(3.0-2.0*f);
i = sin( cos( a ) * a );
j = cos((psone + a)) * (psone + a);
j = sin( j );
a = mix(i,j, f.xxxx);
a.xy = mix(a.xz, a.yw, f.yy);
a.x = mix(a.x, a.y, f.z);
a.xyzw = a.xxxx;
a;
};
please help me...
Well, if you're reading a texture, it'd be
The most used shader random is along the lines of
Code:
(or texture2D, not quite sure about OpenGL ES). Or do you want to load the texture from somewhere and send it to the shader?texture(texname, uv);
The most used shader random is along the lines of
Code:
With carefully selected seed values it produces quite okay random numbers for gfx purposes at least.float rnd = fract(bigseed*sin(smallerseed*x));
Perlin and simplex by Stefan Gustavson
http://www.davidcornette.com/glsl/GLSL-noise.zip
http://www.davidcornette.com/glsl/GLSL-noise.zip
it seems that the random() function I used gives smooth clouds or flames, like in : https://www.shadertoy.com/view/MdX3zr but it's too slow for realtime renderings.
I'm seeking for "LUT based 3d value noise" on Google and I've found nothing. can the noise texture used in ShaderToy could be posted somewhere ?
Bartoshe, do you mean the code to generate the noise texture from ShaderToy or the texture image itself?
yes, thanx, but why if I generate one with rand()&255 , it simply do weird stuffs ?
note that my software DeadDeer can use the shadermodel3 at now, function calls, rep, and more. I've played porting GLSL shaders to my effect built-in scripting engine that can run both OpenGL or directX shaders. I've started upgrading my 3d engine last year after MainParty 2012. I was full of physics I've studied and I was writing books of sciences.
http://deaddeer.free.fr/
Making raymarching animations is simply the top of technology. I want to know how a random table can be set !
http://deaddeer.free.fr/
Making raymarching animations is simply the top of technology. I want to know how a random table can be set !
I'm not sure how that noise texture is generated Bartoshe, hopefully iq will spot this thread and provide the answer.
If you're on Facebook, you could maybe ask here.
Replacing the noise function in the fragment shader with this, should give you what you want (from this noise shader example by iq on shadetoy):
You could also render to texture using the shader to make your own noise texture, just like the shadertoy one.
Code:
float hash( float n ) { return fract(sin(n)*43758.5453123); }
float noise( in vec3 x )
{
vec3 p = floor(x);
vec3 f = fract(x);
f = f*f*(3.0-2.0*f);
float n = p.x + p.y*157.0 + 113.0*p.z;
return mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
mix( hash(n+157.0), hash(n+158.0),f.x),f.y),
mix(mix( hash(n+113.0), hash(n+114.0),f.x),
mix( hash(n+270.0), hash(n+271.0),f.x),f.y),f.z);
}
You could also render to texture using the shader to make your own noise texture, just like the shadertoy one.
barti: where are you using this noise function, and how? If you want to generate it in glsl, it's different from if you want to generate it on the CPU. And if you want it animated in realtime in 3d, that's different from static 2d.
Btw, rand()&255 looks wrong, why the AND part? Check what RAND_MAX is. If it's a 32bit integer output, you're making the first 8 bits all 1. Maybe you can just use rand() alone for 4 pixels (if the texture is 1 channel, 8 bit). I don't think this will work in a shader (at least in GLSL, unless things improved in recent versions the noise function was near enough useless..)
Btw, rand()&255 looks wrong, why the AND part? Check what RAND_MAX is. If it's a 32bit integer output, you're making the first 8 bits all 1. Maybe you can just use rand() alone for 4 pixels (if the texture is 1 channel, 8 bit). I don't think this will work in a shader (at least in GLSL, unless things improved in recent versions the noise function was near enough useless..)
Quote:
you're making the first 8 bits all 1
Eh, no, that is not how a bitwise AND works.
eh, yes, my brain is slowly shutting down for the night :) So it's setting the rest of the bits to 0. I still don't get why you'd do that, since 32bit (or 16 or 64) would give you more random bytes, likely at lower cost.
It would not matter, assuming every bit is random. He just wants a random number between 0 and 255.
And I think he is talking about generating a noise texture map. As you do that only once performance is not really an issue.
yes, well with iq's texture RGBA256x256 the code looks like :
p = floor(x);
f = fractionnal(x);
f = f*f*(3.0-2.0*f);
uv.x = 37.0*p.z;
uv.y = 17.0*p.z;
uv.xy = p.xy + uv.xy;
uv.xy = uv.xy + f.xy;
uv.zw = pszero.xx;
uv.x = (uv.x + 0.5)/256.0;
uv.y = (uv.y + 0.5)/256.0;
a = sample(0,uv);
a.x = 2.0*a.x -1.0;
a.y = 2.0*a.y -1.0;
a.x = mix(a.y, a.x, f.z);
a.xyzw = a.xxxx;
a;
so it seems to the cos sin random function in application of noisy renderings, but if you change 37.0 or 17.0, it does not work properly. so, why ?
deaddeer have Scripting engine to generate the texture, I would want to generate the same Noisy texture !
p = floor(x);
f = fractionnal(x);
f = f*f*(3.0-2.0*f);
uv.x = 37.0*p.z;
uv.y = 17.0*p.z;
uv.xy = p.xy + uv.xy;
uv.xy = uv.xy + f.xy;
uv.zw = pszero.xx;
uv.x = (uv.x + 0.5)/256.0;
uv.y = (uv.y + 0.5)/256.0;
a = sample(0,uv);
a.x = 2.0*a.x -1.0;
a.y = 2.0*a.y -1.0;
a.x = mix(a.y, a.x, f.z);
a.xyzw = a.xxxx;
a;
so it seems to the cos sin random function in application of noisy renderings, but if you change 37.0 or 17.0, it does not work properly. so, why ?
deaddeer have Scripting engine to generate the texture, I would want to generate the same Noisy texture !
I'm not GPU expert, but from what I know, as many shaders are performance bond by texture memory bandwidth, having noise function implemented purely using math is more efficient.
second, I would think that "rand()&255" would be fine as long as you're looking for a uniform noise. this is ok, depending on what you want to do with the noise. if this is what you're looking for you could just use the following
Regarding IQs function, I didn't really dig into it, but it seems to support noise gradients where the values are 2D interpolated between the "noise samples". Those are very useful for generating perlin noise images by adding several layers with different frequencies.
Regarding the 17 and 37, I would think that it should be OK to change those as long as they are primes.
Another little comment on IQs function, the "f*f*(3.0-2.0*f)" part is actually smoothstep function. Two things regarding it: first, you should probably use the improved function "x*x*x*(x*(x*6 - 15) + 10)" suggest by Ken Perlin. second: I'm not sure what's the implementation of the internal GLSL function, but using it might be more effective.
My two cents...
second, I would think that "rand()&255" would be fine as long as you're looking for a uniform noise. this is ok, depending on what you want to do with the noise. if this is what you're looking for you could just use the following
Regarding IQs function, I didn't really dig into it, but it seems to support noise gradients where the values are 2D interpolated between the "noise samples". Those are very useful for generating perlin noise images by adding several layers with different frequencies.
Regarding the 17 and 37, I would think that it should be OK to change those as long as they are primes.
Another little comment on IQs function, the "f*f*(3.0-2.0*f)" part is actually smoothstep function. Two things regarding it: first, you should probably use the improved function "x*x*x*(x*(x*6 - 15) + 10)" suggest by Ken Perlin. second: I'm not sure what's the implementation of the internal GLSL function, but using it might be more effective.
My two cents...
for 17 and 37 values, if I change to 23 for example, that is prime number, it gives artefacts and not smooth noise based on vec3 position.
I just play around with random plasmas added with different frequencies and get perlin-alike stuff. Haven't really tried true perlin before (isn't it just a different way to interpolate in a grid, and you can give to that whatever random texture you want). What is the advantage between true perlin and just adding frequencies which I get from plasma?
this kind of http://www.pouet.net/topic.php?which=9644 could be upgraded with such a material discussing about functions in randomness, to generate noise instead of loading a .png !!!
there are full generators, texture generators, and keeping it secret is something out of the normal mind of learnings.
there are full generators, texture generators, and keeping it secret is something out of the normal mind of learnings.
Optimus: what plasma algorithm do you use?
how do you explain that the random texture, from iq, works with 37/17 and not another texture ?
Bartoshe, I suspect there's something else going on with the PNG texture, perhaps different values packed into the RGBA color channels or something similar. I think this is going to be hard to figure out without some input from IQ. I'm really interested in how the texture is generated myself now. Hopefully he spots this thread.