From 7a7ba6b9ad4fb010332e46b29e6b403e65165a97 Mon Sep 17 00:00:00 2001 From: Christian Petry Date: Wed, 12 Nov 2025 08:13:10 +0100 Subject: [PATCH] Fixes #2748 - Adjusted URP emissiveFactor analog to Built-in material --- .../URP/Export/Materials/UrpLitMaterialExporter.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Packages/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs b/Packages/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs index e0bf6a4f2..6763628e6 100644 --- a/Packages/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs +++ b/Packages/UniGLTF/Runtime/UniGLTF/IO/MaterialIO/URP/Export/Materials/UrpLitMaterialExporter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.Rendering; @@ -174,7 +175,16 @@ namespace UniGLTF { if (!context.IsEmissionEnabled) return; - dst.emissiveFactor = context.EmissionColorLinear.ToFloat3(ColorSpace.Linear, ColorSpace.Linear); + var emissiveFactor = context.EmissionColorLinear.ToFloat3(ColorSpace.Linear, ColorSpace.Linear); + // Unity uses HDR color for emission factor. Normalize it if any component is greater than 1. + // If not normalized, glTF validator throws an error "VALUE_NOT_IN_RANGE" + var maxComponent = emissiveFactor.Max(); + if (maxComponent > 1) + { + emissiveFactor = emissiveFactor.Select(x => x / maxComponent).ToArray(); + glTF_KHR_materials_emissive_strength.Serialize(ref dst.extensions, maxComponent); + } + dst.emissiveFactor = emissiveFactor; if (context.EmissionTexture != null) { var index = textureExporter.RegisterExportingAsSRgb(context.EmissionTexture, true);