This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

3D noise texture

DschoonmakerDschoonmaker Posts: 216Member

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: 693
    edited May 2020 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: 693
    edited June 2020 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.

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    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: 693Moderator
    edited May 2020 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: 216Member

    @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: 693Moderator

    @Dschoonmaker That's right.

  • DschoonmakerDschoonmaker Posts: 216Member

    @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: 693Moderator

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

  • DschoonmakerDschoonmaker Posts: 216Member

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

  • SIsilicon28SIsilicon28 Posts: 693Moderator
    edited June 2020 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: 216Member
    edited June 2020

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

  • SIsilicon28SIsilicon28 Posts: 693Moderator

    Yes, and you get that via SCREEN_UV.

  • DschoonmakerDschoonmaker Posts: 216Member

    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,561Admin
    edited June 2020

    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: 693Moderator

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

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.