/// <summary> /// Copy constructor - wont duplicate textures tho - just settings and references /// </summary> /// <param name="src">Source object</param> public CTSTerrainTextureDetails(CTSTerrainTextureDetails src) { m_isOpenInEditor = src.m_isOpenInEditor; m_textureIdx = src.m_textureIdx; m_name = src.m_name; m_detailPower = src.m_detailPower; m_snowReductionPower = src.m_snowReductionPower; m_geologicalPower = src.m_geologicalPower; m_triplanar = src.m_triplanar; m_tint = src.m_tint; m_tintBrightness = src.m_tintBrightness; m_smoothness = src.m_smoothness; #if !UNITY_WEBGL m_substanceRegenOnBake = src.m_substanceRegenOnBake; m_substanceWasChanged = src.m_substanceWasChanged; m_substance = src.m_substance; #endif m_albedoIdx = src.m_albedoIdx; m_albedoTilingClose = src.m_albedoTilingClose; m_albedoTilingFar = src.m_albedoTilingFar; m_albedoWasChanged = src.m_albedoWasChanged; m_albedoTexture = src.m_albedoTexture; m_normalIdx = src.m_normalIdx; m_normalStrength = src.m_normalStrength; m_normalWasChanged = src.m_normalWasChanged; m_normalTexture = src.m_normalTexture; m_heightIdx = src.m_heightIdx; m_heightDepth = src.m_heightDepth; m_heightTesselationDepth = src.m_heightTesselationDepth; m_heightContrast = src.m_heightContrast; m_heightBlendClose = src.m_heightBlendClose; m_heightBlendFar = src.m_heightBlendFar; m_heightWasChanged = src.m_heightWasChanged; m_heightTexture = src.m_heightTexture; m_aoIdx = src.m_aoIdx; m_aoPower = src.m_aoPower; m_aoWasChanged = src.m_aoWasChanged; m_aoTexture = src.m_aoTexture; m_emissionIdx = src.m_emissionIdx; m_emissionStrength = src.m_emissionStrength; m_emissionWasChanged = src.m_emissionWasChanged; m_emissionTexture = src.m_emissionTexture; m_smoothness = src.m_smoothness; m_roughnessTexture = src.m_roughnessTexture; }
void CreateCTSProfile() { var CTSpro = new CTSProfile(); CTSpro.name = VegetationPackage.name + " CTSProfile"; CTSpro.TerrainTextures = new List <CTS.CTSTerrainTextureDetails>(); for (int i = 0; i < VegetationPackage.TerrainTextureCount; i++) { var ctsTex = new CTS.CTSTerrainTextureDetails(); ctsTex.Albedo = VegetationPackage.TerrainTextureList[i].Texture; ctsTex.Normal = VegetationPackage.TerrainTextureList[i].TextureNormals; CTSpro.TerrainTextures.Add(ctsTex); } AssetDatabase.CreateAsset(CTSpro, pathMain + "/" + CTSpro.name + ".asset"); VPI[VPI.Length - 1]._CTSProfile = pathMain + "/" + CTSpro.name + ".asset"; CTSProfilePackage = CTSpro; }
private void ConstructNormalsTextureArray() { this.m_needsNormalsArrayUpdate = false; List <Texture2D> sourceTextures = new List <Texture2D>(); int num1 = 0; for (int index = 0; index < this.m_terrainTextures.Count; ++index) { CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index]; if (Object.op_Inequality((Object)terrainTexture.Normal, (Object)null)) { sourceTextures.Add(this.BakeNormal(terrainTexture.Normal)); terrainTexture.m_normalIdx = num1++; } else { terrainTexture.m_normalIdx = -1; } terrainTexture.m_normalWasChanged = false; } if (Object.op_Inequality((Object)this.m_snowNormalTexture, (Object)null)) { sourceTextures.Add(this.BakeNormal(this.m_snowNormalTexture)); this.m_snowNormalTextureIdx = num1++; } else { this.m_snowNormalTextureIdx = -1; } if (Object.op_Implicit((Object)this.m_globalDetailNormalMap)) { sourceTextures.Add(this.BakeNormal(this.m_globalDetailNormalMap)); int num2 = num1; int num3 = num2 + 1; this.m_globalDetailNormalMapIdx = num2; } else { this.m_globalDetailNormalMapIdx = -1; } this.NormalsTextureArray = this.GetTextureArray(sourceTextures, CTSConstants.TextureType.Normal, this.m_normalAniso); }
public void UpdateSettingsFromTerrain(Terrain terrain, bool forceUpdate) { if (Object.op_Equality((Object)terrain, (Object)null) || Object.op_Equality((Object)terrain.get_terrainData(), (Object)null)) { return; } if (forceUpdate) { this.m_needsAlbedosArrayUpdate = true; this.m_needsNormalsArrayUpdate = true; } while (this.m_terrainTextures.Count > terrain.get_terrainData().get_splatPrototypes().Length) { this.m_terrainTextures.RemoveAt(this.m_terrainTextures.Count - 1); this.m_needsAlbedosArrayUpdate = true; this.m_needsNormalsArrayUpdate = true; } SplatPrototype[] splatPrototypes = terrain.get_terrainData().get_splatPrototypes(); for (int index = 0; index < splatPrototypes.Length; ++index) { SplatPrototype splatPrototype = splatPrototypes[index]; if (index < this.m_terrainTextures.Count) { CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index]; terrainTexture.Albedo = splatPrototype.get_texture(); terrainTexture.m_albedoTilingClose = (float)terrain.get_terrainData().get_splatPrototypes()[index].get_tileSize().x; terrainTexture.Normal = splatPrototype.get_normalMap(); } else { this.m_terrainTextures.Add(new CTSTerrainTextureDetails() { m_textureIdx = index, Albedo = terrain.get_terrainData().get_splatPrototypes()[index].get_texture(), m_albedoTilingClose = (float)terrain.get_terrainData().get_splatPrototypes()[index].get_tileSize().x, Normal = terrain.get_terrainData().get_splatPrototypes()[index].get_normalMap() }); } } this.RegenerateArraysIfNecessary(); }
public CTSTerrainTextureDetails(CTSTerrainTextureDetails src) { this.m_isOpenInEditor = src.m_isOpenInEditor; this.m_textureIdx = src.m_textureIdx; this.m_name = src.m_name; this.m_detailPower = src.m_detailPower; this.m_snowReductionPower = src.m_snowReductionPower; this.m_geologicalPower = src.m_geologicalPower; this.m_triplanar = src.m_triplanar; this.m_tint = src.m_tint; this.m_tintBrightness = src.m_tintBrightness; this.m_smoothness = src.m_smoothness; this.m_albedoIdx = src.m_albedoIdx; this.m_albedoTilingClose = src.m_albedoTilingClose; this.m_albedoTilingFar = src.m_albedoTilingFar; this.m_albedoWasChanged = src.m_albedoWasChanged; this.m_albedoTexture = src.m_albedoTexture; this.m_normalIdx = src.m_normalIdx; this.m_normalStrength = src.m_normalStrength; this.m_normalWasChanged = src.m_normalWasChanged; this.m_normalTexture = src.m_normalTexture; this.m_heightIdx = src.m_heightIdx; this.m_heightDepth = src.m_heightDepth; this.m_heightTesselationDepth = src.m_heightTesselationDepth; this.m_heightContrast = src.m_heightContrast; this.m_heightBlendClose = src.m_heightBlendClose; this.m_heightBlendFar = src.m_heightBlendFar; this.m_heightWasChanged = src.m_heightWasChanged; this.m_heightTexture = src.m_heightTexture; this.m_aoIdx = src.m_aoIdx; this.m_aoPower = src.m_aoPower; this.m_aoWasChanged = src.m_aoWasChanged; this.m_aoTexture = src.m_aoTexture; this.m_emissionIdx = src.m_emissionIdx; this.m_emissionStrength = src.m_emissionStrength; this.m_emissionWasChanged = src.m_emissionWasChanged; this.m_emissionTexture = src.m_emissionTexture; this.m_smoothness = src.m_smoothness; this.m_roughnessTexture = src.m_roughnessTexture; }
public void ConstructTerrainReplacementNormals() { if (Application.get_isPlaying()) { return; } while (this.m_replacementTerrainNormals.Count > this.m_terrainTextures.Count) { this.m_replacementTerrainNormals.RemoveAt(this.m_replacementTerrainNormals.Count - 1); } while (this.m_replacementTerrainNormals.Count < this.m_terrainTextures.Count) { this.m_replacementTerrainNormals.Add((Texture2D)null); } string path1 = this.m_ctsDirectory + "Terrains/ReplacementTextures/"; Directory.CreateDirectory(path1); for (int index = 0; index < this.m_terrainTextures.Count; ++index) { CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index]; if (Object.op_Inequality((Object)terrainTexture.Normal, (Object)null)) { string path2 = path1 + ((Object)terrainTexture.Normal).get_name() + "_nrm_cts.png"; if (!File.Exists(path2)) { Texture2D texture2D = CTSProfile.ResizeTexture(terrainTexture.Normal, this.m_normalFormat, this.m_normalAniso, 64, 64, false, true, false); ((Object)texture2D).set_name(((Object)terrainTexture.Normal).get_name() + "_nrm_cts"); this.m_replacementTerrainNormals[index] = texture2D; byte[] png = ImageConversion.EncodeToPNG(this.m_replacementTerrainNormals[index]); File.WriteAllBytes(path2, png); } } else { this.m_replacementTerrainNormals[index] = (Texture2D)null; } } CompleteTerrainShader.SetDirty((Object)this, false, true); }
private void ConstructAlbedosTextureArray() { this.m_needsAlbedosArrayUpdate = false; List <Texture2D> sourceTextures = new List <Texture2D>(); int num1 = 0; byte minHeight; byte maxHeight; for (int index = 0; index < this.m_terrainTextures.Count; ++index) { CTSTerrainTextureDetails terrainTexture = this.m_terrainTextures[index]; if (Object.op_Inequality((Object)terrainTexture.Albedo, (Object)null)) { Texture2D texture2D = !Object.op_Equality((Object)terrainTexture.Smoothness, (Object)null) || !Object.op_Equality((Object)terrainTexture.Roughness, (Object)null) ? this.BakeAlbedo(terrainTexture.Albedo, terrainTexture.Smoothness, terrainTexture.Roughness) : (!this.m_albedoCompress ? CTSProfile.ResizeTexture(terrainTexture.Albedo, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, false) : CTSProfile.ResizeTexture(terrainTexture.Albedo, this.m_albedoFormat, this.m_albedoAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, true)); sourceTextures.Add(texture2D); Color linear = ((Color) ref texture2D.GetPixels(texture2D.get_mipmapCount() - 1)[0]).get_linear(); terrainTexture.m_albedoAverage = new Vector4((float)linear.r, (float)linear.g, (float)linear.b, (float)linear.a); terrainTexture.m_albedoIdx = num1++; if ((this.m_shaderType == CTSConstants.ShaderType.Advanced || this.m_shaderType == CTSConstants.ShaderType.Tesselation) && (Object.op_Inequality((Object)terrainTexture.Height, (Object)null) || Object.op_Inequality((Object)terrainTexture.AmbientOcclusion, (Object)null))) { sourceTextures.Add(this.BakeHAOTexture(terrainTexture.m_name, terrainTexture.Height, terrainTexture.AmbientOcclusion, out minHeight, out maxHeight)); if (Object.op_Inequality((Object)terrainTexture.Height, (Object)null)) { terrainTexture.m_heightIdx = num1; terrainTexture.m_heightMin = (float)minHeight / (float)byte.MaxValue; terrainTexture.m_heightMax = (float)maxHeight / (float)byte.MaxValue; } else { terrainTexture.m_heightIdx = -1; } terrainTexture.m_aoIdx = !Object.op_Inequality((Object)terrainTexture.AmbientOcclusion, (Object)null) ? -1 : num1; ++num1; } else { terrainTexture.m_aoIdx = -1; terrainTexture.m_heightIdx = -1; } } else { terrainTexture.m_albedoIdx = -1; } terrainTexture.m_albedoWasChanged = false; } if (Object.op_Inequality((Object)this.m_snowAlbedoTexture, (Object)null)) { Texture2D texture2D = !this.m_albedoCompress ? CTSProfile.ResizeTexture(this.m_snowAlbedoTexture, this.m_albedoFormat, this.m_normalAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, false) : CTSProfile.ResizeTexture(this.m_snowAlbedoTexture, this.m_albedoFormat, this.m_normalAniso, this.m_albedoTextureSizePx, this.m_albedoTextureSizePx, true, false, true); Color linear = ((Color) ref texture2D.GetPixels(texture2D.get_mipmapCount() - 1)[0]).get_linear(); this.m_snowAverage = new Vector4((float)linear.r, (float)linear.g, (float)linear.b, (float)linear.a); sourceTextures.Add(texture2D); this.m_snowAlbedoTextureIdx = num1++; } else { this.m_snowAlbedoTextureIdx = -1; } if (Object.op_Inequality((Object)this.m_snowHeightTexture, (Object)null) || Object.op_Inequality((Object)this.m_snowAOTexture, (Object)null)) { sourceTextures.Add(this.BakeHAOTexture("CTS_SnowHAO", this.m_snowHeightTexture, this.m_snowAOTexture, out minHeight, out maxHeight)); if (Object.op_Inequality((Object)this.m_snowHeightTexture, (Object)null)) { this.m_snowHeightTextureIdx = num1; this.m_snowHeightmapMinValue = (float)minHeight / (float)byte.MaxValue; this.m_snowHeightmapMaxValue = (float)maxHeight / (float)byte.MaxValue; } else { this.m_snowHeightTextureIdx = -1; this.m_snowHeightmapMinValue = 0.0f; this.m_snowHeightmapMaxValue = 1f; } this.m_snowAOTextureIdx = !Object.op_Inequality((Object)this.m_snowAOTexture, (Object)null) ? -1 : num1; int num2 = num1 + 1; } else { this.m_snowAOTextureIdx = -1; this.m_snowHeightTextureIdx = -1; } this.AlbedosTextureArray = this.GetTextureArray(sourceTextures, CTSConstants.TextureType.Albedo, this.m_albedoAniso); }
private void GetTexturesAndSettingsAtCurrentLocation() { this.m_textureList.Clear(); CTSProfile ctsProfile = (CTSProfile)null; SplatPrototype[] splatPrototypeArray = new SplatPrototype[0]; Vector3 position = ((Component)this).get_transform().get_position(); Vector3 localScale = ((Component)this).get_transform().get_localScale(); Vector3 eulerAngles = ((Component)this).get_transform().get_eulerAngles(); for (int index1 = this.m_filters.Length - 1; index1 >= 0; --index1) { Mesh sharedMesh = this.m_filters[index1].get_sharedMesh(); if (Object.op_Inequality((Object)sharedMesh, (Object)null)) { Vector3[] vertices = sharedMesh.get_vertices(); for (int index2 = vertices.Length - 1; index2 >= 0; --index2) { Vector3 locationWU = Vector3.op_Addition(position, Quaternion.op_Multiply(Quaternion.Euler(eulerAngles), Vector3.Scale(vertices[index2], localScale))); Terrain terrain = this.GetTerrain(locationWU); if (Object.op_Inequality((Object)terrain, (Object)null)) { if (Object.op_Equality((Object)ctsProfile, (Object)null)) { CompleteTerrainShader component = (CompleteTerrainShader)((Component)terrain).get_gameObject().GetComponent <CompleteTerrainShader>(); if (Object.op_Inequality((Object)component, (Object)null)) { ctsProfile = component.Profile; } } if (splatPrototypeArray.Length == 0) { splatPrototypeArray = terrain.get_terrainData().get_splatPrototypes(); } Vector3 localPosition = this.GetLocalPosition(terrain, locationWU); float[,,] texturesAtLocation = this.GetTexturesAtLocation(terrain, localPosition); for (int index3 = 0; index3 < texturesAtLocation.GetLength(2); ++index3) { if (index3 == this.m_textureList.Count) { this.m_textureList.Add(new CTSMeshBlender.TextureData() { m_terrainIdx = index3, m_terrainTextureStrength = texturesAtLocation[0, 0, index3] }); } else { this.m_textureList[index3].m_terrainTextureStrength += texturesAtLocation[0, 0, index3]; } } } } } } List <CTSMeshBlender.TextureData> list = this.m_textureList.OrderByDescending <CTSMeshBlender.TextureData, float>((Func <CTSMeshBlender.TextureData, float>)(x => x.m_terrainTextureStrength)).ToList <CTSMeshBlender.TextureData>(); while (list.Count > 3) { list.RemoveAt(list.Count - 1); } this.m_textureList = list.OrderBy <CTSMeshBlender.TextureData, int>((Func <CTSMeshBlender.TextureData, int>)(x => x.m_terrainIdx)).ToList <CTSMeshBlender.TextureData>(); if (Object.op_Inequality((Object)ctsProfile, (Object)null)) { this.m_geoMap = ctsProfile.GeoAlbedo; this.m_geoMapClosePower = ctsProfile.m_geoMapClosePower; this.m_geoMapOffsetClose = ctsProfile.m_geoMapCloseOffset; this.m_geoTilingClose = ctsProfile.m_geoMapTilingClose; this.m_smoothness = ctsProfile.m_globalTerrainSmoothness; this.m_specular = ctsProfile.m_globalTerrainSpecular; switch (ctsProfile.m_globalAOType) { case CTSConstants.AOType.None: this.m_useAO = false; this.m_useAOTexture = false; break; case CTSConstants.AOType.NormalMapBased: this.m_useAO = true; this.m_useAOTexture = false; break; case CTSConstants.AOType.TextureBased: this.m_useAO = true; this.m_useAOTexture = true; break; } } else { this.m_geoMap = (Texture2D)null; this.m_geoMapClosePower = 0.0f; this.m_geoMapOffsetClose = 0.0f; this.m_geoTilingClose = 0.0f; this.m_smoothness = 1f; this.m_specular = 1f; this.m_useAO = true; this.m_useAOTexture = false; } byte minHeight = 0; byte maxHeight = 0; for (int index = 0; index < this.m_textureList.Count; ++index) { CTSMeshBlender.TextureData texture = this.m_textureList[index]; if (Object.op_Inequality((Object)ctsProfile, (Object)null) && texture.m_terrainIdx < ctsProfile.TerrainTextures.Count) { CTSTerrainTextureDetails terrainTexture = ctsProfile.TerrainTextures[texture.m_terrainIdx]; texture.m_albedo = terrainTexture.Albedo; texture.m_normal = terrainTexture.Normal; texture.m_hao_in_GA = ctsProfile.BakeHAOTexture(((Object)terrainTexture.Albedo).get_name(), terrainTexture.Height, terrainTexture.AmbientOcclusion, out minHeight, out maxHeight); texture.m_aoPower = terrainTexture.m_aoPower; texture.m_color = new Vector4((float)terrainTexture.m_tint.r * terrainTexture.m_tintBrightness, (float)terrainTexture.m_tint.g * terrainTexture.m_tintBrightness, (float)terrainTexture.m_tint.b * terrainTexture.m_tintBrightness, terrainTexture.m_smoothness); texture.m_geoPower = terrainTexture.m_geologicalPower; texture.m_normalPower = terrainTexture.m_normalStrength; texture.m_tiling = terrainTexture.m_albedoTilingClose; texture.m_heightContrast = terrainTexture.m_heightContrast; texture.m_heightDepth = terrainTexture.m_heightDepth; texture.m_heightBlendClose = terrainTexture.m_heightBlendClose; } else if (texture.m_terrainIdx < splatPrototypeArray.Length) { SplatPrototype splatPrototype = splatPrototypeArray[texture.m_terrainIdx]; texture.m_albedo = splatPrototype.get_texture(); texture.m_normal = splatPrototype.get_normalMap(); texture.m_hao_in_GA = (Texture2D)null; texture.m_aoPower = 0.0f; texture.m_color = Vector4.get_one(); texture.m_geoPower = 0.0f; texture.m_normalPower = 1f; texture.m_tiling = (float)splatPrototype.get_tileSize().x; texture.m_heightContrast = 1f; texture.m_heightDepth = 1f; texture.m_heightBlendClose = 1f; } } }