Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve shader import model #5703

Merged
merged 67 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
727a700
use naga_oil
robtfm Aug 15, 2022
bdadb44
remove a few unused shader imports
robtfm Aug 16, 2022
2813f77
add override example
robtfm Aug 19, 2022
d49bfd1
readme
robtfm Aug 19, 2022
cf36c73
add global default shader overrides
robtfm Aug 19, 2022
32d6fd6
simplify assuming single render device
robtfm Aug 23, 2022
98cdcdd
format
robtfm Aug 23, 2022
f120513
snake_case wgsl imports
robtfm Aug 23, 2022
e534bae
move builtin position into vertex structs
robtfm Aug 25, 2022
e5cbc2f
Merge branch 'main' into shader_modules
robtfm Aug 26, 2022
9e9390d
Merge branch 'main' into shader_modules
robtfm Aug 26, 2022
34f1c39
fix pbr_global_override demo
robtfm Aug 29, 2022
6aad22d
cleanup overrides, use composer struct api
robtfm Sep 2, 2022
7fcbbe4
Merge branch 'main' into shader_modules
robtfm Sep 6, 2022
5d1f044
Merge branch 'main' into shader_modules
robtfm Sep 6, 2022
0e74bb9
use crates.io
robtfm Sep 9, 2022
dc1ee82
Merge branch 'main' into shader_modules
robtfm Oct 14, 2022
74c08ad
Merge branch 'main' into shader_modules
robtfm Oct 26, 2022
ab278d0
update for wgpu/naga/naga_oil version
robtfm Oct 26, 2022
da1b71e
Merge branch 'main' into shader_modules
robtfm Nov 14, 2022
6f463b3
Merge branch 'main' into shader_modules
robtfm Nov 14, 2022
40d64a2
Merge branch 'main' into shader_modules
robtfm Nov 23, 2022
7304db3
Merge branch 'main' into shader_modules
robtfm Nov 23, 2022
cf245c5
Merge branch 'main' into shader_modules
robtfm Dec 2, 2022
a393728
repair animate_shader example
robtfm Dec 2, 2022
e165da9
module defs
robtfm Dec 3, 2022
e270ccc
Merge branch 'main' into shader_modules
robtfm Dec 8, 2022
343c1c7
naga_oil v4
robtfm Dec 8, 2022
d988d4a
use `#from` in shaders
robtfm Dec 8, 2022
3f1076a
Merge branch 'main' into shader_modules
robtfm Jan 3, 2023
ffc1371
fix new examples
robtfm Jan 3, 2023
9cf33c2
Merge branch 'main' into shader_modules
robtfm Jan 14, 2023
cc3937b
Merge branch 'main' into shader_modules
robtfm Jan 15, 2023
09f0313
cleanup load_internal_asset changes
robtfm Jan 15, 2023
7a7977c
example comments
robtfm Jan 15, 2023
4ab19b4
a != A
robtfm Jan 15, 2023
94e0add
Merge branch 'main' into shader_modules
robtfm Jan 29, 2023
e49b95b
cleanup AssetPath handling
robtfm Jan 29, 2023
8904f33
bump naga_oil v0.5
robtfm Jan 29, 2023
b76ae46
clippy
robtfm Jan 29, 2023
f5c1ac8
rename inverse_transpose_3x3
robtfm Jan 30, 2023
13de5ac
Merge branch 'main' into shader_modules
robtfm Jan 30, 2023
30b4350
Merge branch 'main' into shader_modules
robtfm Feb 8, 2023
83aba93
remove `#else if` tests
robtfm Feb 8, 2023
1c5fef3
fix pbr_global_override example
robtfm Feb 8, 2023
34ed302
remove unsafe from example
robtfm Feb 22, 2023
7e08a2d
Merge branch 'main' into shader_modules
robtfm Apr 9, 2023
2b2184f
fix merge
robtfm Apr 9, 2023
fa9935d
work work
robtfm Apr 10, 2023
1f8de78
remove patch
robtfm Apr 10, 2023
50870f2
template pages
robtfm Apr 10, 2023
a386f7e
review comments
robtfm Apr 10, 2023
b1bc7be
Merge branch 'main' into shader_modules
robtfm Apr 29, 2023
d7e5f8b
undecorate items
robtfm Apr 29, 2023
647517b
point to git branch
robtfm Apr 29, 2023
ea4c92e
fmt
robtfm Apr 29, 2023
ca40e07
fix load_internal_binary_asset
robtfm Apr 30, 2023
94d47eb
Merge remote-tracking branch 'upstream/main' into shader_modules
robtfm Jun 18, 2023
8304580
Merge remote-tracking branch 'upstream/main' into shader_modules
robtfm Jun 18, 2023
27f2ee4
fmt
robtfm Jun 18, 2023
689a7ce
update naga_oil url to bevyengine
robtfm Jun 22, 2023
44340e5
Merge remote-tracking branch 'upstream/main' into shader_modules
robtfm Jun 22, 2023
8326c7a
Merge remote-tracking branch 'upstream/main' into shader_modules
robtfm Jun 24, 2023
6a72438
switch to crates.io
robtfm Jun 26, 2023
d2084bf
fix vertex_tangents accessors
robtfm Jun 26, 2023
3b5598d
MeshVertexOutput.clip_position -> .position
robtfm Jun 26, 2023
d373df4
fix more examples
robtfm Jun 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions assets/shaders/animate_shader.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import bevy_pbr::mesh_types
// The time since startup data is in the globals binding which is part of the mesh_view_bindings import
#import bevy_pbr::mesh_view_bindings
#from bevy_pbr::mesh_view_bindings import globals
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason we can't use this syntax?

#import bevy_pbr::mesh_vertex_output::MeshVertexOutput
#import bevy_pbr::mesh_vertex_output::{MeshVertexOutput, some_other_thing}
#import bevy_pbr::mesh_vertex_output::*`

This is another "non-standard" (or at least, less common) thing that will rub some people the wrong way. We already must have knowledge of "live" module names to resolve imports, so we can decide if something is a module name or a symbol inside of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#import bevy_pbr::mesh_vertex_output::{MeshVertexOutput, some_other_thing}

this is doable. it would mean braces can't be used in module names, but that's fine.

#import bevy_pbr::mesh_vertex_output::MeshVertexOutput
#import bevy_pbr::mesh_vertex_output::*

not sure about these. we use the imported module names to work out what modules need to be loaded (and to trigger loading them, for path imports). it would break confusingly if modules get loaded out of order (which can definitely happen with async io), or if you misname an imported item and it tells you the module can't be found.

Copy link
Contributor

@IceSentry IceSentry Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what's different about #import foo::Bar that makes it more complicated than #import foo::{Bar, Baz}

Also, couldn't the * just be syntax sugar that expands to the syntax with {Bar, Baz}?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would break confusingly if modules get loaded out of order (which can definitely happen with async io),

This is a good point (and feels like its touching on the core issue).

How do we determine if #import bevy_pbr::mesh_vertex_output doesn't exist, or is just still loading?. Currently iirc we rely on assets.set_untracked being called ahead of a given load? Am I right in thinking that module names don't work at all (or at least, not reliably) for server_loaded_shader_asset_file -> server_loaded_shader_asset_file deps? (both on main and in this pr?).

If so thats a hole that needs filling. This is especially important because we almost certainly want to be able to pre-process shaders at development time (in the short term producing final WGSL, in the long term ideally producing per-platform compiled shaders). This implies resolving these dependencies using the asset system instead of at runtime. I think the new asset system would be able to handle this with "processed ids" (ex: this is how I plan to support UUIDs and other "stable" ids).

However the asset system won't have access to a "global shader identity cache" and it couldn't just listen for things to show up there. It would just be able to wait for a given stable id (such as bevy_pbr::mesh_vertex_output) to be resolved (or fail to resolve after all assets have been processed). So that does probably leave us with the need for an unambiguous syntax in this case. We could probably make stable id lookups fallible, but it would mean that shaders with #import bevy_pbr::mesh_vertex_output::foo (where foo is a function name) would always be processed "last" and they would be blocking constantly on other work finishing ... not ideal.

So I guess that does probably leave us in the unfortunate situation where module imports must be unambiguous with other symbol imports (unless anyone else has ideas).

In that case, I think my current preferred syntax is in the vein of:

// Option A
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import bevy_pbr::mesh_vertex_output MeshVertexOutput, some_other_thing
#import bevy_pbr::mesh_vertex_output *

// Option B
#import bevy_pbr:mesh_vertex_output::MeshVertexOutput
#import bevy_pbr:mesh_vertex_output::{MeshVertexOutput, some_other_thing}
#import bevy_pbr:mesh_vertex_output::*

// Option C
#import bevy_pbr/mesh_vertex_output::MeshVertexOutput
#import bevy_pbr/mesh_vertex_output::MeshVertexOutput, some_other_thing}
#import bevy_pbr/mesh_vertex_output::*

Not sure how I feel about Option C. It has the interesting (and likely controversial) property of having rough parity with asset paths (with file extensions resolving the ambiguity)

#import some/path/file.wgsl::MeshVertexOutput

(pretty sure that parity creates confusion but im still sorting out my feelings)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Option A has my preference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer these over from variants because those lack symmetry with other imports. I like that everything reads as #import operations followed by paths, rather than some being "import" operations (#import PATH) and others being "from" operations (#from PATH import THINGS).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned it a few months ago, but I think we could also consider using #use instead of #import to mirror rust a bit more closely. There's the downside that people might assume it's exactly like rust of course, but I think it's worth considering.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah im pretty ok with use (rust parallels generally). use reads nicely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in thinking that module names don't work at all (or at least, not reliably) for server_loaded_shader_asset_file -> server_loaded_shader_asset_file deps? (both on main and in this pr?)

for manually server-loaded shaders, it works fine in both main and in this pr. in both cases we preprocess the shader to extract the dependencies and wait for them to be loaded ... but this requires that we can identify dependencies without context (and disambiguate them from item imports).

i'm not sure if AssetPath (i.e. #import "module.wgsl") shader deps get auto-loaded on main, but they do in this pr.

// Option A
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import bevy_pbr::mesh_vertex_output MeshVertexOutput, some_other_thing
#import bevy_pbr::mesh_vertex_output *

i'll give this a go


fn oklab_to_linear_srgb(c: vec3<f32>) -> vec3<f32> {
let L = c.x;
Expand All @@ -22,17 +22,13 @@ fn oklab_to_linear_srgb(c: vec3<f32>) -> vec3<f32> {
);
}

struct FragmentInput {
#import bevy_pbr::mesh_vertex_output
}

@fragment
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
fn fragment(in: ::MeshVertexOutput) -> @location(0) vec4<f32> {
let speed = 2.0;
// The globals binding contains various global values like time
// which is the time since startup in seconds
let t_1 = sin(globals.time * speed) * 0.5 + 0.5;
let t_2 = cos(globals.time * speed);
let t_1 = sin(::globals.time * speed) * 0.5 + 0.5;
let t_2 = cos(::globals.time * speed);

let distance_to_center = distance(in.uv, vec2<f32>(0.5)) * 1.4;

Expand Down
61 changes: 26 additions & 35 deletions assets/shaders/array_texture.wgsl
Original file line number Diff line number Diff line change
@@ -1,60 +1,51 @@
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::mesh_bindings

#import bevy_pbr::pbr_types
#import bevy_pbr::utils
#import bevy_pbr::clustered_forward
#import bevy_pbr::lighting
#import bevy_pbr::shadows
#import bevy_pbr::fog
#import bevy_pbr::pbr_functions
#import bevy_pbr::pbr_ambient
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput
#from bevy_pbr::mesh_view_bindings import view
#from bevy_pbr::pbr_types import STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT
#import bevy_pbr::pbr_functions as fns
#from bevy_core_pipeline::tonemapping import tone_mapping

@group(1) @binding(0)
var my_array_texture: texture_2d_array<f32>;
@group(1) @binding(1)
var my_array_texture_sampler: sampler;

struct FragmentInput {
@builtin(front_facing) is_front: bool,
@builtin(position) frag_coord: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
};

@fragment
fn fragment(in: FragmentInput) -> @location(0) vec4<f32> {
let layer = i32(in.world_position.x) & 0x3;
fn fragment(
@builtin(front_facing) is_front: bool,
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
let layer = i32(mesh.world_position.x) & 0x3;

// Prepare a 'processed' StandardMaterial by sampling all textures to resolve
// the material members
var pbr_input: PbrInput = pbr_input_new();
var pbr_input: fns::PbrInput = fns::pbr_input_new();

pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, in.uv, layer);
pbr_input.material.base_color = textureSample(my_array_texture, my_array_texture_sampler, mesh.uv, layer);
#ifdef VERTEX_COLORS
pbr_input.material.base_color = pbr_input.material.base_color * in.color;
pbr_input.material.base_color = pbr_input.material.base_color * mesh.color;
#endif

pbr_input.frag_coord = in.frag_coord;
pbr_input.world_position = in.world_position;
pbr_input.world_normal = prepare_world_normal(
in.world_normal,
(pbr_input.material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u,
in.is_front,
pbr_input.frag_coord = mesh.clip_position;
pbr_input.world_position = mesh.world_position;
pbr_input.world_normal = fns::prepare_world_normal(
mesh.world_normal,
(pbr_input.material.flags & ::STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u,
is_front,
);

pbr_input.is_orthographic = view.projection[3].w == 1.0;
pbr_input.is_orthographic = ::view.projection[3].w == 1.0;

pbr_input.N = apply_normal_mapping(
pbr_input.N = fns::apply_normal_mapping(
pbr_input.material.flags,
pbr_input.world_normal,
mesh.world_normal,
#ifdef VERTEX_TANGENTS
#ifdef STANDARDMATERIAL_NORMAL_MAP
in.world_tangent,
mesh.world_tangent,
#endif
#endif
in.uv,
mesh.uv,
);
pbr_input.V = calculate_view(in.world_position, pbr_input.is_orthographic);
pbr_input.V = fns::calculate_view(mesh.world_position, pbr_input.is_orthographic);

return tone_mapping(pbr(pbr_input));
return ::tone_mapping(fns::pbr(pbr_input), ::view.color_grading);
}
6 changes: 3 additions & 3 deletions assets/shaders/cubemap_unlit.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import bevy_pbr::mesh_view_bindings
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput

#ifdef CUBEMAP_ARRAY
@group(1) @binding(0)
Expand All @@ -13,9 +13,9 @@ var base_color_sampler: sampler;

@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
let fragment_position_view_lh = world_position.xyz * vec3<f32>(1.0, 1.0, -1.0);
let fragment_position_view_lh = mesh.world_position.xyz * vec3<f32>(1.0, 1.0, -1.0);
return textureSample(
base_color_texture,
base_color_sampler,
Expand Down
4 changes: 4 additions & 0 deletions assets/shaders/custom_material.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ layout(set = 1, binding = 0) uniform CustomMaterial {
layout(set = 1, binding = 1) uniform texture2D CustomMaterial_texture;
layout(set = 1, binding = 2) uniform sampler CustomMaterial_sampler;

// wgsl modules can be imported and used in glsl
// FIXME - this doesn't work any more ...
// #import bevy_pbr::pbr_functions as PbrFuncs

void main() {
// o_Target = PbrFuncs::tone_mapping(Color * texture(sampler2D(CustomMaterial_texture,CustomMaterial_sampler), v_Uv));
o_Target = Color * texture(sampler2D(CustomMaterial_texture,CustomMaterial_sampler), v_Uv);
}
6 changes: 4 additions & 2 deletions assets/shaders/custom_material.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput

struct CustomMaterial {
color: vec4<f32>,
};
Expand All @@ -11,7 +13,7 @@ var base_color_sampler: sampler;

@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
return material.color * textureSample(base_color_texture, base_color_sampler, uv);
return material.color * textureSample(base_color_texture, base_color_sampler, mesh.uv);
}
10 changes: 5 additions & 5 deletions assets/shaders/custom_material_chromatic_aberration.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import bevy_sprite::mesh2d_view_bindings
#import bevy_pbr::utils
#from bevy_pbr::mesh_view_bindings import view
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput
#from bevy_pbr::utils import coords_to_viewport_uv

@group(1) @binding(0)
var texture: texture_2d<f32>;
Expand All @@ -9,11 +10,10 @@ var our_sampler: sampler;

@fragment
fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_sprite::mesh2d_vertex_output
mesh: ::MeshVertexOutput
) -> @location(0) vec4<f32> {
// Get screen position with coordinates from 0 to 1
let uv = coords_to_viewport_uv(position.xy, view.viewport);
let uv = ::coords_to_viewport_uv(mesh.clip_position.xy, ::view.viewport);
let offset_strength = 0.02;

// Sample each color channel with an arbitrary shift
Expand Down
11 changes: 6 additions & 5 deletions assets/shaders/custom_material_screenspace_texture.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::utils
#from bevy_pbr::mesh_view_bindings import view
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput
#from bevy_pbr::utils import coords_to_viewport_uv

@group(1) @binding(0)
var texture: texture_2d<f32>;
Expand All @@ -8,10 +9,10 @@ var texture_sampler: sampler;

@fragment
fn fragment(
@builtin(position) position: vec4<f32>,
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
let uv = coords_to_viewport_uv(position.xy, view.viewport);
let view = ::view;
let uv = ::coords_to_viewport_uv(mesh.clip_position.xy, view.viewport);
let color = textureSample(texture, texture_sampler, uv);
return color;
}
12 changes: 6 additions & 6 deletions assets/shaders/custom_vertex_attribute.wgsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#import bevy_pbr::mesh_view_bindings
#import bevy_pbr::mesh_bindings
#from bevy_pbr::mesh_bindings import mesh
#from bevy_pbr::mesh_functions import mesh_position_local_to_clip

struct CustomMaterial {
color: vec4<f32>,
};
@group(1) @binding(0)
var<uniform> material: CustomMaterial;

// NOTE: Bindings must come before functions that use them!
#import bevy_pbr::mesh_functions

struct Vertex {
@location(0) position: vec3<f32>,
@location(1) blend_color: vec4<f32>,
Expand All @@ -23,7 +20,10 @@ struct VertexOutput {
@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
out.clip_position = mesh_position_local_to_clip(mesh.model, vec4<f32>(vertex.position, 1.0));
out.clip_position = ::mesh_position_local_to_clip(
::mesh.model,
vec4<f32>(vertex.position, 1.0)
);
out.blend_color = vertex.blend_color;
return out;
}
Expand Down
15 changes: 6 additions & 9 deletions assets/shaders/instancing.wgsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#import bevy_pbr::mesh_types
#import bevy_pbr::mesh_view_bindings

@group(1) @binding(0)
var<uniform> mesh: Mesh;

// NOTE: Bindings must come before functions that use them!
#import bevy_pbr::mesh_functions
#from bevy_pbr::mesh_functions import mesh_position_local_to_clip
#from bevy_pbr::mesh_bindings import mesh

struct Vertex {
@location(0) position: vec3<f32>,
Expand All @@ -25,7 +19,10 @@ struct VertexOutput {
fn vertex(vertex: Vertex) -> VertexOutput {
let position = vertex.position * vertex.i_pos_scale.w + vertex.i_pos_scale.xyz;
var out: VertexOutput;
out.clip_position = mesh_position_local_to_clip(mesh.model, vec4<f32>(position, 1.0));
out.clip_position = ::mesh_position_local_to_clip(
::mesh.model,
vec4<f32>(position, 1.0)
);
out.color = vertex.i_color;
return out;
}
Expand Down
4 changes: 3 additions & 1 deletion assets/shaders/line_material.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput

struct LineMaterial {
color: vec4<f32>,
};
Expand All @@ -7,7 +9,7 @@ var<uniform> material: LineMaterial;

@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
return material.color;
}
4 changes: 2 additions & 2 deletions assets/shaders/post_process_pass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// As you can see, the triangle ends up bigger than the screen.
//
// You don't need to worry about this too much since bevy will compute the correct UVs for you.
#import bevy_core_pipeline::fullscreen_vertex_shader
#from bevy_core_pipeline::fullscreen_vertex_shader import FullscreenVertexOutput

@group(0) @binding(0)
var screen_texture: texture_2d<f32>;
Expand All @@ -33,7 +33,7 @@ struct PostProcessSettings {
var<uniform> settings: PostProcessSettings;

@fragment
fn fragment(in: FullscreenVertexOutput) -> @location(0) vec4<f32> {
fn fragment(in: ::FullscreenVertexOutput) -> @location(0) vec4<f32> {
// Chromatic aberration strength
let offset_strength = settings.intensity;

Expand Down
4 changes: 3 additions & 1 deletion assets/shaders/shader_defs.wgsl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput

struct CustomMaterial {
color: vec4<f32>,
};
Expand All @@ -7,7 +9,7 @@ var<uniform> material: CustomMaterial;

@fragment
fn fragment(
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
#ifdef IS_RED
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
Expand Down
14 changes: 7 additions & 7 deletions assets/shaders/show_prepass.wgsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import bevy_pbr::mesh_types
#import bevy_pbr::mesh_view_bindings
#from bevy_pbr::mesh_view_bindings import globals
#import bevy_pbr::prepass_utils
#from bevy_pbr::mesh_vertex_output import MeshVertexOutput

struct ShowPrepassSettings {
show_depth: u32,
Expand All @@ -14,19 +15,18 @@ var<uniform> settings: ShowPrepassSettings;

@fragment
fn fragment(
@builtin(position) frag_coord: vec4<f32>,
@builtin(sample_index) sample_index: u32,
#import bevy_pbr::mesh_vertex_output
mesh: ::MeshVertexOutput,
) -> @location(0) vec4<f32> {
if settings.show_depth == 1u {
let depth = prepass_depth(frag_coord, sample_index);
let depth = bevy_pbr::prepass_utils::prepass_depth(mesh.clip_position, sample_index);
return vec4(depth, depth, depth, 1.0);
} else if settings.show_normals == 1u {
let normal = prepass_normal(frag_coord, sample_index);
let normal = bevy_pbr::prepass_utils::prepass_normal(mesh.clip_position, sample_index);
return vec4(normal, 1.0);
} else if settings.show_motion_vectors == 1u {
let motion_vector = prepass_motion_vector(frag_coord, sample_index);
return vec4(motion_vector / globals.delta_time, 0.0, 1.0);
let motion_vector = bevy_pbr::prepass_utils::prepass_motion_vector(mesh.clip_position, sample_index);
return vec4(motion_vector / ::globals.delta_time, 0.0, 1.0);
}

return vec4(0.0);
Expand Down
Loading