Skip to content

How do I sample world space coordinate uv's in a custom material shader? #18399

Answered by speakk
speakk asked this question in Q&A
Discussion options

You must be logged in to vote

Here is the solution that seems to work quite well:

#import bevy_pbr::{
    mesh_view_bindings::globals,
    mesh_bindings::mesh,
    mesh_functions,
    forward_io::{
        Vertex,
        VertexOutput,
    },
    view_transformations::position_world_to_clip,
}

@group(2) @binding(0) var<uniform> material_color: vec4<f32>;
@group(2) @binding(1) var noise_texture_1: texture_2d<f32>;
@group(2) @binding(2) var noise_sampler_1: sampler;

@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
    var out: VertexOutput;
    var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index);
    out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, v…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by speakk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant