Esempio n. 1
0
    public IEnumerator RefreshInstant(RenderTexture renderTex, RenderTexture mirrorTex)
    {
        CreateCubemap();
        yield return(null);

        for (int face = 0; face < 6; face++)
        {
            renderCam.transform.rotation = orientations[face];
            renderCam.Render();
            Graphics.Blit(renderTex, mirrorTex, mirror);
            Graphics.CopyTexture(mirrorTex, 0, 0, cubemap, face, 0);
        }

        ConvolutionCubemap();
#if ENVIRO_HDRP
        hdprobe.SetTexture(ProbeSettings.Mode.Custom, finalCubemap);
#else
        myProbe.customBakedTexture = finalCubemap;
#endif
        refreshing = null;
    }
Esempio n. 2
0
        /// <summary>
        ///     Bakes the <paramref name="probe" /> and updates its baked texture.
        ///
        ///     Note: The update of the probe is persistent only in editor mode.
        /// </summary>
        /// <param name="probe">The probe to bake.</param>
        /// <param name="path">The asset path to write the baked texture to.</param>
        /// <param name="options">The options to use for the bake.</param>
        /// <returns>
        ///     Returns <c>null</c> if successful. Otherwise, returns the error that occured.
        ///     The error can be:
        ///     * <see cref="ArgumentException" /> if the <paramref name="path" /> is invalid.
        ///     * <see cref="ArgumentNullException" /> if the <paramref name="probe" /> is <c>null</c>.
        ///     * <see cref="Exception" /> if the <paramref name="probe" /> is not supported. Only
        ///     This functional currently only supports <see cref="HDAdditionalReflectionData" /> probes.
        /// </returns>
        public static Exception BakeProbe([NotNull] HDProbe probe, [NotNull] string path, BakeProbeOptions options)
        {
            // Check arguments
            if (probe == null || probe.Equals(null))
            {
                return(new ArgumentNullException(nameof(probe)));
            }
            if (string.IsNullOrEmpty(path))
            {
                return(new ArgumentException($"{nameof(path)} must not be empty or null."));
            }

            // We force RGBAHalf as we don't support 11-11-10 textures (only RT)
            var probeFormat = GraphicsFormat.R16G16B16A16_SFloat;

            switch (probe)
            {
            case HDAdditionalReflectionData _:
            {
                // Get the texture size from the probe
                var textureSize = options.textureSize.Evaluate(probe);

                // Render and write
                var cubeRT = HDRenderUtilities.CreateReflectionProbeRenderTarget(textureSize, probeFormat);
                HDBakedReflectionSystem.RenderAndWriteToFile(probe, path, cubeRT, null);
                cubeRT.Release();

                // Import asset at target location
                AssetDatabase.ImportAsset(path);
                HDBakedReflectionSystem.ImportAssetAt(probe, path);

                // Assign to the probe the baked texture
                var bakedTexture = AssetDatabase.LoadAssetAtPath <Texture>(path);
                probe.SetTexture(ProbeSettings.Mode.Baked, bakedTexture);

                // Mark probe as dirty
                EditorUtility.SetDirty(probe);

                return(null);
            }

            case PlanarReflectionProbe _:
                return(new Exception("Planar reflection probe baking is not supported."));

            default: return(new Exception($"Cannot handle probe type: {probe.GetType()}"));
            }
        }
Esempio n. 3
0
            static void RenderInCustomAsset(HDProbe probe, bool useExistingCustomAsset)
            {
                var provider = new TProvider();

                string assetPath = null;

                if (useExistingCustomAsset && probe.customTexture != null && !probe.customTexture.Equals(null))
                {
                    assetPath = AssetDatabase.GetAssetPath(probe.customTexture);
                }

                if (string.IsNullOrEmpty(assetPath))
                {
                    assetPath = EditorUtility.SaveFilePanelInProject(
                        "Save custom capture",
                        probe.name, "exr",
                        "Save custom capture");
                }

                if (!string.IsNullOrEmpty(assetPath))
                {
                    var target = HDProbeSystem.CreateRenderTargetForMode(
                        probe, ProbeSettings.Mode.Custom
                        );
                    HDProbeSystem.Render(
                        probe, null, target,
                        out HDProbe.RenderData renderData,
                        forceFlipY: probe.type == ProbeSettings.ProbeType.ReflectionProbe
                        );
                    HDTextureUtilities.WriteTextureFileToDisk(target, assetPath);
                    AssetDatabase.ImportAsset(assetPath);
                    HDBakedReflectionSystem.ImportAssetAt(probe, assetPath);
                    CoreUtils.Destroy(target);

                    var assetTarget = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);
                    probe.SetTexture(ProbeSettings.Mode.Custom, assetTarget);
                    probe.SetRenderData(ProbeSettings.Mode.Custom, renderData);
                    EditorUtility.SetDirty(probe);
                }
            }
            static void RenderInCustomAsset(HDProbe probe, bool useExistingCustomAsset)
            {
                var provider = new TProvider();

                string assetPath = null;

                if (useExistingCustomAsset && probe.customTexture != null && !probe.customTexture.Equals(null))
                {
                    assetPath = AssetDatabase.GetAssetPath(probe.customTexture);
                }

                if (string.IsNullOrEmpty(assetPath))
                {
                    assetPath = EditorUtility.SaveFilePanelInProject(
                        "Save custom capture",
                        probe.name, "exr",
                        "Save custom capture");
                }

                if (!string.IsNullOrEmpty(assetPath))
                {
                    var target = (RenderTexture)HDProbeSystem.CreateRenderTargetForMode(
                        probe, ProbeSettings.Mode.Custom
                        );


                    HDBakedReflectionSystem.RenderAndWriteToFile(
                        probe, assetPath, target, null,
                        out var cameraSettings, out var cameraPositionSettings
                        );
                    AssetDatabase.ImportAsset(assetPath);
                    HDBakedReflectionSystem.ImportAssetAt(probe, assetPath);
                    CoreUtils.Destroy(target);

                    var assetTarget = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);
                    probe.SetTexture(ProbeSettings.Mode.Custom, assetTarget);
                    probe.SetRenderData(ProbeSettings.Mode.Custom, new HDProbe.RenderData(cameraSettings, cameraPositionSettings));
                    EditorUtility.SetDirty(probe);
                }
            }