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

Add multiple render targets example (v2) #5313

Merged
merged 25 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ac4a804
Add the initial files of multiple render targets exmaple.
kaphula Feb 27, 2024
16970ca
Fix Present
cwfitzgerald Feb 27, 2024
a0382d7
Merge branch 'fix-presentation' into multiple_render_targets_example
kaphula Feb 27, 2024
205e22a
Add requested PR review changes.
kaphula Feb 27, 2024
ceb5e4a
Fix cargo clippy warnings.
kaphula Feb 27, 2024
7e994b0
Remove screenshot.
kaphula Feb 27, 2024
d29fa6e
Update CHANGELOG.md
kaphula Feb 27, 2024
74328eb
Add empty line to shader.
kaphula Feb 27, 2024
df5aa53
Fix resize crash by storing screen dimensions on resize.
kaphula Feb 27, 2024
4568912
Make imports to be direct.
kaphula Mar 14, 2024
edc97c0
Add cosmetic code style changes.
kaphula Mar 14, 2024
2d08936
Rename a/b to left/right.
kaphula Mar 14, 2024
359b01b
Make all imports direct.
kaphula Mar 15, 2024
9c3cf48
Merge branch 'trunk' into multiple_render_targets_example
cwfitzgerald Mar 16, 2024
a56355a
Merge branch 'refs/heads/trunk' into multiple_render_targets_example_…
kaphula May 27, 2024
1ba3592
Update to wgpu 0.20.0
kaphula May 27, 2024
63547f0
Merge branch 'trunk' into multiple_render_targets_example
cwfitzgerald Dec 17, 2024
fbc49b0
Compile Errors + Screenshots
cwfitzgerald Dec 17, 2024
c9f3fe9
Adjust Bound
cwfitzgerald Dec 17, 2024
7cd60a5
Add more consistent names for color targets.
kaphula Dec 18, 2024
e9bf491
Simplify fragment state target initialization.
kaphula Dec 18, 2024
cb7d2e2
Fix CI
cwfitzgerald Dec 18, 2024
5839ac9
Fix CI Better
cwfitzgerald Dec 18, 2024
1f681d1
Fix changelog for next release.
kaphula Dec 18, 2024
023e56f
Merge remote-tracking branch 'origin_kaphula/multiple_render_targets_…
kaphula Dec 18, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]

- Fix crash when a texture argument is missing. By @aedm in [#6486](https://github.com/gfx-rs/wgpu/pull/6486)
- Emit an error in constant evaluation, rather than crash, in certain cases where `vecN` constructors have less than N arguments. By @ErichDonGubler in [#6508](https://github.com/gfx-rs/wgpu/pull/6508).

### Examples

- Add multiple render targets example. By @kaphula in [#5297](https://github.com/gfx-rs/wgpu/pull/5313)


### Testing

Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The rest of the examples are for demonstrating specific features that you can co
- `bunnymark` - Demonstrates many things, but chief among them is performing numerous draw calls with different bind groups in one render pass. The example also uses textures for the icon and uniform buffers to transfer both global and per-particle states.
- `skybox` - Shows off too many concepts to list here. The name comes from game development where a "skybox" acts as a background for rendering, usually to add a sky texture for immersion, although they can also be used for backdrops to give the idea of a world beyond the game scene. This example does so much more than this, though, as it uses a car model loaded from a file and uses the user's mouse to rotate the car model in 3d. `skybox` also makes use of depth textures and similar app patterns to `uniform_values`.
- `shadow` - Likely by far the most complex example (certainly the largest in lines of code) of the official WGPU examples. `shadow` demonstrates basic scene rendering with the main attraction being lighting and shadows (as the name implies). It is recommended that any user looking into lighting be very familiar with the basic concepts of not only rendering with WGPU but also the primary mathematical ideas of computer graphics.
- `multiple-render-targets` - Demonstrates how to render to two texture targets simultaneously from fragment shader.
- `render_to_texture` - Renders to an image texture offscreen, demonstrating both off-screen rendering as well as how to add a sort of resolution-agnostic screenshot feature to an engine. This example either outputs an image file of your naming (pass command line arguments after specifying a `--` like `cargo run --bin wgpu-examples -- render_to_texture "test.png"`) or adds an `img` element containing the image to the page in WASM.
- `ray_cube_fragment` - Demonstrates using ray queries with a fragment shader.
- `ray_scene` - Demonstrates using ray queries and model loading
Expand Down
1 change: 1 addition & 0 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod hello_windows;
pub mod hello_workgroups;
pub mod mipmap;
pub mod msaa_line;
pub mod multiple_render_targets;
pub mod ray_cube_compute;
pub mod ray_cube_fragment;
pub mod ray_scene;
Expand Down
6 changes: 6 additions & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ const EXAMPLES: &[ExampleDesc] = &[
webgl: true,
webgpu: true,
},
ExampleDesc {
name: "multiple_render_targets",
function: wgpu_examples::multiple_render_targets::main,
webgl: false,
webgpu: true,
},
ExampleDesc {
name: "render_to_texture",
function: wgpu_examples::render_to_texture::main,
Expand Down
21 changes: 21 additions & 0 deletions examples/src/multiple_render_targets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# multiple_render_targets

This example demonstrates how to use fragment shader to output to two color attachments of a renderpass simultaneously.

The program generates a black and white ball-shaped texture from scratch and uses the fragment shader to draw it to two
separate texture targets. The first texture target receives a red version of the texture and the second target receives
a green version.

Once the colored shapes have been drawn to two separate textures, they
will be displayed on the screen by rendering each one of them to their own viewports that split the screen in half.


## To Run

```
cargo run --bin wgpu-examples multiple_render_targets
```

## Screenshots

![Multi render target](./screenshot.png)
Copy link
Member

Choose a reason for hiding this comment

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

Did you run the tests locally with cargo xtask test? The screenshot was never generated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The screenshot gets generated just fine for me, although bunch of tests fail on my machine overall. Do you want the generated screenshot to be part of the repository?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah - the fact that the screenshot is generated is how we ensure the screenshot stays up to date with the example

Loading
Loading