Skip to content

Commit 95a95b5

Browse files
committed
Modified vertex buffer generation to include tangents when necessary. Added editor support for forcing tangent generation.
1 parent 21ff68f commit 95a95b5

8 files changed

Lines changed: 272 additions & 20 deletions

File tree

Editor/Cesium3DTilesetEditor.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class Cesium3DTilesetEditor : Editor
3535
//private SerializedProperty _useLodTransitions;
3636
//private SerializedProperty _lodTransitionLength;
3737
private SerializedProperty _generateSmoothNormals;
38+
private SerializedProperty _alwaysIncludeTangents;
3839

3940
private SerializedProperty _pointCloudShading;
4041

@@ -84,6 +85,8 @@ private void OnEnable()
8485
// this.serializedObject.FindProperty("_lodTransitionLength");
8586
this._generateSmoothNormals =
8687
this.serializedObject.FindProperty("_generateSmoothNormals");
88+
this._alwaysIncludeTangents =
89+
this.serializedObject.FindProperty("_alwaysIncludeTangents");
8790
this._ignoreKhrMaterialsUnlit = this.serializedObject.FindProperty("_ignoreKhrMaterialsUnlit");
8891

8992
this._pointCloudShading = this.serializedObject.FindProperty("_pointCloudShading");
@@ -428,7 +431,17 @@ private void DrawRenderProperties()
428431
"rendered with smooth normals instead when the original glTF is missing normals.");
429432
EditorGUILayout.PropertyField(this._generateSmoothNormals, generateSmoothNormalsContent);
430433

431-
var ignoreKhrMaterialsUnlit = new GUIContent(
434+
var alwaysIncludeTangents = new GUIContent(
435+
"Always Include Tangents",
436+
"Whether to generate tangents when they are missing from the glTF." +
437+
"According to the glTF spec: \"When tangents are not specified, client " +
438+
"implementations SHOULD calculate tangents using default MikkTSpace algorithms " +
439+
"with the specified vertex positions, normals, and texture coordinates " +
440+
"associated with the normal texture.\""
441+
);
442+
EditorGUILayout.PropertyField(this._alwaysIncludeTangents, alwaysIncludeTangents);
443+
444+
var ignoreKhrMaterialsUnlitContent = new GUIContent(
432445
"Ignore KHR_materials_unlit",
433446
"Whether to ignore the KHR_materials_unlit extension on the glTF tiles in "+
434447
"this tileset, if it exists, and instead render with standard lighting and "+
@@ -439,7 +452,7 @@ private void DrawRenderProperties()
439452
"tilesets because lighting and shadows are already baked into their "+
440453
"textures. "
441454
);
442-
EditorGUILayout.PropertyField(this._ignoreKhrMaterialsUnlit, ignoreKhrMaterialsUnlit);
455+
EditorGUILayout.PropertyField(this._ignoreKhrMaterialsUnlit, ignoreKhrMaterialsUnlitContent);
443456
}
444457

445458
private void DrawPointCloudShadingProperties()

Runtime/Cesium3DTileset.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,27 @@ public bool generateSmoothNormals
589589
}
590590
}
591591

592+
[SerializeField]
593+
private bool _alwaysIncludeTangents = false;
594+
/// <summary>
595+
/// Whether to generate tangents when they are missing from the glTF.
596+
/// </summary>
597+
/// <remarks>
598+
/// According to the glTF spec: "When tangents are not specified, client
599+
/// implementations SHOULD calculate tangents using default MikkTSpace algorithms
600+
/// with the specified vertex positions, normals, and texture coordinates
601+
/// associated with the normal texture."
602+
/// </remarks>
603+
public bool alwaysIncludeTangents
604+
{
605+
get => this._alwaysIncludeTangents;
606+
set
607+
{
608+
this._alwaysIncludeTangents = value;
609+
this.RecreateTileset();
610+
}
611+
}
612+
592613
[SerializeField]
593614
private bool _ignoreKhrMaterialsUnlit = false;
594615

Runtime/ConfigureReinterop.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public void ExposeToCPP()
279279
//tileset.useLodTransitions = tileset.useLodTransitions;
280280
//tileset.lodTransitionLength = tileset.lodTransitionLength;
281281
tileset.generateSmoothNormals = tileset.generateSmoothNormals;
282+
tileset.alwaysIncludeTangents = tileset.alwaysIncludeTangents;
282283
tileset.ignoreKhrMaterialsUnlit = tileset.ignoreKhrMaterialsUnlit;
283284
tileset.createPhysicsMeshes = tileset.createPhysicsMeshes;
284285
tileset.suspendUpdate = tileset.suspendUpdate;

Runtime/Resources/CesiumDefaultTilesetMaterial.mat

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ Material:
2323
m_Name: CesiumDefaultTilesetMaterial
2424
m_Shader: {fileID: -6465566751694194690, guid: 407c0cff68611ac46a65eec87a5203f5,
2525
type: 3}
26+
m_Parent: {fileID: 0}
27+
m_ModifiedSerializedProperties: 0
2628
m_ValidKeywords:
2729
- _ALPHATEST_ON
2830
- _BUILTIN_ALPHATEST_ON
2931
- _BUILTIN_AlphaClip
32+
m_InvalidKeywords:
3033
- _DISABLE_SSR_TRANSPARENT
3134
- _DOUBLESIDED_ON
32-
m_InvalidKeywords: []
3335
m_LightmapFlags: 2
3436
m_EnableInstancingVariants: 0
3537
m_DoubleSidedGI: 1
@@ -43,6 +45,7 @@ Material:
4345
- TransparentBackface
4446
- RayTracingPrepass
4547
- MOTIONVECTORS
48+
m_LockedProperties:
4649
m_SavedProperties:
4750
serializedVersion: 3
4851
m_TexEnvs:
@@ -101,7 +104,7 @@ Material:
101104
- _AlphaCutoffEnable: 1
102105
- _AlphaDstBlend: 0
103106
- _AlphaSrcBlend: 1
104-
- _AlphaToMask: 0
107+
- _AlphaToMask: 1
105108
- _AlphaToMaskInspectorValue: 0
106109
- _BUILTIN_AlphaClip: 1
107110
- _BUILTIN_Blend: 0
@@ -116,6 +119,7 @@ Material:
116119
- _BUILTIN_ZWriteControl: 0
117120
- _Blend: 0
118121
- _BlendMode: 0
122+
- _BlendModePreserveSpecular: 0
119123
- _CastShadows: 1
120124
- _ConservativeDepthOffsetEnable: 0
121125
- _Cull: 0
@@ -222,4 +226,4 @@ MonoBehaviour:
222226
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
223227
m_Name:
224228
m_EditorClassIdentifier:
225-
version: 5
229+
version: 7

Runtime/bin.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/obj.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)