Skip to content

Commit

Permalink
Add example to README, switch to 2D camera
Browse files Browse the repository at this point in the history
  • Loading branch information
wilk10 committed Apr 3, 2021
1 parent 16bd860 commit 53fe08f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ Example | File | Description

Example | File | Description
--- | --- | ---
`animate_shader` | [`shader/animate_shader.rs`](./shader/animate_shader.rs) | Shows how to animate a shader by accessing a time uniform variable
`array_texture` | [`shader/array_texture.rs`](./shader/array_texture.rs) | Illustrates how to create a texture for use with a texture2DArray shader uniform variable
`hot_shader_reloading` | [`shader/hot_shader_reloading.rs`](./shader/hot_shader_reloading.rs) | Illustrates how to load shaders such that they can be edited while the example is still running
`mesh_custom_attribute` | [`shader/mesh_custom_attribute.rs`](./shader/mesh_custom_attribute.rs) | Illustrates how to add a custom attribute to a mesh and use it in a custom shader
Expand Down
21 changes: 9 additions & 12 deletions examples/shader/animate_shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bevy::{
};

/// This example shows how to animate a shader, by passing the global `time.seconds_since_startup()`
/// via a 'TimeComponent` to the shader
/// via a 'TimeComponent` to the shader.
pub fn main() {
App::build()
.add_plugins(DefaultPlugins)
Expand Down Expand Up @@ -78,30 +78,30 @@ fn setup(
mut meshes: ResMut<Assets<Mesh>>,
mut render_graph: ResMut<RenderGraph>,
) {
// Create a new shader pipeline
// Create a new shader pipeline.
let pipeline_handle = pipelines.add(PipelineDescriptor::default_config(ShaderStages {
vertex: shaders.add(Shader::from_glsl(ShaderStage::Vertex, VERTEX_SHADER)),
fragment: Some(shaders.add(Shader::from_glsl(ShaderStage::Fragment, FRAGMENT_SHADER))),
}));

// Add a `RenderResourcesNode` to our `RenderGraph`. This will bind `TimeComponent` to our shader
// Add a `RenderResourcesNode` to our `RenderGraph`. This will bind `TimeComponent` to our shader.
render_graph.add_system_node(
"time_component",
RenderResourcesNode::<TimeComponent>::new(true),
);

// Add a `RenderGraph` edge connecting our new "time_component" node to the main pass node. This
// ensures that "time_component" runs before the main pass
// ensures that "time_component" runs before the main pass.
render_graph
.add_node_edge("time_component", base::node::MAIN_PASS)
.unwrap();

// Spawn a quad and insert the `TimeComponent`
// Spawn a quad and insert the `TimeComponent`.
commands
.spawn_bundle(MeshBundle {
mesh: meshes.add(Mesh::from(shape::Quad {
size: Vec2::new(5.0, 5.0),
flip: true,
size: Vec2::new(400.0, 400.0),
flip: false,
})),
render_pipelines: RenderPipelines::from_pipelines(vec![RenderPipeline::new(
pipeline_handle,
Expand All @@ -111,11 +111,8 @@ fn setup(
})
.insert(TimeComponent { value: 0.0 });

// Spawn a camera
commands.spawn_bundle(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 0.0, -8.0).looking_at(Vec3::ZERO, -Vec3::Y),
..Default::default()
});
// Spawn a camera.
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
}

/// In this system we query for the `TimeComponent` and global `Time` resource, and set `time.seconds_since_startup()`
Expand Down

0 comments on commit 53fe08f

Please sign in to comment.