Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with 3D Perlin implementation #7

Open
ndavd opened this issue Aug 12, 2023 · 8 comments
Open

Issue with 3D Perlin implementation #7

ndavd opened this issue Aug 12, 2023 · 8 comments

Comments

@ndavd
Copy link

ndavd commented Aug 12, 2023

There seems to be an issue with the Perlin 3D implementation.
Passing the following data world_position.xyz * 5.0

  • Simplex 3D:
    image
  • Perlin 3D:
    image

It seems to have something to do with the algorithm only using the decimal part on one of the parameters, the cube has length of 1, notice how I multiplied the input by 5 and we see 5 stripes in one of the directions...

@ChristopherBiscardi
Copy link
Contributor

I spent today updating the library to bevy 0.11 (v0.5 on crates.io) and creating a new example that can generate some screenshots

Here's a collection of the images that are currently being generated. I notice issues in simplex_noise_2d and perlin_noise_3d that need to be addressed.

Thanks for the issue!

perlin-2d
perlin-3d
simplex-2d
simplex-3d
voronoise

@ChristopherBiscardi
Copy link
Contributor

Fixing the 2d simplex turned out to be easy. 3d perlin still pending

image

@ndavd
Copy link
Author

ndavd commented Aug 13, 2023

Awesome!!

@ndavd
Copy link
Author

ndavd commented Aug 13, 2023

By the way @ChristopherBiscardi how are we supposed to import the shaders if we install the library by doing cargo add ..., I wasn't able to import it.. What I have done so far was copying the specific file to my assets directory and put a comment at the beginning with the url to this library for proper crediting, but I'd prefer to just install it like a regular library.

@ChristopherBiscardi
Copy link
Contributor

@ndavd did you look at the shaders for the materials in the example application? I'll include a better README in the next release.

Here's an example using the simplex noise function, which in bevy 0.11 can now be imported by name.

#import bevy_pbr::mesh_vertex_output MeshVertexOutput

#import bevy_shader_utils::simplex_noise_3d simplex_noise_3d

struct Material {
    scale: f32
};

@group(1) @binding(0)
var<uniform> material: Material;

@fragment
fn fragment(
    mesh: MeshVertexOutput
) -> @location(0) vec4<f32> {
    let f: f32 = simplex_noise_3d(material.scale * mesh.world_position.xyz);

    let color_a = vec3(0.282, 0.51, 1.0);
    let color_b = vec3(0.725, 0.816, 0.698);
    let mixed = mix(color_a, color_b, f);
    return vec4(mixed, 1.0);
}

@ndavd
Copy link
Author

ndavd commented Aug 13, 2023

Oh amazing, I'll give it a try

@ndavd
Copy link
Author

ndavd commented Aug 14, 2023

@ChristopherBiscardi I tried what you provided but I do get this:
image

@ndavd
Copy link
Author

ndavd commented Aug 14, 2023

Update: It's working, was just missing the ShaderUtilsPlugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants