Hi i'm currently trying to apply a 4d simplex noise to a sphere and getting unexpected non contuity. I'm wondering if 'im doing something with world position.
Thanks in advance for any help !
Material def
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
struct ShieldMaterial {
#[uniform(0)]
color: LinearRgba,
#[uniform(1)]
time: f32,
#[uniform(2)]
depletion: f32,
#[texture(3)]
#[sampler(4)]
texture_low: Option<Handle<Image>>,
}
impl Material for ShieldMaterial {
fn fragment_shader() -> ShaderRef {
SHADER_ASSET_PATH.into()
}
fn alpha_mode(&self) -> AlphaMode {
AlphaMode::Blend
}
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
_layout: &MeshVertexBufferLayoutRef,
_key: MaterialPipelineKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
descriptor.primitive.cull_mode = None;
Ok(())
}
}
sphere spawning
commands.spawn((
Mesh3d(meshes.add(Sphere::default())),
MeshMaterial3d(materials.add(ShieldMaterial {
color: LinearRgba::BLUE,
time: 0.0,
depletion: 0.5,
texture_low: Some(asset_server.load(LOW_NOISE_ASSET_PATH)),
})),
Transform::from_xyz(0.0, 0.0, 0.0),
));
glsl def, i'm using Lygia snoise4
#import bevy_pbr::forward_io::VertexOutput
@group(2) @binding(0) var<uniform> color: vec4<f32>;
@group(2) @binding(1) var<uniform> time: f32;
@group(2) @binding(2) var<uniform> depletion: f32; // 0..1
@fragment
fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> {
// 4D input for noise: world position + time
let pos4 = vec4<f32>(mesh.world_position.xyz * 5.0, time);
// Compute 3D noise vector using snoise34
let noise = snoise4(pos4);
// Apply uniform color and depletion
return vec4<f32>(noise * color.rgb, color.a) ;
}
Gif of the result