Skip to content

Commit fea7bce

Browse files
committed
com.atteneder.gltfast Release 6.16.0
1 parent 7f31d43 commit fea7bce

File tree

14 files changed

+219
-409
lines changed

14 files changed

+219
-409
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [6.16.0] - 2026-01-20
8+
9+
### Added
10+
- [GltfAsset](xref:GLTFast.GltfAsset) property setters to allow change of behavior from script.
11+
- [PlayAutomatically](xref:GLTFast.GltfAsset.PlayAutomatically).
12+
- [SceneId](xref:GLTFast.GltfAsset.SceneId).
13+
- HDRP material validation (fixes [#561](https://github.com/atteneder/glTFast/issues/561)).
14+
- Various overridable shader loading methods to [MaterialGenerator](xref:GLTFast.Materials.MaterialGenerator)-based classes so users can customize shader lookup. This is useful when working with Addressables (fixes [#715](https://github.com/atteneder/glTFast/issues/715)).
15+
- [MaterialGenerator.FindShader](xref:GLTFast.Materials.MaterialGenerator.FindShader(System.String)) for generic, runtime shader resolution.
16+
- [BuiltInMaterialGenerator.FindShaderMetallicRoughness](xref:GLTFast.Materials.BuiltInMaterialGenerator.FindShaderMetallicRoughness).
17+
- [BuiltInMaterialGenerator.FindShaderSpecularGlossiness](xref:GLTFast.Materials.BuiltInMaterialGenerator.FindShaderSpecularGlossiness).
18+
- [BuiltInMaterialGenerator.FindShaderUnlit](xref:GLTFast.Materials.BuiltInMaterialGenerator.FindShaderUnlit).
19+
- [ShaderGraphMaterialGenerator.LoadShaderByName](xref:GLTFast.Materials.ShaderGraphMaterialGenerator.LoadShaderByName(System.String)).
20+
21+
### Fixed
22+
- Emission color (emissiveFactor) is now in correct color space for shader graphs and built-in shaders.
23+
- Normal map scale on shader graphs.
24+
- (Export) Avoid creating empty ORM textures if no smoothness texture is assigned (fixes [#801](https://github.com/atteneder/glTFast/issues/801)).
25+
26+
### Deprecated
27+
- Access to glTF images via [IGltfReadable.ImageCount](xref:GLTFast.IGltfReadable.ImageCount) and [IGltfReadable.GetImage](xref:GLTFast.IGltfReadable.GetImage*). This has not been used internally and was unreliable. Please access glTF textures instead (see [TextureCount](xref:GLTFast.IGltfReadable.TextureCount) and [GetTexture](xref:GLTFast.IGltfReadable.GetTexture*)).
28+
729
## [6.15.1] - 2025-12-09
830

931
### Added

Runtime/Scripts/Export/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GLTFast.Export
77
{
88
static class Constants
99
{
10-
public const string version = "6.15.1";
10+
public const string version = "6.16.0";
1111

1212
internal const string mimeTypePNG = "image/png";
1313
internal const string mimeTypeJPG = "image/jpeg";

Runtime/Scripts/Export/StandardMaterialExport.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ public override bool ConvertMaterial(UnityEngine.Material uMaterial, out Materia
131131
}
132132

133133
var isPbrMetallicRoughness = IsPbrMetallicRoughness(uMaterial);
134-
var needsMetalRoughTexture =
135-
isPbrMetallicRoughness &&
136-
(
137-
HasMetallicGlossMap(uMaterial)
138-
|| uMaterial.IsKeywordEnabled(k_KeywordSmoothnessTextureAlbedoChannelA)
139-
);
140134

141135
Texture2D occlusionTexture = null;
142136
Texture2D metalGlossTexture = null;
@@ -152,6 +146,13 @@ public override bool ConvertMaterial(UnityEngine.Material uMaterial, out Materia
152146
mainTexProperty = k_ColorTexture;
153147
}
154148

149+
var needsMetalRoughTexture =
150+
isPbrMetallicRoughness &&
151+
(
152+
HasMetallicGlossMap(uMaterial)
153+
|| HasSmoothnessInAlbedoMapAlpha(uMaterial, mainTexProperty)
154+
);
155+
155156
if (IsUnlit(uMaterial))
156157
{
157158
ExportUnlit(material, uMaterial, mainTexProperty, gltf, logger);
@@ -262,6 +263,13 @@ out smoothnessTexture
262263
return success;
263264
}
264265

266+
static bool HasSmoothnessInAlbedoMapAlpha(UnityEngine.Material uMaterial, int mainTexProperty)
267+
{
268+
return uMaterial.IsKeywordEnabled(k_KeywordSmoothnessTextureAlbedoChannelA)
269+
&& uMaterial.HasProperty(mainTexProperty)
270+
&& uMaterial.GetTexture(mainTexProperty) is not null;
271+
}
272+
265273
static bool IsPbrMetallicRoughness(UnityEngine.Material material)
266274
{
267275
return material.HasProperty(MetallicProperty)

Runtime/Scripts/GltfAsset.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,20 @@ public bool LoadOnStartup
3838
/// <summary>
3939
/// Scene to load (-1 loads glTFs default scene)
4040
/// </summary>
41-
protected int SceneId => sceneId;
41+
public int SceneId
42+
{
43+
get => sceneId;
44+
set => sceneId = value;
45+
}
4246

4347
/// <summary>
4448
/// If true, the first animation clip starts playing right after instantiation.
4549
/// </summary>
46-
public bool PlayAutomatically => playAutomatically;
50+
public bool PlayAutomatically
51+
{
52+
get => playAutomatically;
53+
set => playAutomatically = value;
54+
}
4755

4856
/// <summary>
4957
/// If true, url is treated as relative StreamingAssets path

Runtime/Scripts/GltfImport.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,11 @@ void DisposeArray(IEnumerable<UnityEngine.Object> objects)
850850
/// </summary>
851851
public int MaterialCount => m_Materials?.Length ?? 0;
852852

853-
/// <summary>
854-
/// Number of images
855-
/// </summary>
853+
/// <inheritdoc cref="IGltfReadable.ImageCount"/>
854+
[Obsolete("Use TextureCount and GetTexture instead. This property will be removed in future releases.")]
856855
public int ImageCount => m_Images?.Length ?? 0;
857856

858-
/// <summary>
859-
/// Number of textures
860-
/// </summary>
857+
/// <inheritdoc cref="IGltfReadable.TextureCount"/>
861858
public int TextureCount => m_Textures?.Length ?? 0;
862859

863860
/// <summary>
@@ -932,11 +929,8 @@ public UnityEngine.Material GetDefaultMaterial()
932929
return Task.FromResult(GetDefaultMaterial());
933930
}
934931

935-
/// <summary>
936-
/// Returns a texture by its glTF image index
937-
/// </summary>
938-
/// <param name="index">glTF image index</param>
939-
/// <returns>Corresponding Unity texture</returns>
932+
/// <inheritdoc cref="IGltfReadable.GetImage"/>
933+
[Obsolete("Use GetTexture instead. This method will be removed in future releases.")]
940934
public Texture2D GetImage(int index = 0)
941935
{
942936
if (m_Images != null && index >= 0 && index < m_Images.Length)
@@ -946,11 +940,7 @@ public Texture2D GetImage(int index = 0)
946940
return null;
947941
}
948942

949-
/// <summary>
950-
/// Returns a texture by its glTF texture index
951-
/// </summary>
952-
/// <param name="index">glTF texture index</param>
953-
/// <returns>Corresponding Unity texture</returns>
943+
/// <inheritdoc cref="IGltfReadable.GetTexture"/>
954944
public Texture2D GetTexture(int index = 0)
955945
{
956946
if (m_Textures != null && index >= 0 && index < m_Textures.Length)

Runtime/Scripts/IGltfReadable.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ public interface IGltfReadable : IMaterialProvider
3838
/// <summary>
3939
/// Number of images
4040
/// </summary>
41+
/// <seealso cref="TextureCount"/>
42+
/// <seealso cref="GetTexture"/>
43+
[Obsolete("Use TextureCount and GetTexture instead. This property will be removed in future releases.")]
4144
int ImageCount { get; }
4245

4346
/// <summary>
4447
/// Number of textures
4548
/// </summary>
49+
/// <seealso cref="GetTexture"/>
4650
int TextureCount { get; }
4751

4852
/// <summary>
@@ -60,14 +64,18 @@ public interface IGltfReadable : IMaterialProvider
6064
Material GetDefaultMaterial();
6165

6266
/// <summary>
63-
/// Get texture by glTF image index
67+
/// Get imported glTF image by index.
68+
/// <b>Warning:</b> Only works temporarily during loading phase!
69+
/// It's recommended to work with <see cref="GetTexture"/> instead.
6470
/// </summary>
6571
/// <param name="index">glTF image index</param>
6672
/// <returns>Loaded Unity texture</returns>
73+
/// <seealso cref="GetTexture"/>
74+
[Obsolete("Use GetTexture instead. This method will be removed in future releases.")]
6775
Texture2D GetImage(int index = 0);
6876

6977
/// <summary>
70-
/// Get texture by glTF texture index
78+
/// Get imported glTF texture by index.
7179
/// </summary>
7280
/// <param name="index">glTF texture index</param>
7381
/// <returns>Loaded Unity texture</returns>

Runtime/Scripts/Material/BuiltInMaterialGenerator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ protected override Material GenerateDefaultMaterial(bool pointsSupport = false)
8080
/// <returns>Metallic/Roughness shader</returns>
8181
// Needs to be non-static outside of the Editor.
8282
// ReSharper disable once MemberCanBeMadeStatic.Local
83-
Shader FinderShaderMetallicRoughness()
83+
protected virtual Shader FindShaderMetallicRoughness()
8484
{
8585
#if UNITY_EDITOR
8686
return AssetDatabase.LoadAssetAtPath<Shader>($"{k_ShaderPathPrefix}{k_PbrMetallicRoughnessShaderPath}");
8787
#else
88-
return FindShader(k_PbrMetallicRoughnessShaderName, Logger);
88+
return FindShader(k_PbrMetallicRoughnessShaderName);
8989
#endif
9090
}
9191

@@ -95,12 +95,12 @@ Shader FinderShaderMetallicRoughness()
9595
/// <returns>Specular/Glossiness shader</returns>
9696
// Needs to be non-static outside of the Editor.
9797
// ReSharper disable once MemberCanBeMadeStatic.Local
98-
Shader FinderShaderSpecularGlossiness()
98+
protected virtual Shader FindShaderSpecularGlossiness()
9999
{
100100
#if UNITY_EDITOR
101101
return AssetDatabase.LoadAssetAtPath<Shader>($"{k_ShaderPathPrefix}{k_PbrSpecularGlossinessShaderPath}");
102102
#else
103-
return FindShader(k_PbrSpecularGlossinessShaderName, Logger);
103+
return FindShader(k_PbrSpecularGlossinessShaderName);
104104
#endif
105105
}
106106

@@ -110,20 +110,20 @@ Shader FinderShaderSpecularGlossiness()
110110
/// <returns>Unlit shader</returns>
111111
// Needs to be non-static outside of the Editor.
112112
// ReSharper disable once MemberCanBeMadeStatic.Local
113-
Shader FinderShaderUnlit()
113+
protected virtual Shader FindShaderUnlit()
114114
{
115115
#if UNITY_EDITOR
116116
return AssetDatabase.LoadAssetAtPath<Shader>($"{k_ShaderPathPrefix}{k_UnlitShaderPath}");
117117
#else
118-
return FindShader(k_UnlitShaderName, Logger);
118+
return FindShader(k_UnlitShaderName);
119119
#endif
120120
}
121121

122122
Material GetPbrMetallicRoughnessMaterial(bool doubleSided = false)
123123
{
124124
if (m_PbrMetallicRoughnessShader == null)
125125
{
126-
m_PbrMetallicRoughnessShader = FinderShaderMetallicRoughness();
126+
m_PbrMetallicRoughnessShader = FindShaderMetallicRoughness();
127127
}
128128
if (m_PbrMetallicRoughnessShader == null)
129129
{
@@ -145,7 +145,7 @@ Material GetPbrSpecularGlossinessMaterial(bool doubleSided = false)
145145
{
146146
if (m_PbrSpecularGlossinessShader == null)
147147
{
148-
m_PbrSpecularGlossinessShader = FinderShaderSpecularGlossiness();
148+
m_PbrSpecularGlossinessShader = FindShaderSpecularGlossiness();
149149
}
150150
if (m_PbrSpecularGlossinessShader == null)
151151
{
@@ -167,7 +167,7 @@ Material GetUnlitMaterial(bool doubleSided = false)
167167
{
168168
if (m_UnlitShader == null)
169169
{
170-
m_UnlitShader = FinderShaderUnlit();
170+
m_UnlitShader = FindShaderUnlit();
171171
}
172172
if (m_UnlitShader == null)
173173
{
@@ -385,7 +385,7 @@ public override Material GenerateMaterial(
385385

386386
if (gltfMaterial.Emissive != Color.black)
387387
{
388-
material.SetColor(MaterialProperty.EmissiveFactor, gltfMaterial.Emissive.gamma);
388+
material.SetColor(MaterialProperty.EmissiveFactor, gltfMaterial.Emissive);
389389
material.EnableKeyword(k_EmissionKeyword);
390390
}
391391

Runtime/Scripts/Material/HighDefinitionRPMaterialGenerator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
#if USING_HDRP
55

66
using System;
7+
using GLTFast.Schema;
78
#if UNITY_EDITOR
89
using UnityEditor;
910
#endif
1011
using UnityEngine;
1112
using UnityEngine.Rendering;
1213
using UnityEngine.Rendering.HighDefinition;
14+
using Material = UnityEngine.Material;
1315

1416
namespace GLTFast.Materials {
1517

@@ -43,6 +45,13 @@ public class HighDefinitionRPMaterialGenerator : ShaderGraphMaterialGenerator {
4345
static bool s_MetallicStackLitShaderQueried;
4446
static Shader s_MetallicStackLitShader;
4547

48+
public override Material GenerateMaterial(MaterialBase gltfMaterial, IGltfReadable gltf, bool pointsSupport = false)
49+
{
50+
var material = base.GenerateMaterial(gltfMaterial, gltf, pointsSupport);
51+
HDMaterial.ValidateMaterial(material);
52+
return material;
53+
}
54+
4655
protected override void SetDoubleSided(Schema.MaterialBase gltfMaterial, Material material) {
4756
base.SetDoubleSided(gltfMaterial,material);
4857

Runtime/Scripts/Material/MaterialGenerator.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,17 @@ public UnityEngine.Material GetDefaultMaterial(bool pointsSupport = false)
281281
protected abstract UnityEngine.Material GenerateDefaultMaterial(bool pointsSupport = false);
282282

283283
/// <summary>
284-
/// Tries to load a shader and covers error handling.
284+
/// Loads a shader by name and does eventual error reporting.
285+
/// </summary>
286+
/// <param name="shaderName">The requested shader's name.</param>
287+
/// <returns>Requested shader or null if it couldn't be loaded.</returns>
288+
protected virtual Shader FindShader(string shaderName)
289+
{
290+
return FindShader(shaderName, Logger);
291+
}
292+
293+
/// <summary>
294+
/// Loads a shader by name and does eventual error reporting.
285295
/// </summary>
286296
/// <param name="shaderName">The requested shader's name.</param>
287297
/// <param name="logger">Logger used for reporting errors.</param>

Runtime/Scripts/Material/ShaderGraphMaterialGenerator.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,21 @@ protected static Shader LoadShaderByGuid(GUID guid)
531531
}
532532
#endif
533533

534-
protected Shader LoadShaderByName(string shaderName) {
534+
/// <summary>
535+
/// Loads a shader by name and does eventual error reporting.
536+
/// </summary>
537+
/// <param name="shaderName">The requested shader's name.</param>
538+
/// <returns>Requested shader or null if it couldn't be loaded.</returns>
539+
protected virtual Shader LoadShaderByName(string shaderName) {
535540
#if UNITY_EDITOR
536541
var shaderPath = $"{k_ShaderPathPrefix}{shaderName}.shadergraph";
537542
var shader = AssetDatabase.LoadAssetAtPath<Shader>(shaderPath);
538543
if (shader == null) {
539-
Logger?.Error($"Cannot load shader at path {shaderPath}");
544+
Logger?.Error(LogCode.ShaderMissing, shaderPath);
540545
}
541546
return shader;
542547
#else
543-
return FindShader($"{k_ShaderGraphsPrefix}{shaderName}", Logger);
548+
return FindShader($"{k_ShaderGraphsPrefix}{shaderName}");
544549
#endif
545550
}
546551

0 commit comments

Comments
 (0)