From 3e631e6234067921e359fc90ae13aec8b9048922 Mon Sep 17 00:00:00 2001 From: Jakob Hellermann Date: Sun, 20 Mar 2022 21:32:38 +0000 Subject: [PATCH] gltf-loader: disable backface culling if material is double-sided (#4270) # 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`. --- crates/bevy_gltf/src/loader.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_gltf/src/loader.rs b/crates/bevy_gltf/src/loader.rs index db42a5731d..4bf665ffdf 100644 --- a/crates/bevy_gltf/src/loader.rs +++ b/crates/bevy_gltf/src/loader.rs @@ -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, @@ -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,