diff --git a/Runtime/ConfigureReinterop.cs b/Runtime/ConfigureReinterop.cs index c674fbc0..b95d4527 100644 --- a/Runtime/ConfigureReinterop.cs +++ b/Runtime/ConfigureReinterop.cs @@ -158,6 +158,7 @@ public void ExposeToCPP() int crc = meshRenderer.material.ComputeCRC(); meshRenderer.material.SetTexture(id, texture2D); meshRenderer.material.SetFloat(id, 1.0f); + meshRenderer.material.SetFloat(id, (float)CullMode.Off); meshRenderer.material.SetVector(id, new Vector4()); meshRenderer.material.DisableKeyword("keywordName"); meshRenderer.material.EnableKeyword("keywordName"); diff --git a/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph b/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph index 2ac0bd88..4b23589b 100644 --- a/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph +++ b/Runtime/Resources/CesiumDefaultTilesetShader.shadergraph @@ -443,6 +443,15 @@ }, { "m_Id": "bd948bd4fc06461284119e7978eafe57" + }, + { + "m_Id": "b5c83514fdb947ca8ad358fdf7e7ed63" + }, + { + "m_Id": "1bcc4ba4ec1e4f3392cb64d977f935f8" + }, + { + "m_Id": "676548d5b8354feebfa67a60c05d2143" } ], "m_GroupDatas": [ @@ -685,6 +694,20 @@ "m_SlotId": 1 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "1bcc4ba4ec1e4f3392cb64d977f935f8" + }, + "m_SlotId": 3 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "676548d5b8354feebfa67a60c05d2143" + }, + "m_SlotId": 1 + } + }, { "m_OutputSlot": { "m_Node": { @@ -1098,6 +1121,20 @@ }, "m_SlotId": 2 }, + "m_InputSlot": { + "m_Node": { + "m_Id": "676548d5b8354feebfa67a60c05d2143" + }, + "m_SlotId": 0 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "676548d5b8354feebfa67a60c05d2143" + }, + "m_SlotId": 2 + }, "m_InputSlot": { "m_Node": { "m_Id": "e5ca7bb83a9d4a5b99c6b17e8aa77844" @@ -1665,6 +1702,20 @@ "m_SlotId": -590019148 } }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "b5c83514fdb947ca8ad358fdf7e7ed63" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "1bcc4ba4ec1e4f3392cb64d977f935f8" + }, + "m_SlotId": 0 + } + }, { "m_OutputSlot": { "m_Node": { @@ -2311,6 +2362,54 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "046ca63a3c87490fa77c8a5e14d77dd8", + "m_Id": 0, + "m_DisplayName": "A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "A", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -2438,6 +2537,54 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "087ec335769b4e7b980cb235f3696f81", + "m_Id": 2, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "e00": 0.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 0.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 0.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 0.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", @@ -2523,13 +2670,13 @@ "m_ActiveSubTarget": { "m_Id": "450f531d65a441debf469a85c039a601" }, - "m_AllowMaterialOverride": false, + "m_AllowMaterialOverride": true, "m_SurfaceType": 0, "m_ZWriteControl": 0, "m_ZTestMode": 4, "m_AlphaMode": 0, "m_RenderFace": 2, - "m_AlphaClip": false, + "m_AlphaClip": true, "m_CustomEditorGUI": "" } @@ -2594,7 +2741,7 @@ "m_ZWriteControl": 0, "m_AlphaMode": 0, "m_RenderFace": 2, - "m_AlphaClip": false, + "m_AlphaClip": true, "m_CastShadows": false, "m_ReceiveShadows": true, "m_CustomEditorGUI": "", @@ -3458,6 +3605,51 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BranchNode", + "m_ObjectId": "1bcc4ba4ec1e4f3392cb64d977f935f8", + "m_Group": { + "m_Id": "dbd4e9568a614874b25288e2229220e7" + }, + "m_Name": "Branch", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -260.66668701171877, + "y": 1353.3333740234375, + "width": 172.0, + "height": 144.0 + } + }, + "m_Slots": [ + { + "m_Id": "d6dd6c0413814174ba7c6c00b35c72a0" + }, + { + "m_Id": "ced190e2c02144e2a3aec7e23511917d" + }, + { + "m_Id": "55b9951e01f248539b918417c2f4ba8d" + }, + { + "m_Id": "acfc7584ee604a929e560aff39ed23d8" + } + ], + "synonyms": [ + "switch", + "if", + "else" + ], + "m_Precision": 0, + "m_PreviewExpanded": false, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot", @@ -6015,6 +6207,30 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "55b9951e01f248539b918417c2f4ba8d", + "m_Id": 2, + "m_DisplayName": "False", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "False", + "m_StageCapability": 3, + "m_Value": { + "x": -1.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.RedirectNodeData", @@ -6783,6 +6999,48 @@ "m_SerializedDescriptor": "SurfaceDescription.BentNormal" } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.MultiplyNode", + "m_ObjectId": "676548d5b8354feebfa67a60c05d2143", + "m_Group": { + "m_Id": "dbd4e9568a614874b25288e2229220e7" + }, + "m_Name": "Multiply", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 136.66668701171876, + "y": 1156.0, + "width": 131.333251953125, + "height": 120.0 + } + }, + "m_Slots": [ + { + "m_Id": "046ca63a3c87490fa77c8a5e14d77dd8" + }, + { + "m_Id": "aef6383affc845ebbbc53be04e42c3d1" + }, + { + "m_Id": "087ec335769b4e7b980cb235f3696f81" + } + ], + "synonyms": [ + "multiplication", + "times", + "x" + ], + "m_Precision": 0, + "m_PreviewExpanded": false, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -10244,6 +10502,30 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "acfc7584ee604a929e560aff39ed23d8", + "m_Id": 3, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.SubGraphNode", @@ -10318,6 +10600,54 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot", + "m_ObjectId": "aef6383affc845ebbbc53be04e42c3d1", + "m_Id": 1, + "m_DisplayName": "B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "B", + "m_StageCapability": 3, + "m_Value": { + "e00": 2.0, + "e01": 2.0, + "e02": 2.0, + "e03": 2.0, + "e10": 2.0, + "e11": 2.0, + "e12": 2.0, + "e13": 2.0, + "e20": 2.0, + "e21": 2.0, + "e22": 2.0, + "e23": 2.0, + "e30": 2.0, + "e31": 2.0, + "e32": 2.0, + "e33": 2.0 + }, + "m_DefaultValue": { + "e00": 1.0, + "e01": 0.0, + "e02": 0.0, + "e03": 0.0, + "e10": 0.0, + "e11": 1.0, + "e12": 0.0, + "e13": 0.0, + "e20": 0.0, + "e21": 0.0, + "e22": 1.0, + "e23": 0.0, + "e30": 0.0, + "e31": 0.0, + "e32": 0.0, + "e33": 1.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", @@ -10776,6 +11106,55 @@ } } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BooleanMaterialSlot", + "m_ObjectId": "b5bb6f16fdea4c48b5c5f138fb05c632", + "m_Id": 0, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 2, + "m_Value": true, + "m_DefaultValue": true +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.IsFrontFaceNode", + "m_ObjectId": "b5c83514fdb947ca8ad358fdf7e7ed63", + "m_Group": { + "m_Id": "dbd4e9568a614874b25288e2229220e7" + }, + "m_Name": "Is Front Face", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -466.0, + "y": 1329.3333740234375, + "width": 121.33331298828125, + "height": 78.6666259765625 + } + }, + "m_Slots": [ + { + "m_Id": "b5bb6f16fdea4c48b5c5f138fb05c632" + } + ], + "synonyms": [ + "face", + "side" + ], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -11724,6 +12103,30 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", + "m_ObjectId": "ced190e2c02144e2a3aec7e23511917d", + "m_Id": 1, + "m_DisplayName": "True", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "True", + "m_StageCapability": 3, + "m_Value": { + "x": 1.0, + "y": 1.0, + "z": 1.0, + "w": 1.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + } +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -12048,6 +12451,20 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BooleanMaterialSlot", + "m_ObjectId": "d6dd6c0413814174ba7c6c00b35c72a0", + "m_Id": 0, + "m_DisplayName": "Predicate", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Predicate", + "m_StageCapability": 3, + "m_Value": false, + "m_DefaultValue": false +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", diff --git a/native~/Runtime/src/TilesetMaterialProperties.cpp b/native~/Runtime/src/TilesetMaterialProperties.cpp index 2018a8c6..010b5446 100644 --- a/native~/Runtime/src/TilesetMaterialProperties.cpp +++ b/native~/Runtime/src/TilesetMaterialProperties.cpp @@ -16,6 +16,11 @@ using namespace DotNet::UnityEngine; namespace CesiumForUnityNative { #pragma region Parameter Names +const std::string TilesetMaterialProperties::_cullName = "_Cull"; +const std::string TilesetMaterialProperties::_cullModeName = "_CullMode"; +const std::string TilesetMaterialProperties::_builtInCullModeName = + "_BUILTIN_CullMode"; + const std::string TilesetMaterialProperties::_baseColorFactorName = "_baseColorFactor"; const std::string TilesetMaterialProperties::_baseColorTextureName = @@ -78,7 +83,11 @@ const std::string TilesetMaterialProperties::_overlayTranslationAndScalePrefix = #pragma endregion TilesetMaterialProperties::TilesetMaterialProperties() - : _baseColorFactorID( + : _cullID(Shader::PropertyToID(System::String(_cullName))), + _cullModeID(Shader::PropertyToID(System::String(_cullModeName))), + _builtInCullModeID( + Shader::PropertyToID(System::String(_builtInCullModeName))), + _baseColorFactorID( Shader::PropertyToID(System::String(_baseColorFactorName))), _baseColorTextureID( Shader::PropertyToID(System::String(_baseColorTextureName))), diff --git a/native~/Runtime/src/TilesetMaterialProperties.h b/native~/Runtime/src/TilesetMaterialProperties.h index ee26e922..f0999615 100644 --- a/native~/Runtime/src/TilesetMaterialProperties.h +++ b/native~/Runtime/src/TilesetMaterialProperties.h @@ -13,6 +13,10 @@ class TilesetMaterialProperties { public: TilesetMaterialProperties(); + const int32_t getCullID() const noexcept { return this->_cullID; } + const int32_t getBuiltInCullModeID() const noexcept { return this->_builtInCullModeID; } + const int32_t getCullModeID() const noexcept { return this->_cullModeID; } + const int32_t getBaseColorFactorID() const noexcept { return this->_baseColorFactorID; } @@ -88,6 +92,10 @@ class TilesetMaterialProperties { const std::vector& overlayMaterialKeys); private: + int32_t _cullID; + int32_t _cullModeID; + int32_t _builtInCullModeID; + int32_t _baseColorFactorID; int32_t _baseColorTextureID; int32_t _baseColorTextureCoordinateIndexID; @@ -118,6 +126,10 @@ class TilesetMaterialProperties { std::unordered_map _overlayTextureIDs; std::unordered_map _overlayTranslationAndScaleIDs; + static const std::string _cullName; + static const std::string _cullModeName; + static const std::string _builtInCullModeName; + static const std::string _baseColorFactorName; static const std::string _baseColorTextureName; static const std::string _baseColorTextureCoordinateIndexName; diff --git a/native~/Runtime/src/UnityPrepareRendererResources.cpp b/native~/Runtime/src/UnityPrepareRendererResources.cpp index 34cdbadf..6eef6c3e 100644 --- a/native~/Runtime/src/UnityPrepareRendererResources.cpp +++ b/native~/Runtime/src/UnityPrepareRendererResources.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1024,6 +1025,31 @@ void setGltfMaterialParameterValues( const TilesetMaterialProperties& materialProperties) { CESIUM_TRACE("Cesium::CreateMaterials"); + // These similar-sounding material properties are used in various render + // pipelines (built-in, URP, HDRP). Rather than try to figure out which + // applies, we just set them all. + if (gltfMaterial.doubleSided) { + unityMaterial.SetFloat( + materialProperties.getCullID(), + float(UnityEngine::Rendering::CullMode::Off)); + unityMaterial.SetFloat( + materialProperties.getCullModeID(), + float(UnityEngine::Rendering::CullMode::Off)); + unityMaterial.SetFloat( + materialProperties.getBuiltInCullModeID(), + float(UnityEngine::Rendering::CullMode::Off)); + } else { + unityMaterial.SetFloat( + materialProperties.getCullID(), + float(UnityEngine::Rendering::CullMode::Back)); + unityMaterial.SetFloat( + materialProperties.getCullModeID(), + float(UnityEngine::Rendering::CullMode::Back)); + unityMaterial.SetFloat( + materialProperties.getBuiltInCullModeID(), + float(UnityEngine::Rendering::CullMode::Back)); + } + const CesiumGltf::MaterialPBRMetallicRoughness& pbr = gltfMaterial.pbrMetallicRoughness ? gltfMaterial.pbrMetallicRoughness.value()