bevy-pbr-materials
Skill29 starsChanged 11 days agoMITView on GitHub
Use when spawning `Mesh3d` with `StandardMaterial`, writing a custom `Material` with `AsBindGroup` and a `.wesl` shader, enabling `shadow_maps_enabled` / `contact_shadows_enabled` on lights, adding `ContactShadows` or `ScreenSpaceTransmission` to a `Camera3d`, spawning an `Atmosphere` entity, loading glTF `#Material0/std` sub-assets, or fixing `#import` / `#ifdef` shader errors after the WESL switch in Bevy 0.20.
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- bevy-a11ySkill
- bevy-animationSkill
- bevy-assetsSkill
- bevy-audioSkill
- bevy-camerasSkill
- bevy-captureSkill
- bevy-cargo-featuresSkill
- bevy-core-conceptsSkill
- bevy-custom-assetsSkill
- bevy-diagnostics-profilingSkill
- bevy-ecs-componentsSkill
- bevy-ecs-queriesSkill
- bevy-ecs-systemsSkill
- bevy-fluentSkill
- bevy-input-actionsSkill
- bevy-migration-0-17-to-0-18Skill
- bevy-migration-0-18-to-0-19Skill
- bevy-migration-0-19-to-0-20Skill
- bevy-physicsSkill
- bevy-portingSkill
- bevy-renderingSkill
- bevy-save-loadSkill
- bevySkill
- bevy-testingSkill
- bevy-uiSkill
- bevy-vfxSkill
- bevy-voxel-dataSkill
- bevy-voxel-pipelineSkill
- bevy-voxel-runtimeSkill
- bevy-wasm-webgpuSkill
- similarity-rsSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 143
Use Mesh3d(handle) and MeshMaterial3d(handle) — the renderer queries the wrappers.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Bevy 0.20 — PBR Materials
When to use this skill
- Texturing a mesh with the built-in physically based shader.
- Writing a custom
Material(stylised shading, dissolve, world-space effects). - Compiler error:
no field shadows_enabledon a light (renamed in 0.19). - Shader error:
#importor#ifdefnot recognised (naga_oil is gone in 0.20). - Translucent glass renders flat (screen-space transmission is opt-in in 0.20).
Handle<StandardMaterial>from a glTF sub-asset fails to load (needs/stdsince 0.19).
Canonical pattern — StandardMaterial
use bevy::pbr::ContactShadows;
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let mesh = meshes.add(Cuboid::new(1.0, 1.0, 1.0));
let material = materials.add(StandardMaterial {
base_color: Color::srgb(0.8, 0.3, 0.2),
perceptual_roughness: 0.4,
metallic: 0.1,
..default()
});
commands.spawn((
Mesh3d(mesh),
MeshMaterial3d(material),
Transform::from_xyz(0.0, 0.5, 0.0),
));
commands.spawn((
Camera3d::default(),
// Screen-space contact shadows (0.19+). Requires the depth prepass,
// which `ContactShadows` adds as a required component.
ContactShadows::default(),
Transform::from_xyz(0.0, 2.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y),
));
commands.spawn((
DirectionalLight {
// 0.19 renamed `shadows_enabled` to `shadow_maps_enabled`.
shadow_maps_enabled: true,
contact_shadows_enabled: true,
..default()
},
Transform::from_xyz(2.0, 4.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}Custom Material — 0.20 shape
use bevy::prelude::*;
use bevy::render::render_resource::AsBindGroup;
use bevy::shader::ShaderRef;
#[derive(Asset, AsBindGroup, TypePath, Debug, Clone)]
struct TintMaterial {
#[uniform(0)]
tint: LinearRgba,
}
impl Material for TintMaterial {
// 0.20: shaders are WESL. Use the `.wesl` extension for anything with imports.
fn fragment_shader() -> ShaderRef {
"shaders/tint.wesl".into()
}
}assets/shaders/tint.wesl:
import bevy_pbr::render::forward_io::VertexOutput;
@group(2) @binding(0) var<uniform> tint: vec4<f32>;
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
return tint;
}Full Material trait reference, AsBindGroup attributes and WESL translation rules:
references/custom-material.md.
Topics
| Topic | Reference |
PointLight, DirectionalLight, SpotLight fields; GlobalAmbientLight; cascades; Atmosphere entity | references/lighting.md |
Plane3d, Cuboid, Sphere, Circle, Cylinder, Capsule3d, Torus constructors and orientation | references/mesh-primitives.md |
Material trait methods, AsBindGroup attributes, ShaderRef, WESL syntax, MaterialPlugin | references/custom-material.md |
Gotchas
0.19 → 0.20
- Shaders are WESL. naga_oil is gone.
#import bevy_pbr::forward_io::VertexOutputbecomesimport bevy_pbr::render::forward_io::VertexOutput;(semicolon, module path mirrors the crate file path).#ifdef X ... #endifbecomes@if(X)on a declaration.#{MATERIAL_BIND_GROUP}becomesconstants::MATERIAL_BIND_GROUP.#define_import_pathis gone. Rename files.wgsl→.wesl; plain WGSL with no directives still loads. GLSL and theshader_format_weslfeature are gone. ScreenSpaceTransmissionis opt-in.Camera3dno longer requires it. Addbevy::pbr::ScreenSpaceTransmission::default()to the camera or transmissive materials render without refraction.Tonemapping::Noneis a pure passthrough (no grading, no dither, no clamp). For "no tone curve, keep the rest" useTonemapping::Linear.- Hand-rolled
AsBindGroup:unprepared_bind_groupis nowbuild_bind_groupwriting into aBindGroupBuilder.#[derive(AsBindGroup)]users are unaffected. - OIT is per-material. Override
Material::enable_oit(); the shader def isMATERIAL_OIT_ENABLED. bevy_shapesplit frombevy_math.Cuboid,Sphere, etc. still come throughbevy::prelude::*; direct paths arebevy::shape::*.
0.18 → 0.19
shadows_enabled→shadow_maps_enabledonPointLight,DirectionalLight,SpotLight. Newcontact_shadows_enabledfield plus theContactShadowscamera component.Atmosphereis an entity, inbevy::light. SpawnAtmosphere::earth(medium)on its own entity; the camera keepsAtmosphereSettings.scene_units_to_mis gone (scale the entity'sTransform).Atmosphere::earthlike→Atmosphere::earth.- glTF materials:
#Material0now loads aGltfMaterial. Append/stdfor aHandle<StandardMaterial>. Skybox.imageisOption<Handle<Image>>andSkyboxlives inbevy::light.AlphaModemoved tobevy_material(prelude still exports it).- Bloom luma is linear. Scenes look dimmer; raise
Bloom::intensityor emissive strength. - Render graph nodes are systems.
ViewNode/add_render_graph_nodeare gone; write a system withViewQueryinCore3d.
Still true
- Use
Mesh3d(handle)andMeshMaterial3d(handle)— the renderer queries the wrappers. Plane3d::newtakesVec2forhalf_size.Color::rgbis gone; useColor::srgb.- Directional light position is ignored; only rotation matters.
MaterialPlugin::<M>has noprepass_enabled/shadows_enabledfields; overrideMaterial::enable_prepass()/enable_shadows().
See also
bevy-cameras—Camera3d,Hdr,Tonemapping, render targets.bevy-vfx— custom-material shader effects and GPU particles.bevy-migration-0-19-to-0-20— WESL translation andScreenSpaceTransmission.bevy-migration-0-18-to-0-19— light field renames,Atmosphereentity, render systems.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

