public void Update() { if (target == null) { Volume tempVolume = GetComponent <Volume>(); foreach (VolumeComponent tempComponent in tempVolume.sharedProfile.components) { target = tempComponent as IndirectLightingController; if (target != null) { break; } } } else { target.active = ifOpen; target.indirectDiffuseLightingMultiplier.value = diffuseLight; target.reflectionLightingMultiplier.value = reflectionLight; } }
public static void RenderScenePreview(Transform origin, PreviewTextures textures, bool forcePreview) { var pos = origin.position; var rot = origin.rotation; ReinitializeRenderPipeline(); var hasReflectionProbes = Object.FindObjectOfType <ReflectionProbe>() != null; var volumes = Object.FindObjectsOfType <Volume>(); Volume volume = null; IndirectLightingController indirectLightingController = null; foreach (var vol in volumes) { if (vol.isGlobal && volume == null) { volume = vol; continue; } var collider = vol.GetComponent <Collider>(); if (collider.bounds.Contains(pos)) { volume = vol; break; } } var previewRootPrefab = AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Prefabs/ScenePreviewRoot.prefab"); var previewRoot = Object.Instantiate(previewRootPrefab, pos, rot); var camera = previewRoot.GetComponentInChildren <Camera>(); if (forcePreview) { previewRoot.transform.SetPositionAndRotation(pos, Quaternion.Euler(new Vector3(0f, rot.eulerAngles.y, 0f))); camera.transform.SetParent(null); camera.transform.SetPositionAndRotation(pos, rot); } // This will trigger HDCamera.Update, which must be done before calling HDCamera.GetOrCreate // Otherwise m_AdditionalCameraData will not be set and HDCamera will be discarded after first frame camera.Render(); var hdSettings = camera.GetComponent <HDAdditionalCameraData>(); hdSettings.hasPersistentHistory = true; var hd = HDCamera.GetOrCreate(camera); if (volume == null) { volume = previewRoot.GetComponentInChildren <Volume>(); } // CullingResults in first frame after loading scene does not contain aby data about reflection probes. // Light loop will use further options, which usually means skybox indirect reflections. This ignores // occlusion and will break interior lighting. Due to lack of other options, just disable indirect specular // lighting for preview rendering. indirectLightingController = volume.profile.components.FirstOrDefault(x => x is IndirectLightingController) as IndirectLightingController; var indirectControllerAdded = hasReflectionProbes && indirectLightingController == null; if (indirectControllerAdded) { indirectLightingController = volume.profile.Add <IndirectLightingController>(); } var indirectMultiplier = indirectLightingController == null ? 0f : indirectLightingController.reflectionLightingMultiplier.value; if (hasReflectionProbes && indirectLightingController != null) { indirectLightingController.reflectionLightingMultiplier.value = 0f; } var pointCloudRenderers = Object.FindObjectsOfType <NodeTreeRenderer>(); foreach (var pointCloudRenderer in pointCloudRenderers) { pointCloudRenderer.UpdateImmediate(camera); } Render(hd, textures, volume); if (hasReflectionProbes && indirectLightingController != null) { indirectLightingController.reflectionLightingMultiplier.value = indirectMultiplier; } if (indirectControllerAdded && indirectLightingController != null) { volume.profile.Remove <IndirectLightingController>(); } Object.DestroyImmediate(previewRoot); }