Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ libCesiumForUnityNative-*.so.meta
libCesiumForUnityNative-*.dylib
libCesiumForUnityNative-*.dylib.meta
Documentation~/Reference/
package-lock.json

5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- Added option to ignore the `KHR_material_unlit` extension to force default lighting on tilesets.

##### Breaking Changes :mega:

- Flat normals are now computed in `CesiumDefaultTilesetShader` to avoid duplicating vertices as tiles are loaded. Existing copies of this shader should incorporate this logic using the boolean `computeFlatNormals` property to maintain a correct appearance.


## v1.17.0 - 2025-08-01

##### Additions :tada:
Expand Down
22 changes: 16 additions & 6 deletions Editor/Cesium3DTilesetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class Cesium3DTilesetEditor : Editor
//private SerializedProperty _useLodTransitions;
//private SerializedProperty _lodTransitionLength;
private SerializedProperty _generateSmoothNormals;
private SerializedProperty _generateTangents;

private SerializedProperty _pointCloudShading;

Expand Down Expand Up @@ -84,6 +85,9 @@ private void OnEnable()
// this.serializedObject.FindProperty("_lodTransitionLength");
this._generateSmoothNormals =
this.serializedObject.FindProperty("_generateSmoothNormals");
this._generateTangents =
this.serializedObject.FindProperty("_generateTangents");

this._ignoreKhrMaterialsUnlit = this.serializedObject.FindProperty("_ignoreKhrMaterialsUnlit");

this._pointCloudShading = this.serializedObject.FindProperty("_pointCloudShading");
Expand Down Expand Up @@ -422,13 +426,19 @@ private void DrawRenderProperties()
"Generate Smooth Normals",
"Whether to generate smooth normals when normals are missing in the glTF." +
"\n\n" +
"According to the glTF spec: \"When normals are not specified, client " +
"implementations should calculate flat normals.\" However, calculating flat " +
"normals requires duplicating vertices. This option allows the glTFs to be " +
"rendered with smooth normals instead when the original glTF is missing normals.");
"This option allows glTFs to be rendered with smooth normals when the original glTF " +
"is missing normals. If this option is not enabled and normals are missing, " +
"flat normals will be generated in the shader. "
);
EditorGUILayout.PropertyField(this._generateSmoothNormals, generateSmoothNormalsContent);

var ignoreKhrMaterialsUnlit = new GUIContent(
var generateTangentsContent = new GUIContent(
"Generate Tangents",
"Whether to generate per-vertex tangets if they are missing in the source glTF."
);
EditorGUILayout.PropertyField(this._generateTangents, generateTangentsContent);

var ignoreKhrMaterialsUnlitContent = new GUIContent(
"Ignore KHR_materials_unlit",
"Whether to ignore the KHR_materials_unlit extension on the glTF tiles in "+
"this tileset, if it exists, and instead render with standard lighting and "+
Expand All @@ -439,7 +449,7 @@ private void DrawRenderProperties()
"tilesets because lighting and shadows are already baked into their "+
"textures. "
);
EditorGUILayout.PropertyField(this._ignoreKhrMaterialsUnlit, ignoreKhrMaterialsUnlit);
EditorGUILayout.PropertyField(this._ignoreKhrMaterialsUnlit, ignoreKhrMaterialsUnlitContent);
}

private void DrawPointCloudShadingProperties()
Expand Down
31 changes: 27 additions & 4 deletions Runtime/Cesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,8 @@ public Material opaqueMaterial
/// Whether to generate smooth normals when normals are missing in the glTF.
/// </summary>
/// <remarks>
/// According to the glTF spec: "When normals are not specified, client
/// implementations should calculate flat normals." However, calculating flat
/// normals requires duplicating vertices. This option allows the glTFs to be rendered
/// with smooth normals instead when the original glTF is missing normals.
/// This option allows the glTFs to be rendered with smooth normals instead when the original glTF is missing normals.
/// If normals are missing and this option is not enabled, flat normals will be generated in the shader.
/// </remarks>
public bool generateSmoothNormals
{
Expand All @@ -589,6 +587,31 @@ public bool generateSmoothNormals
}
}

[SerializeField]
private bool _generateTangents = false;

/// <summary>
/// Whether to generate per-vertex tangents when tangents are missing in the glTF.
/// </summary>
/// <remarks>
/// The glTF 2.0 specification suggests that tangents should be generated when they
/// are missing.
/// "When tangents are not specified, client implementations SHOULD calculate tangents using
/// default MikkTSpace algorithms with the specified vertex positions, normals, and texture
/// coordinates associated with the normal texture."
/// </remarks>
/// <seealso cref="https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html"/>

public bool generateTangents
{
get => _generateTangents;
set
{
this._generateSmoothNormals = value;
this.RecreateTileset();
}
}

[SerializeField]
private bool _ignoreKhrMaterialsUnlit = false;

Expand Down
14 changes: 12 additions & 2 deletions Runtime/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void ExposeToCPP()
int pixelWidth = c.pixelWidth;
float aspect = c.aspect;
bool isOrtho = c.orthographic;
float orthoSize = c.orthographicSize;
float orthoSize = c.orthographicSize;
//IFormattable f = new Vector3();
//IEquatable<Vector3> f2 = new Vector3();

Expand Down Expand Up @@ -185,6 +185,14 @@ public void ExposeToCPP()
meshFilter.mesh = mesh;
meshFilter.sharedMesh = mesh;

Debug.Log("Hello world");

mesh.RecalculateTangents();
var tangents = mesh.tangents;
var normals = mesh.normals;
mesh.RecalculateNormals();


Resources.Load<Material>("name");

byte b;
Expand Down Expand Up @@ -236,7 +244,7 @@ public void ExposeToCPP()
string e = request.error;
string method = request.method;
string url = request.url;
if (request.result == UnityWebRequest.Result.Success) { };
if (request.result == UnityWebRequest.Result.Success) { }
request.downloadHandler = new NativeDownloadHandler();
request.SetRequestHeader("name", "value");
request.GetResponseHeader("name");
Expand Down Expand Up @@ -279,6 +287,7 @@ public void ExposeToCPP()
//tileset.useLodTransitions = tileset.useLodTransitions;
//tileset.lodTransitionLength = tileset.lodTransitionLength;
tileset.generateSmoothNormals = tileset.generateSmoothNormals;
tileset.generateTangents = tileset.generateTangents;
tileset.ignoreKhrMaterialsUnlit = tileset.ignoreKhrMaterialsUnlit;
tileset.createPhysicsMeshes = tileset.createPhysicsMeshes;
tileset.suspendUpdate = tileset.suspendUpdate;
Expand All @@ -289,6 +298,7 @@ public void ExposeToCPP()
tileset.ionServer = tileset.ionServer;
tileset.RecreateTileset();


GraphicsFormat gfxFmt = GraphicsFormat.RGB_ETC_UNorm;
FormatUsage fmtUsage = FormatUsage.Sample;
SystemInfo.IsFormatSupported(gfxFmt, fmtUsage);
Expand Down
17 changes: 9 additions & 8 deletions Runtime/Resources/CesiumDefaultTilesetMaterial.mat
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: CesiumDefaultTilesetMaterial
m_Shader: {fileID: -6465566751694194690, guid: 407c0cff68611ac46a65eec87a5203f5,
m_Shader: {fileID: -6465566751694194690, guid: f1bf6a52c1d9b4896bcefbee4a1432af,
type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHATEST_ON
- _BUILTIN_ALPHATEST_ON
- _BUILTIN_AlphaClip
- _DISABLE_SSR_TRANSPARENT
- _DOUBLESIDED_ON
m_InvalidKeywords: []
m_LightmapFlags: 2
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 1
m_CustomRenderQueue: 2450
m_CustomRenderQueue: -1
stringTagMap:
MotionVector: User
RenderType: TransparentCutout
Expand All @@ -43,6 +41,7 @@ Material:
- TransparentBackface
- RayTracingPrepass
- MOTIONVECTORS
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
Expand Down Expand Up @@ -101,7 +100,7 @@ Material:
- _AlphaCutoffEnable: 1
- _AlphaDstBlend: 0
- _AlphaSrcBlend: 1
- _AlphaToMask: 0
- _AlphaToMask: 1
Comment thread
david-lively marked this conversation as resolved.
- _AlphaToMaskInspectorValue: 0
- _BUILTIN_AlphaClip: 1
- _BUILTIN_Blend: 0
Expand All @@ -116,6 +115,7 @@ Material:
- _BUILTIN_ZWriteControl: 0
- _Blend: 0
- _BlendMode: 0
- _BlendModePreserveSpecular: 0
- _CastShadows: 1
- _ConservativeDepthOffsetEnable: 0
- _Cull: 0
Expand Down Expand Up @@ -168,6 +168,7 @@ Material:
- _ZWrite: 1
- _ZWriteControl: 0
- _baseColorTextureCoordinateIndex: 0
- _computeFlatNormals: 0
- _emissiveTextureCoordinateIndex: 0
- _metallicRoughnessTextureCoordinateIndex: 0
- _normalMapScale: 0
Expand Down Expand Up @@ -222,4 +223,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 5
version: 7
Loading
Loading