Skip to content

Commit 85b1729

Browse files
committed
Fix PBR regression for unlit materials (#2197)
Fixes the frag shader for unlit materials by correcting the scope of the `#ifndef` to include the light functions. Closes #2190, introduced in #2112. Tested by changing materials in the the `3d_scene` example to be unlit. Unsure how to prevent future regressions without creating a test case scene that will catch these runtime panics.
1 parent 189df30 commit 85b1729

File tree

2 files changed

+30
-6
lines changed
  • crates/bevy_pbr/src/render_graph/pbr_pipeline
  • examples/3d

2 files changed

+30
-6
lines changed

crates/bevy_pbr/src/render_graph/pbr_pipeline/pbr.frag

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ vec3 reinhard_extended_luminance(vec3 color, float max_white_l) {
283283
return change_luminance(color, l_new);
284284
}
285285

286-
#endif
287-
288286
vec3 point_light(PointLight light, float roughness, float NdotV, vec3 N, vec3 V, vec3 R, vec3 F0, vec3 diffuseColor) {
289287
vec3 light_to_frag = light.pos.xyz - v_WorldPosition.xyz;
290288
float distance_square = dot(light_to_frag, light_to_frag);
@@ -349,6 +347,8 @@ vec3 dir_light(DirectionalLight light, float roughness, float NdotV, vec3 normal
349347
return (specular + diffuse) * light.color.rgb * NoL;
350348
}
351349

350+
#endif
351+
352352
void main() {
353353
vec4 output_color = base_color;
354354
#ifdef STANDARDMATERIAL_BASE_COLOR_TEXTURE

examples/3d/pbr.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,44 @@ fn setup(
3333
roughness: x01,
3434
..Default::default()
3535
}),
36-
transform: Transform::from_xyz(x as f32, y as f32, 0.0),
36+
transform: Transform::from_xyz(x as f32, y as f32 + 0.5, 0.0),
3737
..Default::default()
3838
});
3939
}
4040
}
41+
// unlit sphere
42+
commands.spawn_bundle(PbrBundle {
43+
mesh: meshes.add(Mesh::from(shape::Icosphere {
44+
radius: 0.45,
45+
subdivisions: 32,
46+
})),
47+
material: materials.add(StandardMaterial {
48+
base_color: Color::hex("ffd891").unwrap(),
49+
// vary key PBR parameters on a grid of spheres to show the effect
50+
unlit: true,
51+
..Default::default()
52+
}),
53+
transform: Transform::from_xyz(-5.0, -2.5, 0.0),
54+
..Default::default()
55+
});
4156
// light
4257
commands.spawn_bundle(PointLightBundle {
43-
transform: Transform::from_translation(Vec3::new(0.0, 5.0, 5.0)),
58+
transform: Transform::from_translation(Vec3::new(50.0, 50.0, 50.0)),
59+
point_light: PointLight {
60+
intensity: 50000.,
61+
range: 100.,
62+
..Default::default()
63+
},
4464
..Default::default()
4565
});
4666
// camera
47-
commands.spawn_bundle(PerspectiveCameraBundle {
67+
commands.spawn_bundle(OrthographicCameraBundle {
4868
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 8.0))
4969
.looking_at(Vec3::default(), Vec3::Y),
50-
..Default::default()
70+
orthographic_projection: bevy::render::camera::OrthographicProjection {
71+
scale: 0.01,
72+
..Default::default()
73+
},
74+
..OrthographicCameraBundle::new_3d()
5175
});
5276
}

0 commit comments

Comments
 (0)