#Shader imports

5 messages · Page 1 of 1 (latest)

open ice
#

rust:

#[derive(AsBindGroup, TypePath, TypeUuid, Clone)]
#[uuid = "bb1f08eb-a0fb-43f1-a918-54871ea597d5"]
pub struct CombineOutputFx {

    #[texture(0)]
    #[sampler(1)]
    pub source_image: Handle<Image>,

    #[texture(2)]
    #[sampler(3)]
    pub source_image2: Handle<Image>,
}

impl Default for CombineOutputFx {
    fn default() -> Self {
        Self { source_image: Default::default(), source_image2: Default::default() }
    }
}

impl Material2d for CombineOutputFx {
    fn fragment_shader() -> ShaderRef {
        "shaders/combine_output.wgsl".into()
    }
}

wgsl code:

#import bevy_sprite::mesh2d_view_bindings
#import bevy_pbr::utils

@group(1) @binding(0)
var text0: texture_2d<f32>;

@group(1) @binding(1)
var s0: sampler;

@group(1) @binding(2)
var text1: texture_2d<f32>;

@group(1) @binding(3)
var s1: sampler;


const OFFSET: f32 = 2.20;
const OFF:    f32 = 0.03;

@fragment
fn fragment(
    @builtin(position) pos: vec4<f32>,
    #import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
    // Get screen position with coordinates from 0 to 1
    let out0 = vec3<f32>(textureSample(text0, s0, coords_to_viewport_uv(pos.xy + vec2(0.0,0.0) * OFFSET, view.viewport)).rgb);
    let out1 = vec3<f32>(textureSample(text1, s1, coords_to_viewport_uv(pos.xy + vec2(0.0,0.0) * OFFSET, view.viewport)).rgb);
    let output = vec4(1.0, 1.0, 1,0, 1.0);

    return output;
}
#

error:

#
   ┌─ shaders/combine_output.wgsl:26:51
   │
26 │     let out0 = vec3<f32>(textureSample(text0, s0, coords_to_viewport_uv(pos.xy + vec2(0.0,0.0) * OFFSET, view.viewport)).rgb);
   │                                                   ^^^^^^^^^^^^^^^^^^^^^ unknown identifier
   │
   = no definition in scope for identifier: 'coords_to_viewport_uv'
#

I also tried to simply use a color but that didn't work out either, so I am kindly asking for help with both

#
fn fragment(
    @builtin(position) pos: vec4<f32>,
    #import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
    // Get screen position with coordinates from 0 to 1
   let output = vec4(1.0, 1.0, 1,0, 1.0);

    return output;
}```