public Material GetMaterial(TETerrainShardData.ElementType materialType)
    {
        switch (materialType)
        {
        case TETerrainShardData.ElementType.Far:        return(farMaterial);

        case TETerrainShardData.ElementType.Default: return(defaultMaterial);

        case TETerrainShardData.ElementType.Near:       return(nearMaterial);

        default: return(null);
        }
    }
示例#2
0
    public Mesh GetMesh(TETerrainShardData.ElementType meshType, TETerrainShardRenderElement renderElement, TETerrainShardData shardData, int edgeLength, int edgeQuadCount, Vector4 uvScaleOffset, bool forceUpdateHeight, bool forceUpdateNormal, string label, bool isTemp)
    {
        if (isTemp)
        {
            return(CreateMesh(shardData, edgeLength, edgeQuadCount, false, uvScaleOffset, label));
        }

        MeshSet meshSet = null;

        if (!m_renderElementMeshMap.TryGetValue(renderElement.elementHash, out meshSet))
        {
            meshSet        = m_renderElementMeshMap[renderElement.elementHash] = new MeshSet();
            meshSet.meshes = new MeshInfo[3];
        }

        MeshInfo meshInfo = meshSet.meshes[(int)meshType];

        if (meshInfo != null && meshInfo.mesh)
        {
            if (meshInfo.edgeLen == edgeLength && meshInfo.edgeQuads == edgeQuadCount && meshInfo.uvScaleOffset == uvScaleOffset)
            {
                if (forceUpdateHeight || forceUpdateNormal)
                {
                    UpdateMesh(meshInfo.mesh, shardData, edgeLength, edgeQuadCount, false, uvScaleOffset, forceUpdateHeight, forceUpdateNormal);

#if UNITY_EDITOR
                    UnityEditor.EditorUtility.SetDirty(this);
#endif
                }
                return(meshInfo.mesh);
            }

            Object.DestroyImmediate(meshInfo.mesh, true);
        }

        meshInfo = meshSet.meshes[(int)meshType] = CreateMeshInfo(shardData, edgeLength, edgeQuadCount, false /*meshType != TETerrainShardData.ElementType.Far*/, uvScaleOffset, label);

#if UNITY_EDITOR
        UnityEditor.AssetDatabase.AddObjectToAsset(meshInfo.mesh, this);
        UnityEditor.EditorUtility.SetDirty(this);
#endif

        return(meshInfo.mesh);
    }
    public void RebindMaterial(TETerrainShardData.ElementType kind, MaterialPropertyBlock mpb)
    {
        if (textureSets == null || textureSets.Length == 0 || albedoTextureArray == null)
        {
            return;
        }

        if (kind == TETerrainShardData.ElementType.Default)
        {
            var detailLayersCount = detailLayers.Length;

            var u_DetailLayersAlbedoTint              = new Vector4[detailLayersCount];
            var u_DetailLayersSpecularTint            = new Vector4[detailLayersCount];
            var u_DetailLayersSmtNrmDspOccScales      = new Vector4[detailLayersCount];
            var u_DetailLayersDisplacementScaleOffset = new Vector4[detailLayersCount];
            var u_DetailLayersUVScaleArrayMultiIndex  = new Vector4[detailLayersCount];
            var u_DetailLayersSlopeThresholds         = new Vector4[detailLayersCount];

            for (int i = 0; i < detailLayersCount; ++i)
            {
                var dl = detailLayers[i];
                var ts = TextureSetFromGuid(dl.textureSet);

                u_DetailLayersAlbedoTint[i]              = ts.albedoTint.linear * ts.albedoTintScale * dl.textureAlbedoTint.linear;
                u_DetailLayersSpecularTint[i]            = ts.specularTint.linear * ts.specularTintScale * dl.textureSpecularTint.linear;
                u_DetailLayersSmtNrmDspOccScales[i]      = new Vector4(ts.smoothnessScale * dl.textureSmoothnessScale, ts.normalScale * dl.textureNormalScale, ts.displacementScale * dl.textureDisplacementScale, ts.occlusionScale * dl.textureOcclusionScale);
                u_DetailLayersDisplacementScaleOffset[i] = new Vector4(ts.displacementScale * dl.textureDisplacementScale, ts.displacementOffset + dl.textureDisplacementOffset, ts.displacementGeomScale * dl.textureDisplacementGeomScale, 0f);
                u_DetailLayersUVScaleArrayMultiIndex[i]  = new Vector4(-1f / (ts.uvScale * dl.textureUVScale.x), dl.textureUVTileRotation ? 1.5f : 0f, 0.25f + (float)TextureSetIndexFromGuid(dl.textureSet), dl.textureUVMultiProjection ? 1.5f : 0f);
                u_DetailLayersSlopeThresholds[i]         = RemapTreshold(dl.slopeThreshold);
            }
            mpb.SetVectorArray("u_DetailLayersAlbedoTint", u_DetailLayersAlbedoTint);
            mpb.SetVectorArray("u_DetailLayersSpecularTint", u_DetailLayersSpecularTint);
            mpb.SetVectorArray("u_DetailLayersSmtNrmDspOccScales", u_DetailLayersSmtNrmDspOccScales);
            mpb.SetVectorArray("u_DetailLayersDisplacementScaleOffset", u_DetailLayersDisplacementScaleOffset);
            mpb.SetVectorArray("u_DetailLayersUVScaleArrayMultiIndex", u_DetailLayersUVScaleArrayMultiIndex);
            mpb.SetVectorArray("u_DetailLayersSlopeThresholds", u_DetailLayersSlopeThresholds);
        }
    }