bevyengine/naga_oil

Question? Am I doing imports/defines incorrectly or is this a bug?

Closed this issue · 2 comments

forgive the screengrab:
image

I have this error:

2023-10-05T08:32:45.075565Z ERROR bevy_render::render_resource::pipeline_cache: failed to process shader:
error: required import 'shadplay::common' not found
  ┌─ shaders/myshader_2d.wgsl:3:1
  │
3 │ #import shadplay::common
  │ ^
  │
  = missing import 'shadplay::common'

from this frag:

// myrustproject/assets/shaders/myshader.wgsl
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import shadplay::common::common

@fragment
fn fragment(in: MeshVertexOutput) -> @location(0) vec4<f32> {
    var fragColor: vec4<f32> = vec4<f32>(0.0080);
    var uv = (in.uv.xy * 2.0)- 1.0;
    var col = vec4f(0.220);

    return col;
}

and the common.wgsl is:

// myrustproject/assets/shaders/common.wgsl
#define_import_path shadplay::common

/// Clockwise by `theta`
fn rotate2D(theta: f32) -> mat2x2<f32> {
    let c = cos(theta);
    let s = sin(theta);
    return mat2x2<f32>(c, s, -s, c);
}

My paths and files are there...

#MYPROJECT DIR
├──  src/
│   ├──  lib.rs
         /* snip */
├── assets/
│   └── shaders
│       ├── common.wgsl
│       ├── myshader.wgsl
│       ├── myshader_2d.wgsl

I think i've copied everything exactly per you example, and even pulled this project to see it working -- so all my paths etc are correct, what gives?
The readme mentions Compose -- is there setup on the bevy side of my code that needs to do something to make the path discovery work?

robtfm commented

if you want to import from the assets folder in bevy you need to

  • remove the #define_import_path declaration from your common module
  • import it using asset-path syntax: #import "shaders/common.wgsl"

alternatively you can use the load_internal_asset macro in your rust code to load the common module (normally from somewhere in your /src directory), then import it as you have above. this approach is more normal for crates that need to embed shaders.

if you want to import from the assets folder in bevy you need to

* remove the `#define_import_path` declaration from your common module

* import it using asset-path syntax: `#import "shaders/common.wgsl"`

alternatively you can use the load_internal_asset macro in your rust code to load the common module (normally from somewhere in your /src directory), then import it as you have above. this approach is more normal for crates that need to embed shaders.

Right - so the #define... syntax only works when my xyz.wgsl etc are in some child directory of the src ?