public Texture2D GetHealthyDryNoiseTexture(GPUInstancerDetailPrototype detailPrototype) { if (detailPrototype.useCustomHealthyDryNoiseTexture && detailPrototype.healthyDryNoiseTexture != null) { return(detailPrototype.healthyDryNoiseTexture); } return(healthyDryNoiseTexture); }
private void UpdateManagers() { for (int i = 0; i < terrainCounter; i++) { GPUInstancerDetailManager detailManager = terrainArray[i].GetComponent <GPUInstancerDetailManager>(); detailManager.terrainSettings.windVector = _windVector; for (int j = 0; j < detailManager.prototypeList.Count; j++) { GPUInstancerDetailPrototype detailPrototype = (GPUInstancerDetailPrototype)detailManager.prototypeList[j]; // noise settings: detailPrototype.detailHealthyColor = _healthyColor; detailPrototype.detailDryColor = _dryColor; detailPrototype.noiseSpread = _noiseSpread; detailPrototype.ambientOcclusion = _ambientOcclusion; detailPrototype.gradientPower = _gradientPower; // wind settings: detailPrototype.windIdleSway = _windIdleSway; detailPrototype.windWavesOn = _windWavesOn; detailPrototype.windWaveTint = _windWaveTint; detailPrototype.windWaveSize = _windWaveSize; detailPrototype.windWaveSway = _windWaveSway; detailPrototype.windWaveTintColor = _windWaveTintColor; // mesh settings: detailPrototype.isBillboard = _useCrossQuads ? false : _isBillboard; detailPrototype.useCrossQuads = _useCrossQuads; detailPrototype.quadCount = _crossQuadCount; detailPrototype.billboardDistance = _crossQuadBillboardDistance; detailPrototype.detailScale = _scale; // GPU Instancer settings detailPrototype.isShadowCasting = _isShadowCasting; detailPrototype.isFrustumCulling = _isFrustumCulling; detailPrototype.frustumOffset = _frustumOffset; detailPrototype.maxDistance = _maxDistance; } GPUInstancerAPI.UpdateDetailInstances(detailManager, true); } }
private void AddInstancer(Terrain terrain) { GPUInstancerDetailManager detailManager = terrain.gameObject.AddComponent <GPUInstancerDetailManager>(); GPUInstancerAPI.SetupManagerWithTerrain(detailManager, terrain); detailManager.terrainSettings.windVector = _windVector; // Can change prototype properties here if (detailManager.prototypeList.Count > 0) { GPUInstancerDetailPrototype detailPrototype = (GPUInstancerDetailPrototype)detailManager.prototypeList[0]; detailPrototype.detailHealthyColor = _healthyColor; detailPrototype.detailDryColor = _dryColor; detailPrototype.noiseSpread = _noiseSpread; detailPrototype.ambientOcclusion = _ambientOcclusion; detailPrototype.gradientPower = _gradientPower; detailPrototype.windIdleSway = _windIdleSway; detailPrototype.windWavesOn = _windWavesOn; detailPrototype.windWaveTint = _windWaveTint; detailPrototype.windWaveSize = _windWaveSize; detailPrototype.windWaveSway = _windWaveSway; detailPrototype.windWaveTintColor = _windWaveTintColor; detailPrototype.isBillboard = _isBillboard; detailPrototype.useCrossQuads = _useCrossQuads; detailPrototype.quadCount = _crossQuadCount; detailPrototype.billboardDistance = _crossQuadBillboardDistance; detailPrototype.detailScale = _scale; detailPrototype.isShadowCasting = _isShadowCasting; detailPrototype.isFrustumCulling = _isFrustumCulling; detailPrototype.frustumOffset = _frustumOffset; detailPrototype.maxDistance = _maxDistance; } GPUInstancerAPI.InitializeGPUInstancer(detailManager); }
private void SetPrototypesByQuality(QualityMode qualityMode) { for (int i = 0; i < detailManager.prototypeList.Count; i++) { GPUInstancerDetailPrototype detailPrototype = (GPUInstancerDetailPrototype)detailManager.prototypeList[i]; switch (qualityMode) { case QualityMode.Low: detailPrototype.isBillboard = !detailPrototype.usePrototypeMesh; detailPrototype.useCrossQuads = false; //detailPrototype.quadCount = 2; //detailPrototype.billboardDistance = 50f; detailPrototype.isShadowCasting = false; detailPrototype.maxDistance = 150f; break; case QualityMode.Mid: detailPrototype.isBillboard = false; detailPrototype.useCrossQuads = !detailPrototype.usePrototypeMesh; detailPrototype.quadCount = 2; //detailPrototype.billboardDistance = 50f; detailPrototype.isShadowCasting = detailPrototype.usePrototypeMesh; detailPrototype.maxDistance = 250; break; case QualityMode.High: detailPrototype.isBillboard = false; detailPrototype.useCrossQuads = !detailPrototype.usePrototypeMesh; detailPrototype.quadCount = 4; //detailPrototype.billboardDistance = 50f; detailPrototype.isShadowCasting = true; detailPrototype.maxDistance = 500; break; } } }
public static void DrawGPUInstancerPrototypeInfo(GPUInstancerPrototype selectedPrototype, UnityAction <string> DrawHelpText, UnityEngine.Object component, UnityAction OnEditorDataChanged, GPUInstancerShaderBindings shaderBindings, GPUInstancerEditorSimulator simulator, GPUInstancerTerrainSettings terrainSettings, int detailLayer) { GPUInstancerDetailPrototype prototype = (GPUInstancerDetailPrototype)selectedPrototype; EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box); GPUInstancerEditorConstants.DrawCustomLabel(GPUInstancerEditorConstants.TEXT_detailProperties, GPUInstancerEditorConstants.Styles.boldLabel); EditorGUI.BeginChangeCheck(); prototype.detailDensity = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_detailDensity, prototype.detailDensity, 0.0f, terrainSettings.detailDensity); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_detailDensity); prototype.detailScale = EditorGUILayout.Vector4Field(GPUInstancerEditorConstants.TEXT_detailScale, prototype.detailScale); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_detailScale); prototype.noiseSpread = EditorGUILayout.FloatField(GPUInstancerEditorConstants.TEXT_noiseSpread, prototype.noiseSpread); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_noiseSpread); prototype.useCustomHealthyDryNoiseTexture = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_useCustomHealthyDryNoiseTexture, prototype.useCustomHealthyDryNoiseTexture); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_useCustomHealthyDryNoiseTexture); if (prototype.useCustomHealthyDryNoiseTexture) { prototype.healthyDryNoiseTexture = (Texture2D)EditorGUILayout.ObjectField(GPUInstancerEditorConstants.TEXT_healthyDryNoiseTexture, prototype.healthyDryNoiseTexture, typeof(Texture2D), false); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_healthyDryNoiseTexture); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(component, "Editor data changed."); if (OnEditorDataChanged != null) { OnEditorDataChanged(); } EditorUtility.SetDirty(prototype); } EditorGUI.BeginChangeCheck(); if (!prototype.usePrototypeMesh) { prototype.useCustomMaterialForTextureDetail = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_useCustomMaterialForTextureDetail, prototype.useCustomMaterialForTextureDetail); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_useCustomMaterialForTextureDetail); if (prototype.useCustomMaterialForTextureDetail) { prototype.textureDetailCustomMaterial = (Material)EditorGUILayout.ObjectField(GPUInstancerEditorConstants.TEXT_textureDetailCustomMaterial, prototype.textureDetailCustomMaterial, typeof(Material), false); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_textureDetailCustomMaterial); prototype.isBillboard = false; } else { prototype.textureDetailCustomMaterial = null; } } EditorGUILayout.EndVertical(); if (!prototype.usePrototypeMesh && !prototype.isBillboard) { EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box); GPUInstancerEditorConstants.DrawCustomLabel(GPUInstancerEditorConstants.TEXT_crossQuads, GPUInstancerEditorConstants.Styles.boldLabel); prototype.useCrossQuads = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_crossQuads, prototype.useCrossQuads); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_crossQuads); if (prototype.useCrossQuads) { prototype.quadCount = EditorGUILayout.IntSlider(GPUInstancerEditorConstants.TEXT_quadCount, prototype.quadCount, 2, 4); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_quadCount); if (!prototype.useCustomMaterialForTextureDetail) { prototype.billboardDistance = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_billboardDistance, prototype.billboardDistance, 0.5f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_billboardDistance); prototype.billboardDistanceDebug = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_billboardDistanceDebug, prototype.billboardDistanceDebug); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_billboardDistanceDebug); if (prototype.billboardDistanceDebug) { prototype.billboardDistanceDebugColor = EditorGUILayout.ColorField(GPUInstancerEditorConstants.TEXT_billboardDistanceDebugColor, prototype.billboardDistanceDebugColor); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_billboardDistanceDebugColor); } prototype.billboardFaceCamPos = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_CQBillboardFaceCamPos, prototype.billboardFaceCamPos); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_CQBillboardFaceCamPos); } } else { prototype.quadCount = 1; } EditorGUILayout.EndVertical(); } else { prototype.useCrossQuads = false; } if (EditorGUI.EndChangeCheck()) { if (!prototype.usePrototypeMesh && prototype.useCustomMaterialForTextureDetail && prototype.textureDetailCustomMaterial != null) { if (!shaderBindings.IsShadersInstancedVersionExists(prototype.textureDetailCustomMaterial.shader.name)) { Shader instancedShader; if (GPUInstancerUtility.IsShaderInstanced(prototype.textureDetailCustomMaterial.shader)) { instancedShader = prototype.textureDetailCustomMaterial.shader; } else { instancedShader = GPUInstancerUtility.CreateInstancedShader(prototype.textureDetailCustomMaterial.shader, shaderBindings); } if (instancedShader != null) { shaderBindings.AddShaderInstance(prototype.textureDetailCustomMaterial.shader.name, instancedShader); } else { Debug.LogWarning("Can not create instanced version for shader: " + prototype.textureDetailCustomMaterial.shader.name + ". Standard Shader will be used instead."); } } } EditorUtility.SetDirty(prototype); } if (!prototype.usePrototypeMesh && !prototype.useCustomMaterialForTextureDetail) { EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box); GPUInstancerEditorConstants.DrawCustomLabel(GPUInstancerEditorConstants.TEXT_foliageShaderProperties, GPUInstancerEditorConstants.Styles.boldLabel); EditorGUI.BeginChangeCheck(); prototype.isBillboard = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_isBillboard, prototype.isBillboard); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_isBillboard); if (prototype.isBillboard) { prototype.billboardFaceCamPos = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_billboardFaceCamPos, prototype.billboardFaceCamPos); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_billboardFaceCamPos); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(prototype); if (simulator != null && simulator.simulateAtEditor && !simulator.initializingInstances) { GPUInstancerUtility.UpdateDetailInstanceRuntimeDataList(simulator.gpuiManager.runtimeDataList, terrainSettings, false, detailLayer); } } EditorGUI.BeginChangeCheck(); prototype.detailHealthyColor = EditorGUILayout.ColorField(GPUInstancerEditorConstants.TEXT_detailHealthyColor, prototype.detailHealthyColor); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_detailHealthyColor); prototype.detailDryColor = EditorGUILayout.ColorField(GPUInstancerEditorConstants.TEXT_detailDryColor, prototype.detailDryColor); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_detailDryColor); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(component, "Editor data changed."); if (OnEditorDataChanged != null) { OnEditorDataChanged(); } if (simulator != null && simulator.simulateAtEditor && !simulator.initializingInstances) { GPUInstancerUtility.UpdateDetailInstanceRuntimeDataList(simulator.gpuiManager.runtimeDataList, terrainSettings, false, detailLayer); } EditorUtility.SetDirty(prototype); } EditorGUI.BeginChangeCheck(); prototype.ambientOcclusion = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_ambientOcclusion, prototype.ambientOcclusion, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_ambientOcclusion); prototype.gradientPower = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_gradientPower, prototype.gradientPower, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_gradientPower); GPUInstancerEditorConstants.DrawCustomLabel(GPUInstancerEditorConstants.TEXT_windSettings, GPUInstancerEditorConstants.Styles.boldLabel); prototype.windIdleSway = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_windIdleSway, prototype.windIdleSway, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windIdleSway); prototype.windWavesOn = EditorGUILayout.Toggle(GPUInstancerEditorConstants.TEXT_windWavesOn, prototype.windWavesOn); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windWavesOn); if (prototype.windWavesOn) { prototype.windWaveTintColor = EditorGUILayout.ColorField(GPUInstancerEditorConstants.TEXT_windWaveTintColor, prototype.windWaveTintColor); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windWaveTintColor); prototype.windWaveSize = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_windWaveSize, prototype.windWaveSize, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windWaveSize); prototype.windWaveTint = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_windWaveTint, prototype.windWaveTint, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windWaveTint); prototype.windWaveSway = EditorGUILayout.Slider(GPUInstancerEditorConstants.TEXT_windWaveSway, prototype.windWaveSway, 0f, 1f); DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_windWaveSway); } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(prototype); if (simulator != null && simulator.simulateAtEditor && !simulator.initializingInstances) { GPUInstancerUtility.UpdateDetailInstanceRuntimeDataList(simulator.gpuiManager.runtimeDataList, terrainSettings, false, detailLayer); } } EditorGUILayout.EndVertical(); } }
private void MapMagicTerrainAddDetailManager(Terrain terrain) { if (terrain.GetComponent <GPUInstancerDetailManager>() == null && detailPrototypes != null && detailPrototypes.Count > 0) { GPUInstancerDetailManager newDetailManager = terrain.gameObject.AddComponent <GPUInstancerDetailManager>(); newDetailManager.isFrustumCulling = isFrustumCulling; newDetailManager.isOcclusionCulling = isOcclusionCulling; newDetailManager.minCullingDistance = minCullingDistance; newDetailManager.detailLayer = detailLayer; newDetailManager.runInThreads = detailRunInThreads; newDetailManager.autoSelectCamera = autoSelectCamera; newDetailManager.cameraData.SetCamera(cameraData.mainCamera); newDetailManager.cameraData.renderOnlySelectedCamera = cameraData.renderOnlySelectedCamera; newDetailManager.cameraData.hiZOcclusionGenerator = null; newDetailManager.InitializeCameraData(); // for mapmagic detail optimization if (terrain.terrainData.detailPrototypes.Length != detailPrototypes.Count) { int terrainDetailIndex = 0; List <GPUInstancerPrototype> newPrototypeList = new List <GPUInstancerPrototype>(); for (int i = 0; i < detailPrototypes.Count; i++) { if (terrainDetailIndex >= terrain.terrainData.detailPrototypes.Length) { break; } GPUInstancerDetailPrototype dp = (GPUInstancerDetailPrototype)detailPrototypes[i]; if (!terrain.terrainData.detailPrototypes[terrainDetailIndex].usePrototypeMesh && dp.prototypeTexture == terrain.terrainData.detailPrototypes[terrainDetailIndex].prototypeTexture) { newPrototypeList.Add(dp); terrainDetailIndex++; } else if (terrain.terrainData.detailPrototypes[terrainDetailIndex].usePrototypeMesh && dp.prefabObject == terrain.terrainData.detailPrototypes[terrainDetailIndex].prototype) { newPrototypeList.Add(dp); terrainDetailIndex++; } } newDetailManager.prototypeList = newPrototypeList; } else { newDetailManager.prototypeList = detailPrototypes; } newDetailManager.SetupManagerWithTerrain(terrain); newDetailManager.terrainSettings.maxDetailDistance = terrainSettings.maxDetailDistance; newDetailManager.terrainSettings.detailDensity = terrainSettings.detailDensity; newDetailManager.terrainSettings.healthyDryNoiseTexture = terrainSettings.healthyDryNoiseTexture; newDetailManager.terrainSettings.windWaveNormalTexture = terrainSettings.windWaveNormalTexture; newDetailManager.terrainSettings.windVector = terrainSettings.windVector; newDetailManager.terrainSettings.autoSPCellSize = terrainSettings.autoSPCellSize; newDetailManager.terrainSettings.preferedSPCellSize = terrainSettings.preferedSPCellSize; if (terrain.gameObject.activeSelf) { newDetailManager.InitializeRuntimeDataAndBuffers(); } } }