Skip to content

Commit

Permalink
gltf-loader: disable backface culling if material is double-sided (#4270
Browse files Browse the repository at this point in the history
)

# Objective

The  [glTF spec](https://github.com/KhronosGroup/glTF/blob/8e798b02d254cea97659a333cfcb20875b62bdd4/specification/2.0/Specification.adoc#395-double-sided) the `doubleSided` has the following to say about the `doubleSided` boolean:

> When this value is false, back-face culling is enabled, i.e., only front-facing triangles are rendered.
> When this value is true, back-face culling is disabled and double sided lighting is enabled. The back-face MUST have its normals reversed before the lighting equation is evaluated.

## Solution
Disable backface culling when `doubleSided: true`.
  • Loading branch information
jakobhellermann committed Mar 20, 2022
1 parent af24576 commit 3e631e6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use bevy_render::{
color::Color,
mesh::{Indices, Mesh, VertexAttributeValues},
primitives::{Aabb, Frustum},
render_resource::{AddressMode, FilterMode, PrimitiveTopology, SamplerDescriptor},
render_resource::{AddressMode, Face, FilterMode, PrimitiveTopology, SamplerDescriptor},
renderer::RenderDevice,
texture::{CompressedImageFormats, Image, ImageType, TextureError},
view::VisibleEntities,
Expand Down Expand Up @@ -473,6 +473,11 @@ fn load_material(material: &Material, load_context: &mut LoadContext) -> Handle<
metallic_roughness_texture,
normal_map_texture,
double_sided: material.double_sided(),
cull_mode: if material.double_sided() {
None
} else {
Some(Face::Back)
},
occlusion_texture,
emissive: Color::rgba(emissive[0], emissive[1], emissive[2], 1.0),
emissive_texture,
Expand Down

0 comments on commit 3e631e6

Please sign in to comment.