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; } } }
private void UpdateShader() { this.InitializeShaderConstants(); if (Object.op_Equality((Object)this.m_sharedMaterial, (Object)null)) { Debug.LogWarning((object)"CTS Blender Missing Material. Exiting without updating."); } else if (this.m_renderers == null || this.m_renderers.Length == 0) { Debug.LogWarning((object)"CTS Blender Missing Renderer. Exiting without updating."); } else if (this.m_textureList.Count == 0) { Debug.LogWarning((object)"CTS Blender has no textures. Exiting without updating."); } else { if (this.m_materialProperties == null) { this.m_materialProperties = new MaterialPropertyBlock(); } for (int index = 0; index < this.m_renderers.Length; ++index) { this.m_sharedMaterial.SetInt(CTSMeshBlender._Use_AO, !this.m_useAO ? 0 : 1); this.m_sharedMaterial.SetInt(CTSMeshBlender._Use_AO_Texture, !this.m_useAOTexture ? 0 : 1); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Terrain_Specular, this.m_specular); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Terrain_Smoothness, this.m_smoothness); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Geological_Map, (Texture)this.m_geoMap); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Geological_Tiling_Close, this.m_geoTilingClose); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Geological_Map_Offset_Close, this.m_geoMapOffsetClose); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Geological_Map_Close_Power, this.m_geoMapClosePower); if (this.m_textureList.Count >= 1) { CTSMeshBlender.TextureData texture = this.m_textureList[0]; this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Albedo_Sm_1, (Texture)texture.m_albedo); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Normal_1, (Texture)texture.m_normal); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_GHeightAAO_1, (Texture)texture.m_hao_in_GA); this.m_sharedMaterial.SetVector(CTSMeshBlender._Texture_Color_1, texture.m_color); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_Tiling_1, texture.m_tiling); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_Normal_Power, texture.m_normalPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_AO_Power, texture.m_aoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_Geological_Power, texture.m_geoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_Height_Contrast, texture.m_heightContrast); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_Heightmap_Depth, texture.m_heightDepth); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_1_Heightblend_Close, texture.m_heightBlendClose); } if (this.m_textureList.Count >= 2) { CTSMeshBlender.TextureData texture = this.m_textureList[1]; this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Albedo_Sm_2, (Texture)texture.m_albedo); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Normal_2, (Texture)texture.m_normal); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_GHeightAAO_2, (Texture)texture.m_hao_in_GA); this.m_sharedMaterial.SetVector(CTSMeshBlender._Texture_Color_2, texture.m_color); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_Tiling_2, texture.m_tiling); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_Normal_Power, texture.m_normalPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_AO_Power, texture.m_aoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_Geological_Power, texture.m_geoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_Height_Contrast, texture.m_heightContrast); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_Heightmap_Depth, texture.m_heightDepth); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_2_Heightblend_Close, texture.m_heightBlendClose); } if (this.m_textureList.Count >= 3) { CTSMeshBlender.TextureData texture = this.m_textureList[2]; this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Albedo_Sm_3, (Texture)texture.m_albedo); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_Normal_3, (Texture)texture.m_normal); this.m_sharedMaterial.SetTexture(CTSMeshBlender._Texture_GHeightAAO_3, (Texture)texture.m_hao_in_GA); this.m_sharedMaterial.SetVector(CTSMeshBlender._Texture_Color_3, texture.m_color); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_Tiling_3, texture.m_tiling); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_Normal_Power, texture.m_normalPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_AO_Power, texture.m_aoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_Geological_Power, texture.m_geoPower); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_Height_Contrast, texture.m_heightContrast); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_Heightmap_Depth, texture.m_heightDepth); this.m_sharedMaterial.SetFloat(CTSMeshBlender._Texture_3_Heightblend_Close, texture.m_heightBlendClose); } } } }