Skip to content

Commit

Permalink
remove webgl support for example
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Feb 7, 2023
1 parent 41466f5 commit 5a6643e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ path = "examples/shader/shader_prepass.rs"
name = "Material Prepass"
description = "A shader that uses the various textures generated by the prepass"
category = "Shaders"
wasm = true
wasm = false


[[example]]
Expand Down
14 changes: 0 additions & 14 deletions assets/shaders/show_prepass.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,14 @@ var show_prepass_sampler: sampler;
@fragment
fn fragment(
@builtin(position) frag_coord: vec4<f32>,
#ifndef WEBGL
@builtin(sample_index) sample_index: u32,
#endif // WEBGL
#import bevy_pbr::mesh_vertex_output
) -> @location(0) vec4<f32> {
if settings.show_depth == 1u {
#ifdef WEBGL
// prepass_depth() uses textureLoad which doesn't work in WebGL for depth textures.
// Instead we need to use a sampler
let dims = textureDimensions(depth_prepass_texture);
let uv = frag_coord.xy / vec2<f32>(dims);
let depth = textureSample(depth_prepass_texture, show_prepass_sampler, uv);
#else
let depth = prepass_depth(frag_coord, sample_index);
#endif // WEBGL
return vec4(depth, depth, depth, 1.0);
} else if settings.show_normals == 1u {
#ifdef WEBGL
let normal = prepass_normal(frag_coord, 0u);
#else // WEBGL
let normal = prepass_normal(frag_coord, sample_index);
#endif // WEBGL
return vec4(normal, 1.0);
}

Expand Down
25 changes: 1 addition & 24 deletions examples/shader/shader_prepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use bevy::{

fn main() {
App::new()
// When using the prepass with WebGL, you can't use Msaa
.insert_resource(Msaa::Off)
.add_plugins(DefaultPlugins.set(PbrPlugin {
// The prepass is enabled by default on the StandardMaterial,
// but you can disable it if you need to.
Expand Down Expand Up @@ -72,8 +70,6 @@ fn setup(
mesh: meshes.add(shape::Quad::new(Vec2::new(20.0, 20.0)).into()),
material: depth_materials.add(PrepassOutputMaterial {
settings: ShowPrepassSettings::default(),
// We don't actually need a texture here, we just want bevy to give us a sampler
sampler: None,
}),
transform: Transform::from_xyz(-0.75, 1.25, 3.0)
.looking_at(Vec3::new(2.0, -2.5, -5.0), Vec3::Y),
Expand Down Expand Up @@ -200,8 +196,8 @@ fn rotate(mut q: Query<&mut Transform, With<Rotates>>, time: Res<Time>) {
struct ShowPrepassSettings {
show_depth: u32,
show_normals: u32,
is_webgl: u32,
padding_1: u32,
padding_2: u32,
}

// This shader simply loads the prepass texture and outputs it directly
Expand All @@ -210,9 +206,6 @@ struct ShowPrepassSettings {
pub struct PrepassOutputMaterial {
#[uniform(0)]
settings: ShowPrepassSettings,
// We just need a sampler here. We don't even need to load an image, but we still need to specify the type for the macro
#[sampler(1)]
sampler: Option<Handle<Image>>,
}

impl Material for PrepassOutputMaterial {
Expand All @@ -224,22 +217,6 @@ impl Material for PrepassOutputMaterial {
fn alpha_mode(&self) -> AlphaMode {
AlphaMode::Blend
}

#[cfg(target_arch = "wasm32")]
fn specialize(
_pipeline: &bevy::pbr::MaterialPipeline<Self>,
descriptor: &mut bevy::render::render_resource::RenderPipelineDescriptor,
_layout: &bevy::render::mesh::MeshVertexBufferLayout,
_key: bevy::pbr::MaterialPipelineKey<Self>,
) -> Result<(), bevy::render::render_resource::SpecializedMeshPipelineError> {
descriptor
.fragment
.as_mut()
.unwrap()
.shader_defs
.push("WEBGL".into());
Ok(())
}
}

/// Every time you press space, it will cycle between transparent, depth and normals view
Expand Down

0 comments on commit 5a6643e

Please sign in to comment.