generated from NiklasEi/bevy_game_template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
593fe22
commit 1375eeb
Showing
11 changed files
with
295 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#import bevy_pbr::{ | ||
pbr_fragment::pbr_input_from_standard_material, | ||
pbr_functions::alpha_discard, | ||
} | ||
|
||
#ifdef PREPASS_PIPELINE | ||
#import bevy_pbr::{ | ||
prepass_io::{VertexOutput, FragmentOutput}, | ||
pbr_deferred_functions::deferred_output, | ||
} | ||
#else | ||
#import bevy_pbr::{ | ||
forward_io::{VertexOutput, FragmentOutput}, | ||
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing}, | ||
} | ||
#endif | ||
|
||
@fragment | ||
fn fragment( | ||
in: VertexOutput, | ||
@builtin(front_facing) is_front: bool, | ||
) -> FragmentOutput { | ||
// generate a PbrInput struct from the StandardMaterial bindings | ||
var pbr_input = pbr_input_from_standard_material(in, is_front); | ||
|
||
if (pbr_input.material.base_color.a < 0.5) { | ||
discard; | ||
} | ||
|
||
#ifdef PREPASS_PIPELINE | ||
// in deferred mode we can't modify anything after that, as lighting is run in a separate fullscreen shader. | ||
let out = deferred_output(in, pbr_input); | ||
#else | ||
var out: FragmentOutput; | ||
// apply lighting | ||
out.color = apply_pbr_lighting(pbr_input); | ||
|
||
// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr) | ||
// note this does not include fullscreen postprocessing effects like bloom. | ||
out.color = main_pass_post_lighting_processing(pbr_input, out.color); | ||
#endif | ||
|
||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#import bevy_pbr::{ | ||
prepass_bindings, | ||
mesh_functions, | ||
prepass_io::{Vertex, VertexOutput, FragmentOutput}, | ||
skinning, | ||
morph, | ||
mesh_view_bindings::{view, previous_view_proj}, | ||
rgb9e5::vec3_to_rgb9e5_, | ||
pbr_prepass_functions::prepass_alpha_discard, | ||
pbr_prepass_functions, | ||
pbr_bindings::material, | ||
pbr_deferred_functions, | ||
pbr_types::{ | ||
STANDARD_MATERIAL_FLAGS_UNLIT_BIT, | ||
STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT | ||
}, | ||
pbr_functions, | ||
prepass_io, | ||
pbr_types | ||
} | ||
#import bevy_render::instance_index::get_instance_index | ||
#import bevy_shader_utils::simplex_noise_3d::simplex_noise_3d | ||
|
||
@group(1) @binding(101) var base_teture: texture_2d<f32>; | ||
@group(1) @binding(102) var base_teture_sampler: sampler; | ||
|
||
|
||
|
||
// basically all of this prepass shader is just copy/pasted from | ||
// the bevy pbr prepass shader. | ||
@fragment | ||
fn fragment( | ||
in: VertexOutput, | ||
@builtin(front_facing) is_front: bool, | ||
) -> FragmentOutput { | ||
pbr_prepass_functions::prepass_alpha_discard(in); | ||
|
||
var out: FragmentOutput; | ||
|
||
#ifdef DEPTH_CLAMP_ORTHO | ||
out.frag_depth = in.clip_position_unclamped.z; | ||
#endif // DEPTH_CLAMP_ORTHO | ||
|
||
#ifdef NORMAL_PREPASS | ||
// NOTE: Unlit bit not set means == 0 is true, so the true case is if lit | ||
|
||
if (material.flags & STANDARD_MATERIAL_FLAGS_UNLIT_BIT) == 0u { | ||
let double_sided = (material.flags & STANDARD_MATERIAL_FLAGS_DOUBLE_SIDED_BIT) != 0u; | ||
|
||
let world_normal = pbr_functions::prepare_world_normal( | ||
in.world_normal, | ||
double_sided, | ||
is_front, | ||
); | ||
|
||
let normal = pbr_functions::apply_normal_mapping( | ||
material.flags, | ||
world_normal, | ||
double_sided, | ||
is_front, | ||
#ifdef VERTEX_TANGENTS | ||
#ifdef STANDARDMATERIAL_NORMAL_MAP | ||
in.world_tangent, | ||
#endif // STANDARDMATERIAL_NORMAL_MAP | ||
#endif // VERTEX_TANGENTS | ||
#ifdef VERTEX_UVS | ||
in.uv, | ||
#endif // VERTEX_UVS | ||
view.mip_bias, | ||
); | ||
|
||
out.normal = vec4(normal * 0.5 + vec3(0.5), 1.0); | ||
} else { | ||
out.normal = vec4(in.world_normal * 0.5 + vec3(0.5), 1.0); | ||
} | ||
|
||
|
||
|
||
#endif // NORMAL_PREPASS | ||
|
||
#ifdef MOTION_VECTOR_PREPASS | ||
out.motion_vector = pbr_prepass_functions::calculate_motion_vector(in.world_position, in.previous_world_position); | ||
#endif | ||
|
||
if textureSample(base_teture, base_teture_sampler, in.uv).a < 0.5 { discard; }; | ||
|
||
return out; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
//safe area description and logic | ||
//safe area description and logic | ||
|
||
use std::f32::consts::PI; | ||
|
||
use bevy::prelude::*; | ||
|
||
pub struct SafeAreaPlugin; | ||
|
||
impl Plugin for SafeAreaPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(Update, draw_safe_area); | ||
} | ||
} | ||
|
||
#[derive(Component)] | ||
pub enum SafeArea { | ||
Rect { pos: Vec2, size: Vec2 }, | ||
Ellipse { pos1: Vec2, pos2: Vec2, radius: f32 }, | ||
} | ||
|
||
fn draw_safe_area(mut gizmos: Gizmos, query: Query<&SafeArea>) { | ||
for safe_area in query.iter() { | ||
match safe_area { | ||
SafeArea::Rect { pos, size } => { | ||
gizmos.rect( | ||
Vec3::new(pos.x, 0.001, pos.y), | ||
Quat::from_euler(EulerRot::XYZ, PI / 2.0, 0.0, 0.0), | ||
*size, | ||
Color::GREEN, | ||
); | ||
} | ||
SafeArea::Ellipse { pos1, pos2, radius } => {} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//just for testing. Gizmo works very bad with AlphaMode::Blend. Its alternative shader with discard on depth step | ||
|
||
use bevy::{ | ||
pbr::{ExtendedMaterial, MaterialExtension}, | ||
prelude::*, | ||
render::render_resource::{AsBindGroup, ShaderRef}, | ||
}; | ||
|
||
pub type SpriteMaterial = ExtendedMaterial<StandardMaterial, SpriteExtension>; | ||
|
||
pub struct SpriteMaterialPlugin; | ||
|
||
impl Plugin for SpriteMaterialPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugins(MaterialPlugin::< | ||
ExtendedMaterial<StandardMaterial, SpriteExtension>, | ||
>::default()); | ||
} | ||
} | ||
|
||
#[derive(Asset, AsBindGroup, Reflect, Debug, Clone)] | ||
pub struct SpriteExtension { | ||
#[texture(101)] | ||
#[sampler(102)] | ||
pub base_teture: Option<Handle<Image>>, | ||
} | ||
|
||
impl MaterialExtension for SpriteExtension { | ||
fn fragment_shader() -> ShaderRef { | ||
"shaders/sprite.wgsl".into() | ||
} | ||
|
||
fn deferred_fragment_shader() -> ShaderRef { | ||
"shaders/sprite.wgsl".into() | ||
} | ||
|
||
fn prepass_fragment_shader() -> ShaderRef { | ||
"shaders/sprite_prepass.wgsl".into() | ||
} | ||
} |
Oops, something went wrong.