internal static void RenderAndWriteToFile( HDProbe probe, string targetFile, RenderTexture cubeRT, RenderTexture planarRT, out CameraSettings cameraSettings, out CameraPositionSettings cameraPositionSettings ) { var settings = probe.settings; switch (settings.type) { case ProbeSettings.ProbeType.ReflectionProbe: { var positionSettings = ProbeCapturePositionSettings.ComputeFrom(probe, null); HDRenderUtilities.Render(probe.settings, positionSettings, cubeRT, out cameraSettings, out cameraPositionSettings, forceFlipY: true, forceInvertBackfaceCulling: true, // Cubemap have an RHS standard, so we need to invert the face culling (uint)StaticEditorFlags.ReflectionProbeStatic ); HDBakingUtilities.CreateParentDirectoryIfMissing(targetFile); Checkout(targetFile); HDTextureUtilities.WriteTextureFileToDisk(cubeRT, targetFile); break; } case ProbeSettings.ProbeType.PlanarProbe: { var planarProbe = (PlanarReflectionProbe)probe; var positionSettings = ProbeCapturePositionSettings.ComputeFromMirroredReference( probe, planarProbe.referencePosition ); HDRenderUtilities.Render( settings, positionSettings, planarRT, out cameraSettings, out cameraPositionSettings ); HDBakingUtilities.CreateParentDirectoryIfMissing(targetFile); Checkout(targetFile); HDTextureUtilities.WriteTextureFileToDisk(planarRT, targetFile); var renderData = new HDProbe.RenderData(cameraSettings, cameraPositionSettings); var targetRenderDataFile = targetFile + ".renderData"; Checkout(targetRenderDataFile); HDBakingUtilities.TrySerializeToDisk(renderData, targetRenderDataFile); break; } default: throw new ArgumentOutOfRangeException(nameof(probe.settings.type)); } }
static void ComputeProbeSettingsHashes(IList <HDProbe> probes, HDProbeBakingState *states) { for (int i = 0; i < probes.Count; ++i) { var probe = probes[i]; var positionSettings = ProbeCapturePositionSettings.ComputeFrom(probe, null); var positionSettingsHash = positionSettings.ComputeHash(); // TODO: make ProbeSettings and unmanaged type so its hash can be the hash of its memory var probeSettingsHash = probe.settings.ComputeHash(); HashUtilities.AppendHash(ref positionSettingsHash, ref probeSettingsHash); states[i].probeSettingsHash = probeSettingsHash; } }
static void ComputeProbeSettingsHashes(IEnumerable <HDProbe> probes, HDProbeBakingState *states) { var i = 0; foreach (var probe in probes) { var positionSettings = ProbeCapturePositionSettings.ComputeFrom(probe, null); var positionSettingsHash = positionSettings.ComputeHash(); // TODO: make ProbeSettings and unmanaged type so its hash can be the hash of its memory var probeSettingsHash = probe.settings.ComputeHash(); HashUtilities.AppendHash(ref positionSettingsHash, ref probeSettingsHash); states[i].probeSettingsHash = probeSettingsHash; ++i; } }
static void Gizmos_CapturePoint(ReflectionProbe target) { if (sphere == null) { sphere = Resources.GetBuiltinResource <Mesh>("New-Sphere.fbx"); } if (material == null) { material = new Material(Shader.Find("Debug/ReflectionProbePreview")); } var probe = target.GetComponent <HDAdditionalReflectionData>(); var probePositionSettings = ProbeCapturePositionSettings.ComputeFrom(probe, null); HDRenderUtilities.ComputeCameraSettingsFromProbeSettings( probe.settings, probePositionSettings, out _, out var cameraPositionSettings ); var capturePosition = cameraPositionSettings.position; material.SetTexture("_Cubemap", probe.texture); material.SetPass(0); Graphics.DrawMeshNow(sphere, Matrix4x4.TRS(capturePosition, Quaternion.identity, Vector3.one * capturePointPreviewSize)); var ray = new Ray(capturePosition, Vector3.down); if (Physics.Raycast(ray, out RaycastHit hit)) { var startPoint = capturePosition - Vector3.up * 0.5f * capturePointPreviewSize; var c = InfluenceVolumeUI.k_GizmoThemeColorBase; c.a = 0.8f; Handles.color = c; Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual; Handles.DrawLine(startPoint, hit.point); Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); c.a = 0.25f; Handles.color = c; Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater; Handles.DrawLine(capturePosition, hit.point); Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); } }