Skip to content

Instantly share code, notes, and snippets.

@pcwalton
pcwalton / invert-culling-fix.diff
Created October 19, 2026 05:00
invert-culling-fix.diff
commit a4d688a833fd36dd7cab7cf694b1cebf46f63a91
Author: Patrick Walton <pcwalton@mimiga.net>
Date: Sun Oct 18 21:47:25 2026 -0700
Switch which face is front and which is back when `INVERT_CULLING` is
present in order to fix flipped normals in mirrors.
Currently, the `INVERT_CULLING` flag intended for use in mirrors flips
the cull mode only. This ensures that the models don't render inside
out. However, this isn't enough, because we have to flip the normals as
@pcwalton
pcwalton / transparent-gradients.diff
Created October 17, 2026 22:59
transparent-gradients.diff
commit c45ad12159256c565d1c31c15b2ea4247c3a5dc5
Author: Patrick Walton <pcwalton@mimiga.net>
Date: Sat Oct 17 15:37:35 2026 -0700
Premultiply colors with alpha when interpolating UI gradients according
to the CSS-COLOR-4 spec.
Gradients involving colors that fade to transparent are currently
unsightly in Bevy UI, resulting in a gradient that becomes darker as it
becomes transparent, because the gradient shader doesn't premultiply the
@pcwalton
pcwalton / UnityFreeformStretching.md
Last active October 31, 2025 04:48
Unity Freeform Stretching

Unity Freeform Stretching

Revision 2

This note explains how the freeform stretching and rotate with stretch features in Unity's Shuriken ("Legacy") particle system work. It may be useful for those who want to duplicate the effect on the GPU, via Unity's VFX Graph or otherwise. These formulas were obtained through experimentation and, while they seem algebraically equivalent to what Shuriken does, are not the exact operations that Unity uses.

Vector projection of $V$ onto $U$ is notated as $\mathrm{proj}_U(V) = U\frac{V \cdot U}{U \cdot U}$. The magnitude of a vector $V$ is denoted with $||V|| = \sqrt{V \cdot V}$. A normalized vector is notated with $\hat V = \frac{V}{||V||}$.

All these operations are in particle space. That is, we assume that the particle is centered at the origin $(0, 0, 0)$, with its normal facing the +Z directi

@pcwalton
pcwalton / BevyGPUDrivenReleaseNotes.md
Created April 10, 2025 04:10
Bevy GPU-driven release notes

GPU-Driven Rendering

Over the years, the trend in real-time rendering has increasingly been to move work from the CPU to the GPU. One of the latest developments in this area has been GPU-driven rendering, in which the GPU takes a representation of the scene and essentially works out what to draw on its own. While Bevy 0.15 had some support for GPU-driven rendering for meshlets only, Bevy 0.16 features comprehensive support for this technique, including for skinned meshes. This dramatically reduces the amount of CPU time that the renderer needs for larger scenes. It's automatically enabled on platforms that support it; unless your application hooks into the rendering pipeline, upgrading to Bevy 0.16 will automatically enable GPU-driven rendering for your meshes.

To explain how GPU-driven rendering operates, it's easiest to first describe how CPU-driven rendering works:

  1. The CPU determines the objects that are visible, via frustum culling and perhaps occlusion culling.

  2. For each such object:

@pcwalton
pcwalton / BevyFeatures.md
Created January 16, 2025 18:26
Bevy rendering features

Bevy Features

  • wgpu-based renderer
    • Direct3D 12
    • Vulkan
    • OpenGL
    • Metal
    • WebGPU
    • WebGL 2
  • Multithreaded rendering
diff --git a/Cargo.toml b/Cargo.toml
index 7729047..393959d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -39,7 +39,7 @@ name = "ui"
required-features = ["render"]
[dependencies]
-bevy = { version = "0.14.0", default-features = false, features = [
+bevy = { version = "0.15.0-dev", default-features = false, features = [
diff --git a/examples/tools/scene_viewer/scene_viewer_plugin.rs b/examples/tools/scene_viewer/scene_viewer_plugin.rs
index 2ff6af494..52597c1bb 100644
--- a/examples/tools/scene_viewer/scene_viewer_plugin.rs
+++ b/examples/tools/scene_viewer/scene_viewer_plugin.rs
@@ -72,6 +72,7 @@ impl Plugin for SceneViewerPlugin {
Update,
(
update_lights,
+ update_materials,
camera_tracker,
diff --git a/crates/bevy_pbr/src/extended_material.rs b/crates/bevy_pbr/src/extended_material.rs
index a5c46ea6f..39ad33faf 100644
--- a/crates/bevy_pbr/src/extended_material.rs
+++ b/crates/bevy_pbr/src/extended_material.rs
@@ -1,3 +1,5 @@
+use std::marker::PhantomData;
+
use bevy_asset::{Asset, Handle};
use bevy_reflect::{impl_type_path, Reflect};
use bevy_render::{
diff --git a/crates/bevy_pbr/src/meshlet/from_mesh.rs b/crates/bevy_pbr/src/meshlet/from_mesh.rs
index 36af9c445..c6f8c6cff 100644
--- a/crates/bevy_pbr/src/meshlet/from_mesh.rs
+++ b/crates/bevy_pbr/src/meshlet/from_mesh.rs
@@ -23,14 +23,14 @@ impl MeshletMesh {
if mesh.primitive_topology() != PrimitiveTopology::TriangleList {
return Err(MeshToMeshletMeshConversionError::WrongMeshPrimitiveTopology);
}
- let vertex_buffer_layout = &mesh.get_mesh_vertex_buffer_layout();
- if vertex_buffer_layout.attribute_ids()
diff --git a/crates/bevy_pbr/src/meshlet/material_draw_prepare.rs b/crates/bevy_pbr/src/meshlet/material_draw_prepare.rs
index 1fee72d69..fb723a0d5 100644
--- a/crates/bevy_pbr/src/meshlet/material_draw_prepare.rs
+++ b/crates/bevy_pbr/src/meshlet/material_draw_prepare.rs
@@ -9,11 +9,11 @@ use bevy_core_pipeline::{
use bevy_derive::{Deref, DerefMut};
use bevy_render::{
camera::TemporalJitter,
- mesh::{InnerMeshVertexBufferLayout, Mesh, MeshVertexBufferLayout},
+ mesh::{Mesh, MeshVertexBufferLayout, MeshVertexBufferLayoutRef, MeshVertexBufferLayouts},