3D noise texture
Is there a built in way to generate a 3D noise texture? If not, how could I do it in GDScript?
Best Answers

SIsilicon28 Posts: 714
You could also try using some shader magic to do it. That's what I did in my Volumetrics Plugin. It comes with a tool to create 3D noise textures almost automatically. You can find the shader somewhere in the scene file here.

SIsilicon28 Posts: 714
VERTEX
is in view space actually. It's as simple as a matrix multiplication.
vec3 world_vert = (CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz;
It has to be converted from avec3
to avec4
and back in order for it to be transformed properly. 
SIsilicon28 Posts: 714
If by screen space you mean view space, then this should work.
vec3 view_normal = (INV_CAMERA_MATRIX * vec4(world_normal, 0.0)).xyz;
To do the opposite of a transform, use the inverse of the matrix.
Answers
It looks like it is at least possible, since there is a
get_noise_3d
function (documentation). I have not tried it myself though.You could also try using some shader magic to do it. That's what I did in my Volumetrics Plugin. It comes with a tool to create 3D noise textures almost automatically. You can find the shader somewhere in the scene file here.
@TwistedTwigleg I know how to get noise, but how can I create and fill a 3D texture?
@SIsilicon28 do you mean calculating noise in a shader?
@Dschoonmaker That's right.
Oh, it's in the scene file. That's why I didn't see it before. I'll look in the .tscn file, although it's probably a good idea to save a .shader file also.
In the function float pnoise(vec3 P, float rep), what is rep?
rep
stands for repeat. It's how far the texture generates until it repeats itself.I need to generate noise in the fragment function, how can I convert screen space VERTEX to world space?
VERTEX
is in view space actually. It's as simple as a matrix multiplication.vec3 world_vert = (CAMERA_MATRIX * vec4(VERTEX, 1.0)).xyz;
It has to be converted from a
vec3
to avec4
and back in order for it to be transformed properly.Oh, I meant view space. Is screen space 2D screen coordinates?
Yes, and you get that via
SCREEN_UV
.I knew about SCREEN_UV, but I just saw FRAG_COORD and it looks like the same thing. What's the difference?
I believe that
SREEN_UV
is the position of the fragement on the screen itself, mapped0>1
, whileFRAG_CORD
is the position of the fragement in screen space.FRAG_CORD
also has a z value for depth, which can be helpful for various effects.Plus,
FRAG_COORD
's xy range is that of the viewport's pixel size.Do you know what to do to convert a world space normal to a view space normal, or vice versa? I found the multiplication you used for world space vertex didn't work. Maybe VIEW is useful here?
The formula only works on positional vectors. For vectors that represent a direction, replace the 1.0 with 0.0.
vec3 normal = (CAMERA_MATRIX * vec4(NORMAL, 0.0)).xyz;
How about the opposite? How could a world space normal be converted to a screen space normal?
If by screen space you mean view space, then this should work.
vec3 view_normal = (INV_CAMERA_MATRIX * vec4(world_normal, 0.0)).xyz;
To do the opposite of a transform, use the inverse of the matrix.
Yes, I meant view space. That makes sense, thanks for your answers!