pouët.net

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...
added on the 2013-10-23 18:28:56 by Bartoshe Bartoshe
Well, if you're reading a texture, it'd be
Code:texture(texname, uv);
(or texture2D, not quite sure about OpenGL ES). Or do you want to load the texture from somewhere and send it to the shader?

The most used shader random is along the lines of
Code:float rnd = fract(bigseed*sin(smallerseed*x));
With carefully selected seed values it produces quite okay random numbers for gfx purposes at least.
added on the 2013-10-23 18:36:24 by msqrt msqrt
Perlin and simplex by Stefan Gustavson

http://www.davidcornette.com/glsl/GLSL-noise.zip
added on the 2013-10-23 18:37:59 by visy visy
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.
added on the 2013-10-23 19:39:52 by Bartoshe Bartoshe
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 ?
added on the 2013-10-23 20:05:25 by Bartoshe Bartoshe
Bartoshe, do you mean the code to generate the noise texture from ShaderToy or the texture image itself?
added on the 2013-10-23 20:18:58 by raizor raizor
If you're just after the textures:

RBGA 256x256
RBGA 64x64
R 256x256
R 64x64
added on the 2013-10-23 20:26:06 by raizor raizor
yes, thanx, but why if I generate one with rand()&255 , it simply do weird stuffs ?
added on the 2013-10-23 21:18:06 by Bartoshe Bartoshe
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 !
added on the 2013-10-23 21:31:22 by Bartoshe Bartoshe
I'm not sure how that noise texture is generated Bartoshe, hopefully iq will spot this thread and provide the answer.
added on the 2013-10-23 22:06:32 by raizor raizor
If you're on Facebook, you could maybe ask here.
added on the 2013-10-23 22:07:22 by raizor raizor
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):

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.
added on the 2013-10-23 23:21:47 by raizor raizor
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..)
added on the 2013-10-23 23:24:53 by psonice psonice
Quote:
you're making the first 8 bits all 1


Eh, no, that is not how a bitwise AND works.
added on the 2013-10-23 23:29:50 by Rob Rob
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.
added on the 2013-10-23 23:48:57 by psonice psonice
It would not matter, assuming every bit is random. He just wants a random number between 0 and 255.
added on the 2013-10-23 23:51:06 by Rob Rob
And I think he is talking about generating a noise texture map. As you do that only once performance is not really an issue.
added on the 2013-10-23 23:56:50 by Rob Rob
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 !
added on the 2013-10-24 05:58:05 by Bartoshe Bartoshe
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...
added on the 2013-10-24 08:18:29 by TLM TLM
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.
added on the 2013-10-24 10:01:32 by Bartoshe Bartoshe
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?
added on the 2013-10-24 10:32:45 by Optimus Optimus
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.
added on the 2013-10-24 12:09:19 by Bartoshe Bartoshe
Optimus: what plasma algorithm do you use?
added on the 2013-10-24 14:36:24 by TLM TLM
how do you explain that the random texture, from iq, works with 37/17 and not another texture ?
added on the 2013-10-24 14:54:23 by Bartoshe Bartoshe
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.
added on the 2013-10-24 15:19:00 by raizor raizor

login