3D noise texture

DschoonmakerDschoonmaker Posts: 241Member
in 3D

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

Best Answers

  • SIsilicon28SIsilicon28 Posts: 714
    edited May 31 Accepted Answer

    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.

  • SIsilicon28SIsilicon28 Posts: 714
    edited June 1 Accepted Answer

    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 a vec4 and back in order for it to be transformed properly.

  • SIsilicon28SIsilicon28 Posts: 714
    edited July 8 Accepted Answer

    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

  • TwistedTwiglegTwistedTwigleg Posts: 2,655Admin

    It looks like it is at least possible, since there is a get_noise_3d function (documentation). I have not tried it myself though.

  • SIsilicon28SIsilicon28 Posts: 714Moderator
    edited May 31 Accepted Answer

    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.

  • DschoonmakerDschoonmaker Posts: 241Member

    @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?

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    @Dschoonmaker That's right.

  • DschoonmakerDschoonmaker Posts: 241Member

    @SIsilicon28 said: You can find the shader somewhere in the scene file here.

    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?

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    rep stands for repeat. It's how far the texture generates until it repeats itself.

  • DschoonmakerDschoonmaker Posts: 241Member

    I need to generate noise in the fragment function, how can I convert screen space VERTEX to world space?

  • SIsilicon28SIsilicon28 Posts: 714Moderator
    edited June 1 Accepted Answer

    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 a vec4 and back in order for it to be transformed properly.

  • DschoonmakerDschoonmaker Posts: 241Member
    edited June 1

    Oh, I meant view space. Is screen space 2D screen coordinates?

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    Yes, and you get that via SCREEN_UV.

  • DschoonmakerDschoonmaker Posts: 241Member

    I knew about SCREEN_UV, but I just saw FRAG_COORD and it looks like the same thing. What's the difference?

  • TwistedTwiglegTwistedTwigleg Posts: 2,655Admin
    edited June 3

    I believe that SREEN_UV is the position of the fragement on the screen itself, mapped 0->1, while FRAG_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.

  • SIsilicon28SIsilicon28 Posts: 714Moderator

    Plus, FRAG_COORD's xy range is that of the viewport's pixel size.

  • DschoonmakerDschoonmaker Posts: 241Member

    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?

  • SIsilicon28SIsilicon28 Posts: 714Moderator
    edited July 7

    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;

  • DschoonmakerDschoonmaker Posts: 241Member

    How about the opposite? How could a world space normal be converted to a screen space normal?

  • SIsilicon28SIsilicon28 Posts: 714Moderator
    edited July 8 Accepted Answer

    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.

  • DschoonmakerDschoonmaker Posts: 241Member

    Yes, I meant view space. That makes sense, thanks for your answers!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file