rust-adventure / bevy-examples

Shaders and other small Bevy examples
MIT License
152 stars 11 forks source link

Issue with 3D Perlin implementation #7

Open ndavd opened 1 year ago

ndavd commented 1 year ago

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

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 commented 1 year ago

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 commented 1 year ago

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

image

ndavd commented 1 year ago

Awesome!!

ndavd commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

Oh amazing, I'll give it a try

ndavd commented 1 year ago

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

ndavd commented 1 year ago

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