#Weird outlines when trying to create random shader texture

13 messages · Page 1 of 1 (latest)

slow ginkgo
#

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

slow ginkgo
#

Here is an rgb view of the sphere with xyz position

#

Here is an RGB sphere of the coordinates:

waxen wave
#

I think what you are getting is a mix of front and back faces

#
  • you have face culling disabled
  • transparent objects are rendered without depth writes, so depth doesn't do anything in this scene
  • your alpha output from the fragment shader is 1.0
#

if you are going for a force-field effect you should probably start by using AlphaMode::Add which means you will see the sum of the front faces and the back faces, instead of an arbitrary one of them per pixel

slow ginkgo
#

Some eye candy for reward :

waxen wave
#

My diagnosis thought process:

  1. the result has visible triangle edges.
  2. could the mesh have wrong UVs? no, it is a standard Bevy sphere mesh.
  3. how else can we get triangle edges showing? by drawing order
slow ginkgo
slow ginkgo
slow ginkgo
#

@waxen wave Thanks again friend. I just needed those settings right!