Exemplo n.º 1
0
        public void InitData(RenderPipelineResources renderPipelineResources)
        {
            m_DebugLightVolumeMaterial       = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.debugLightVolumePS);
            m_DebugLightVolumeCompute        = renderPipelineResources.shaders.debugLightVolumeCS;
            m_DebugLightVolumeGradientKernel = m_DebugLightVolumeCompute.FindKernel("LightVolumeGradient");
            m_DebugLightVolumeColorsKernel   = m_DebugLightVolumeCompute.FindKernel("LightVolumeColors");
            m_ColorGradientTexture           = renderPipelineResources.textures.colorGradient;

            m_Blit = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.blitPS);

            m_LightCountBuffer         = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeCount");
            m_ColorAccumulationBuffer  = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeColorAccumulation");
            m_DebugLightVolumesTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useMipMap: false, name: "LightVolumeDebugLightVolumesTexture");
            m_DepthBuffer = RTHandles.Alloc(Vector2.one, depthBufferBits: DepthBits.None, colorFormat: GraphicsFormat.R8_UNorm, filterMode: FilterMode.Point, name: "LightVolumeDepth");
            // Fill the render target array
            m_RTIDs[0] = m_LightCountBuffer;
            m_RTIDs[1] = m_ColorAccumulationBuffer;
        }
Exemplo n.º 2
0
        public void Initialize(RenderPipelineResources resources, HDRaytracingManager raytracingManager, SharedRTManager sharedRTManager, LightLoop lightLoop)
        {
            // Keep track of the external buffers
            m_RenderPipelineResources = resources;
            m_RaytracingManager       = raytracingManager;

            // Keep track of the lightloop
            m_LightLoop = lightLoop;

            // Keep track of the shader rt manager
            m_SharedRTManager = sharedRTManager;

            // Texture used to output debug information
            m_DebugLightClusterTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R16G16B16A16_SFloat), enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "DebugLightClusterTexture");

            // Pre allocate the cluster with a dummy size
            m_LightCluster = new ComputeBuffer(1, sizeof(uint));
        }
Exemplo n.º 3
0
 void CheckIntermediateTexturesSize(int texWidth, int texHeight)
 {
     // If the first texture is not the right size
     if (m_PlanarReflectionFilterTex0 == null || m_PlanarReflectionFilterTex0.rt.width < texWidth)
     {
         var hdPipeline  = (HDRenderPipeline)RenderPipelineManager.currentPipeline;
         var probeFormat = (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.lightLoopSettings.reflectionProbeFormat;
         // We re-allocate them all
         RTHandles.Release(m_PlanarReflectionFilterTex0);
         RTHandles.Release(m_PlanarReflectionFilterTex1);
         RTHandles.Release(m_PlanarReflectionFilterDepthTex0);
         RTHandles.Release(m_PlanarReflectionFilterDepthTex1);
         m_PlanarReflectionFilterTex0      = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: probeFormat, enableRandomWrite: true, useDynamicScale: false, useMipMap: true, name: "PlanarReflectionTextureIntermediate0");
         m_PlanarReflectionFilterTex1      = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: probeFormat, enableRandomWrite: true, useDynamicScale: false, useMipMap: false, name: "PlanarReflectionTextureIntermediate1");
         m_PlanarReflectionFilterDepthTex0 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: true, name: "PlanarReflectionTextureIntermediateDepth0");
         m_PlanarReflectionFilterDepthTex1 = RTHandles.Alloc(texWidth, texHeight, TextureXR.slices, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: true, useDynamicScale: false, useMipMap: false, name: "PlanarReflectionTextureIntermediateDepth1");
     }
 }
Exemplo n.º 4
0
    // It can be used to configure render targets and their clear state. Also to create temporary render target textures.
    // When empty this render pass will render to the active camera render target.
    // You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
    // The render pipeline will ensure target setup and clearing happens in an performance manner.
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        blurMaterial        = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/FullScreen/BlurPasses"));
        compositingMaterial = CoreUtils.CreateEngineMaterial(Shader.Find("Hidden/FullScreen/LiquidCompositing"));

        shaderTags = new ShaderTagId[4]
        {
            new ShaderTagId("Forward"),
            new ShaderTagId("ForwardOnly"),
            new ShaderTagId("SRPDefaultUnlit"),
            new ShaderTagId("FirstPass"),
        };

        // Allocate the buffers used for the blur in half resolution to save some memory
        downSampleBuffer = RTHandles.Alloc(
            Vector2.one * 0.5f, TextureXR.slices, dimension: TextureXR.dimension,
            colorFormat: GraphicsFormat.R16G16B16A16_SNorm,
            useDynamicScale: true, name: "DownSampleBuffer"
            );

        blurBuffer = RTHandles.Alloc(
            Vector2.one * 0.5f, TextureXR.slices, dimension: TextureXR.dimension,
            colorFormat: GraphicsFormat.R16G16B16A16_SNorm,
            useDynamicScale: true, name: "BlurBuffer"
            );

        targetColorBuffer = TargetBuffer.Custom;
        targetDepthBuffer = TargetBuffer.Custom;
        clearFlags        = ClearFlag.All;

        quad = new Mesh();
        quad.SetVertices(new List <Vector3> {
            new Vector3(-1, -1, 0),
            new Vector3(1, -1, 0),
            new Vector3(-1, 1, 0),
            new Vector3(1, 1, 0),
        });
        quad.SetTriangles(new List <int> {
            0, 3, 1, 0, 2, 3
        }, 0);
        quad.RecalculateBounds();

        quad.UploadMeshData(false);
    }
Exemplo n.º 5
0
        protected override void DoSetup()
        {
            if (Shader.Find(ShaderName) != null)
            {
                material = new Material(Shader.Find(ShaderName));
            }
            else
            {
                Debug.LogError($"Unable to find shader {ShaderName}. Post Process Volume {nameof(SunFlareFX)} is unable to load.");
            }

            computeShader = Resources.Load("PostProcessShaders/SunFlareOcclusion") as ComputeShader;
            if (computeShader == null)
            {
                Debug.LogError($"Unable to find shader SunFlareOcclusion in Resources. Post Process Volume {nameof(SunFlareFX)} is unable to load.");
            }
            else
            {
                textureOcclusionKernel       = computeShader.FindKernel("TextureOcclusion");
                blurTextureOcclusionKernel   = computeShader.FindKernel("BlurTextureOcclusion");
                reduceTextureOcclusionKernel = computeShader.FindKernel("ReduceTextureOcclusion");
                angleOcclusionKernel         = computeShader.FindKernel("AngleOcclusion");
            }

            occlusionTextureA = RTHandles.Alloc(
                OcclusionRes, OcclusionRes,
                colorFormat: GraphicsFormat.R32_SFloat,
                name: "SunFlareOcclusionA",
                enableRandomWrite: true,
                useMipMap: false,
                autoGenerateMips: false,
                wrapMode: TextureWrapMode.Clamp);

            occlusionTextureB = RTHandles.Alloc(
                OcclusionRes, OcclusionRes,
                colorFormat: GraphicsFormat.R32_SFloat,
                name: "SunFlareOcclusionB",
                enableRandomWrite: true,
                useMipMap: false,
                autoGenerateMips: false,
                wrapMode: TextureWrapMode.Clamp);

            angleOcclusion = new ComputeBuffer(AngleSamples, sizeof(float));
        }
Exemplo n.º 6
0
        public void RebuildTextures(int resolution)
        {
            bool updateNeeded = m_SkyboxCubemapRT == null || (m_SkyboxCubemapRT.rt.width != resolution);

            // Cleanup first if needed
            if (updateNeeded)
            {
                RTHandles.Release(m_SkyboxCubemapRT);
                m_SkyboxCubemapRT = null;

                RTHandles.Release(m_SkyboxBSDFCubemapIntermediate);
                m_SkyboxBSDFCubemapIntermediate = null;

                CoreUtils.Destroy(m_SkyboxBSDFCubemapArray);
                m_SkyboxBSDFCubemapArray = null;
            }

            // Reallocate everything
            if (m_SkyboxCubemapRT == null)
            {
                m_SkyboxCubemapRT = RTHandles.Alloc(resolution, resolution, colorFormat: HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R16G16B16A16_SFloat), dimension: TextureDimension.Cube, useMipMap: true, autoGenerateMips: false, filterMode: FilterMode.Trilinear, name: "SkyboxCubemap");
                if (m_SupportsConvolution)
                {
                    m_SkyboxBSDFCubemapIntermediate = RTHandles.Alloc(resolution, resolution, colorFormat: UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.OverrideRTGraphicsFormat(GraphicsFormat.R16G16B16A16_SFloat), dimension: TextureDimension.Cube, useMipMap: true, autoGenerateMips: false, filterMode: FilterMode.Trilinear, name: "SkyboxBSDFIntermediate");
                    m_SkyboxBSDFCubemapArray        = new CubemapArray(resolution, m_IBLFilterArray.Length, TextureFormat.RGBAHalf, true)
                    {
                        hideFlags  = HideFlags.HideAndDontSave,
                        wrapMode   = TextureWrapMode.Repeat,
                        wrapModeV  = TextureWrapMode.Clamp,
                        filterMode = FilterMode.Trilinear,
                        anisoLevel = 0,
                        name       = "SkyboxCubemapConvolution"
                    };
                }
            }

            m_CubemapScreenSize = new Vector4((float)resolution, (float)resolution, 1.0f / (float)resolution, 1.0f / (float)resolution);

            if (updateNeeded)
            {
                m_NeedUpdate = true; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
                RebuildSkyMatrices(resolution);
            }
        }
        void InitializeScreenSpaceShadows()
        {
            if (!m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.supportScreenSpaceShadows)
            {
                return;
            }

            // Fetch the shaders
#if ENABLE_RAYTRACING
            m_ScreenSpaceShadowsCS       = m_Asset.renderPipelineRayTracingResources.shadowRaytracingCS;
            m_ScreenSpaceShadowsFilterCS = m_Asset.renderPipelineRayTracingResources.shadowFilterCS;
            m_ScreenSpaceShadowsRT       = m_Asset.renderPipelineRayTracingResources.shadowRaytracingRT;

            // Directional shadow kernels
            m_ClearShadowTexture                = m_ScreenSpaceShadowsCS.FindKernel("ClearShadowTexture");
            m_OutputShadowTextureKernel         = m_ScreenSpaceShadowsCS.FindKernel("OutputShadowTexture");
            m_RaytracingDirectionalShadowSample = m_ScreenSpaceShadowsCS.FindKernel("RaytracingDirectionalShadowSample");
            m_RaytracingPointShadowSample       = m_ScreenSpaceShadowsCS.FindKernel("RaytracingPointShadowSample");

            // Area shadow kernels
            m_AreaRaytracingAreaShadowPrepassKernel   = m_ScreenSpaceShadowsCS.FindKernel("RaytracingAreaShadowPrepass");
            m_AreaRaytracingAreaShadowNewSampleKernel = m_ScreenSpaceShadowsCS.FindKernel("RaytracingAreaShadowNewSample");
            m_AreaShadowApplyTAAKernel        = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowApplyTAA");
            m_AreaUpdateAnalyticHistoryKernel = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaAnalyticHistoryCopy");
            m_AreaUpdateShadowHistoryKernel   = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowHistoryCopy");
            m_AreaEstimateNoiseKernel         = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowEstimateNoise");
            m_AreaFirstDenoiseKernel          = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowDenoiseFirstPass");
            m_AreaSecondDenoiseKernel         = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowDenoiseSecondPass");
            m_AreaShadowNoDenoiseKernel       = m_ScreenSpaceShadowsFilterCS.FindKernel("AreaShadowNoDenoise");

            // Allocate the intermediate buffers
            m_ShadowIntermediateBufferRG0   = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "ShadowIntermediateBufferRG0");
            m_ShadowIntermediateBufferRGBA0 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "ShadowIntermediateBufferRGBA0");
            m_ShadowIntermediateBufferRGBA1 = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "ShadowIntermediateBufferRGBA1");
#endif

            // Directional shadow material
            s_ScreenSpaceShadowsMat = CoreUtils.CreateEngineMaterial(screenSpaceShadowsShader);

            // Allocate the final result texture
            int numMaxShadows = Math.Max(m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadows, 1);
            m_ScreenSpaceShadowTextureArray = RTHandles.Alloc(Vector2.one, slices: numMaxShadows * TextureXR.slices, dimension: TextureDimension.Tex2DArray, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16_SFloat, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "AreaShadowArrayBuffer");
        }
Exemplo n.º 8
0
        void InitializeScreenSpaceShadows()
        {
            if (!m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.supportScreenSpaceShadows)
            {
                return;
            }

#if ENABLE_RAYTRACING
            // Allocate the intermediate buffers
            m_AnalyticProbBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "AnalyticProbBuffer");
            m_DenoiseBuffer0     = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "DenoiseBuffer0");
            m_DenoiseBuffer1     = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "DenoiseBuffer1");
#endif
            s_ScreenSpaceShadowsMat = CoreUtils.CreateEngineMaterial(screenSpaceShadowsShader);

            // Allocate the final result texture
            int numMaxShadows = Math.Max(m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadows, 1);
            m_ScreenSpaceShadowTextureArray = RTHandles.Alloc(Vector2.one, slices: numMaxShadows * TextureXR.slices, dimension: TextureDimension.Tex2DArray, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16_SFloat, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "AreaShadowArrayBuffer");
        }
Exemplo n.º 9
0
        public void Init(HDRenderPipelineRayTracingResources rayTracingResources, DebugDisplaySettings currentDebugDisplaySettings)
        {
            // Keep track of the external resources
            m_DebugDisplaySettings = currentDebugDisplaySettings;
            m_PipelineResources    = rayTracingResources;

            m_RayCountTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32G32B32A32_UInt, enableRandomWrite: true, useMipMap: false, name: "RayCountTexture");

            // We only require 3 buffers (this supports a maximal size of 8192x8192)
            m_ReducedRayCountBuffer0 = new ComputeBuffer(4 * 256 * 256, sizeof(uint));
            m_ReducedRayCountBuffer1 = new ComputeBuffer(4 * 32 * 32, sizeof(uint));
            m_ReducedRayCountBuffer2 = new ComputeBuffer(4, sizeof(uint));

            // Initialize the cpu ray count (Optional)
            for (int i = 0; i < 4; ++i)
            {
                m_ReducedRayCountValues[i] = 0;
            }
        }
        public void Init(RenderPipelineResources rpResources, HDRenderPipelineRayTracingResources rpRTResources, RenderPipelineSettings pipelineSettings, HDRaytracingManager raytracingManager, SharedRTManager sharedRTManager)
        {
            // Keep track of the pipeline asset
            m_PipelineSettings            = pipelineSettings;
            m_PipelineResources           = rpResources;
            m_PipelineRayTracingResources = rpRTResources;

            // keep track of the ray tracing manager
            m_RaytracingManager = raytracingManager;

            // Keep track of the shared rt manager
            m_SharedRTManager = sharedRTManager;

            // Intermediate buffer that holds the pre-denoised texture
            m_IntermediateBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IntermediateAOBuffer");

            // Buffer that holds the uncompressed normal buffer
            m_ViewSpaceNormalBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "ViewSpaceNormalBuffer");
        }
Exemplo n.º 11
0
        public override void OnEnable()
        {
            base.OnEnable();

            m_EnableLuxIntensityMode = true;

            // HDRI sky does not have control over sun display.
            m_CommonUIElementsMask = 0xFFFFFFFF & ~(uint)(SkySettingsUIElement.IncludeSunInBaking);

            var o = new PropertyFetcher <HDRISky>(serializedObject);

            m_hdriSky = Unpack(o.Find(x => x.hdriSky));
            m_UpperHemisphereLuxValue = Unpack(o.Find(x => x.upperHemisphereLuxValue));
            m_UpperHemisphereLuxColor = Unpack(o.Find(x => x.upperHemisphereLuxColor));

            m_EnableCloudMotion   = Unpack(o.Find(x => x.enableDistortion));
            m_Procedural          = Unpack(o.Find(x => x.procedural));
            m_Flowmap             = Unpack(o.Find(x => x.flowmap));
            m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly));
            m_ScrollDirection     = Unpack(o.Find(x => x.scrollDirection));
            m_ScrollSpeed         = Unpack(o.Find(x => x.scrollSpeed));

            m_EnableBackplate    = Unpack(o.Find(x => x.enableBackplate));
            m_BackplateType      = Unpack(o.Find(x => x.backplateType));
            m_GroundLevel        = Unpack(o.Find(x => x.groundLevel));
            m_Scale              = Unpack(o.Find(x => x.scale));
            m_ProjectionDistance = Unpack(o.Find(x => x.projectionDistance));
            m_PlateRotation      = Unpack(o.Find(x => x.plateRotation));
            m_PlateTexRotation   = Unpack(o.Find(x => x.plateTexRotation));
            m_PlateTexOffset     = Unpack(o.Find(x => x.plateTexOffset));
            m_BlendAmount        = Unpack(o.Find(x => x.blendAmount));
            m_PointLightShadow   = Unpack(o.Find(x => x.pointLightShadow));
            m_DirLightShadow     = Unpack(o.Find(x => x.dirLightShadow));
            m_RectLightShadow    = Unpack(o.Find(x => x.rectLightShadow));
            m_ShadowTint         = Unpack(o.Find(x => x.shadowTint));

            m_IntensityTexture = RTHandles.Alloc(1, 1, colorFormat: GraphicsFormat.R32G32B32A32_SFloat);
            if (HDRenderPipelineGlobalSettings.instance?.renderPipelineResources != null)
            {
                m_IntegrateHDRISkyMaterial = CoreUtils.CreateEngineMaterial(HDRenderPipelineGlobalSettings.instance.renderPipelineResources.shaders.integrateHdriSkyPS);
            }
            m_ReadBackTexture = new Texture2D(1, 1, GraphicsFormat.R32G32B32A32_SFloat, TextureCreationFlags.None);
        }
Exemplo n.º 12
0
        void AllocateRenderTexture()
        {
            if (m_Atlas != null)
            {
                m_Atlas.Release();
            }

            m_Atlas = RTHandles.Alloc(width, height, filterMode: m_FilterMode, depthBufferBits: m_DepthBufferBits, sRGB: false, colorFormat: m_Format, name: m_Name);
            if (m_SupportMomentShadows)
            {
                string momentShadowMapName = m_Name + "Moment";
                m_AtlasMoments = RTHandles.Alloc(width, height, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBFloat, sRGB: false, enableRandomWrite: true, name: momentShadowMapName);
                string intermediateSummedAreaName = m_Name + "IntermediateSummedArea";
                m_IntermediateSummedAreaTexture = RTHandles.Alloc(width, height, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBInt, sRGB: false, enableRandomWrite: true, name: intermediateSummedAreaName);
                string summedAreaName = m_Name + "SummedAreaFinal";
                m_SummedAreaTexture = RTHandles.Alloc(width, height, filterMode: FilterMode.Point, colorFormat: RenderTextureFormat.ARGBInt, sRGB: false, enableRandomWrite: true, name: summedAreaName);
            }
            identifier = new RenderTargetIdentifier(m_Atlas);
        }
Exemplo n.º 13
0
    AOVRequestDataCollection BuildAovRequest()
    {
        var aovRequest = AOVRequest.NewDefault();

        CustomPassAOVBuffers[] customPassAovBuffers = null;
        customPassAovBuffers = new[] { new CustomPassAOVBuffers(CustomPassInjectionPoint.BeforePostProcess, CustomPassAOVBuffers.OutputType.CustomPassBuffer) };

        var bufAlloc = _rt ?? (_rt = RTHandles.Alloc(_outputTexture.width, _outputTexture.height));

        return(new AOVRequestBuilder().Add(
                   aovRequest,
                   RTAllocator,
                   null, // lightFilter
                   null,
                   customPassAovBuffers,
                   bufferId => bufAlloc,
                   AovCallbackEx
                   ).Build());
    }
Exemplo n.º 14
0
        public Texture2DAtlas(int width, int height, GraphicsFormat format, FilterMode filterMode = FilterMode.Point, bool powerOfTwoPadding = false, string name = "", bool useMipMap = true)
        {
            m_Width        = width;
            m_Height       = height;
            m_Format       = format;
            m_UseMipMaps   = useMipMap;
            m_AtlasTexture = RTHandles.Alloc(
                width: m_Width,
                height: m_Height,
                filterMode: filterMode,
                colorFormat: m_Format,
                wrapMode: TextureWrapMode.Clamp,
                useMipMap: useMipMap,
                autoGenerateMips: false,
                name: name
                );

            m_AtlasAllocator = new AtlasAllocator(width, height, powerOfTwoPadding);
        }
        public void Init(HDRenderPipelineAsset asset, SkyManager skyManager, HDRaytracingManager raytracingManager, SharedRTManager sharedRTManager, GBufferManager gbufferManager)
        {
            // Keep track of the pipeline asset
            m_PipelineAsset     = asset;
            m_PipelineResources = asset.renderPipelineResources;

            // Keep track of the sky manager
            m_SkyManager = skyManager;

            // keep track of the ray tracing manager
            m_RaytracingManager = raytracingManager;

            // Keep track of the shared rt manager
            m_SharedRTManager = sharedRTManager;
            m_GBufferManager  = gbufferManager;

            m_IndirectDiffuseTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, xrInstancing: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer");
            m_DenoiseBuffer0         = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, xrInstancing: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseDenoiseBuffer");
        }
Exemplo n.º 16
0
        void InitSSSBuffers()
        {
            RenderPipelineSettings settings = asset.currentPlatformRenderPipelineSettings;

            if (settings.supportedLitShaderMode == RenderPipelineSettings.SupportedLitShaderMode.ForwardOnly) //forward only
            {
                // In case of full forward we must allocate the render target for forward SSS (or reuse one already existing)
                // TODO: Provide a way to reuse a render target
                m_SSSColor = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8G8B8A8_SRGB, dimension: TextureXR.dimension, useDynamicScale: true, name: "SSSBuffer");
                m_SSSReuseGBufferMemory = false;
            }

            // We need to allocate the texture if we are in forward or both in case one of the cameras is in enable forward only mode
            if (settings.supportMSAA && settings.supportedLitShaderMode != RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly)
            {
                m_SSSColorMSAA = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R8G8B8A8_SRGB, dimension: TextureXR.dimension, enableMSAA: true, bindTextureMS: true, useDynamicScale: true, name: "SSSBufferMSAA");
            }

            if ((settings.supportedLitShaderMode & RenderPipelineSettings.SupportedLitShaderMode.DeferredOnly) != 0) //deferred or both
            {
                // In case of deferred, we must be in sync with SubsurfaceScattering.hlsl and lit.hlsl files and setup the correct buffers
                m_SSSColor = m_GbufferManager.GetSubsurfaceScatteringBuffer(0); // Note: This buffer must be sRGB (which is the case with Lit.shader)
                m_SSSReuseGBufferMemory = true;
            }

            if (NeedTemporarySubsurfaceBuffer() || settings.supportMSAA)
            {
                // Caution: must be same format as m_CameraSssDiffuseLightingBuffer
                m_SSSCameraFilteringBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.B10G11R11_UFloatPack32, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, name: "SSSCameraFiltering"); // Enable UAV
            }

            // fill the list with the max number of diffusion profile so we dont have
            // the error: exceeds previous array size (5 vs 3). Cap to previous size.
            m_SSSThicknessRemaps = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSShapeParams     = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSTransmissionTintsAndFresnel0         = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSDisabledTransmissionTintsAndFresnel0 = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSWorldScales            = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSFilterKernels          = new Vector4[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT * DiffusionProfileConstants.SSS_N_SAMPLES_NEAR_FIELD];
            m_SSSDiffusionProfileHashes = new float[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSDiffusionProfileUpdate = new int[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
            m_SSSSetDiffusionProfiles   = new DiffusionProfileSettings[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
        }
        public void Initialize(RenderPipelineResources rpResources, HDRenderPipelineRayTracingResources rpRTResources, HDRaytracingManager raytracingManager, SharedRTManager sharedRTManager, HDRenderPipeline renderPipeline)
        {
            // Keep track of the external buffers
            m_RenderPipelineResources           = rpResources;
            m_RenderPipelineRayTracingResources = rpRTResources;
            m_RaytracingManager = raytracingManager;

            // Keep track of the render pipeline
            m_RenderPipeline = renderPipeline;

            // Keep track of the shader rt manager
            m_SharedRTManager = sharedRTManager;

            // Texture used to output debug information
            m_DebugLightClusterTexture = RTHandles.Alloc(Vector2.one, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "DebugLightClusterTexture");

            // Pre allocate the cluster with a dummy size
            m_LightCluster = new ComputeBuffer(1, sizeof(uint));
        }
Exemplo n.º 18
0
        internal void CreateProbeVolumeBuffers()
        {
            m_VisibleProbeVolumeBounds               = new List <OrientedBBox>();
            m_VisibleProbeVolumeData                 = new List <ProbeVolumeEngineData>();
            s_VisibleProbeVolumeBoundsBuffer         = new ComputeBuffer(k_MaxVisibleProbeVolumeCount, Marshal.SizeOf(typeof(OrientedBBox)));
            s_VisibleProbeVolumeDataBuffer           = new ComputeBuffer(k_MaxVisibleProbeVolumeCount, Marshal.SizeOf(typeof(ProbeVolumeEngineData)));
            s_ProbeVolumeAtlasBlitDataBuffer         = new ComputeBuffer(s_MaxProbeVolumeProbeCount, Marshal.SizeOf(typeof(SphericalHarmonicsL1)));
            s_ProbeVolumeAtlasBlitDataValidityBuffer = new ComputeBuffer(s_MaxProbeVolumeProbeCount, Marshal.SizeOf(typeof(float)));
            s_ProbeVolumeAtlasOctahedralDepthBuffer  = new ComputeBuffer(s_MaxProbeVolumeProbeCount, Marshal.SizeOf(typeof(float)));

            m_ProbeVolumeAtlasSHRTHandle = RTHandles.Alloc(
                width: s_ProbeVolumeAtlasWidth,
                height: s_ProbeVolumeAtlasHeight,
                slices: s_ProbeVolumeAtlasDepth * m_ProbeVolumeAtlasSHRTDepthSliceCount,
                dimension:         TextureDimension.Tex3D,
                colorFormat:       UnityEngine.Experimental.Rendering.GraphicsFormat.R16G16B16A16_SFloat,//GraphicsFormat.B10G11R11_UFloatPack32,
                enableRandomWrite: true,
                useMipMap:         false,
                name:              "ProbeVolumeAtlasSH"
                );

            probeVolumeAtlas = new Texture3DAtlasDynamic(s_ProbeVolumeAtlasWidth, s_ProbeVolumeAtlasHeight, s_ProbeVolumeAtlasDepth, k_MaxVisibleProbeVolumeCount, m_ProbeVolumeAtlasSHRTHandle);

            // TODO: (Nick): Might be able drop precision down to half-floats, since we only need to encode depth data up to one probe spacing distance away. Could rescale depth data to this range before encoding.
            m_ProbeVolumeAtlasOctahedralDepthRTHandle = RTHandles.Alloc(
                width: s_ProbeVolumeAtlasOctahedralDepthWidth,
                height: s_ProbeVolumeAtlasOctahedralDepthHeight,
                slices: 1,
                dimension: TextureDimension.Tex2D,
                colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R32G32_SFloat, // float2(mean, variance)
                enableRandomWrite: true,
                useMipMap: false,
                name: "ProbeVolumeAtlasOctahedralDepthMeanAndVariance"
                );

            probeVolumeAtlasOctahedralDepth = new Texture2DAtlasDynamic(
                s_ProbeVolumeAtlasOctahedralDepthWidth,
                s_ProbeVolumeAtlasOctahedralDepthHeight,
                k_MaxVisibleProbeVolumeCount,
                m_ProbeVolumeAtlasOctahedralDepthRTHandle
                );
        }
Exemplo n.º 19
0
        void InitScreenSpaceGlobalIllumination()
        {
            if (m_Asset.currentPlatformRenderPipelineSettings.supportSSGI)
            {
                m_IndirectDiffuseBuffer0        = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer0");
                m_IndirectDiffuseBuffer1        = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseBuffer1");
                m_IndirectDiffuseHitPointBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, autoGenerateMips: false, name: "IndirectDiffuseHitBuffer");

                // Grab the sets of shaders that we'll be using
                ComputeShader ssGICS = m_Asset.renderPipelineResources.shaders.screenSpaceGlobalIlluminationCS;
                ComputeShader bilateralUpsampleCS = m_Asset.renderPipelineResources.shaders.bilateralUpsampleCS;

                // Grab the set of kernels that we shall be using
                m_TraceGlobalIlluminationKernel         = ssGICS.FindKernel("TraceGlobalIllumination");
                m_TraceGlobalIlluminationHalfKernel     = ssGICS.FindKernel("TraceGlobalIlluminationHalf");
                m_ReprojectGlobalIlluminationKernel     = ssGICS.FindKernel("ReprojectGlobalIllumination");
                m_ReprojectGlobalIlluminationHalfKernel = ssGICS.FindKernel("ReprojectGlobalIlluminationHalf");
                m_BilateralUpSampleColorTMKernel        = bilateralUpsampleCS.FindKernel("BilateralUpSampleColorTM");
            }
        }
Exemplo n.º 20
0
        public void Initialize(HDRenderPipeline renderPipeline)
        {
            // Keep track of the external buffers
            m_RenderPipelineResources           = renderPipeline.asset.renderPipelineResources;
            m_RenderPipelineRayTracingResources = renderPipeline.asset.renderPipelineRayTracingResources;

            // Keep track of the render pipeline
            m_RenderPipeline = renderPipeline;

            // Texture used to output debug information
            m_DebugLightClusterTexture = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: "DebugLightClusterTexture");

            // Pre allocate the cluster with a dummy size
            m_LightCluster         = new ComputeBuffer(1, sizeof(uint));
            m_LightDataGPUArray    = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(LightData)));
            m_EnvLightDataGPUArray = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(EnvLightData)));

            // Create the material required for debug
            m_DebugMaterial = CoreUtils.CreateEngineMaterial(m_RenderPipelineRayTracingResources.lightClusterDebugS);
        }
Exemplo n.º 21
0
        public static void InitializeBudget(uint maxTextureCount)
        {
            if (m_RenderTargets == null || m_RenderTargets.Length != maxTextureCount)
            {
                m_RenderTargets   = new RTHandle[maxTextureCount];
                m_RenderTargetIds = new int[maxTextureCount];
                ShadowRendering.maxTextureCount = maxTextureCount;

                for (int i = 0; i < maxTextureCount; i++)
                {
                    m_RenderTargetIds[i] = Shader.PropertyToID($"ShadowTex_{i}");
                    m_RenderTargets[i]   = RTHandles.Alloc(m_RenderTargetIds[i], $"ShadowTex_{i}");
                }
            }

            if (m_LightInputTextures == null || m_LightInputTextures.Length != maxTextureCount)
            {
                m_LightInputTextures = new RenderTargetIdentifier[maxTextureCount];
            }
        }
Exemplo n.º 22
0
        internal void ReleaseRayTracingManager()
        {
            RTHandles.Release(m_RayTracingDistanceBuffer);
            RTHandles.Release(m_RayTracingDirectionBuffer);

            RTHandles.Release(m_RayTracingIntermediateBufferR0);
            RTHandles.Release(m_RayTracingIntermediateBufferR1);
            RTHandles.Release(m_RayTracingIntermediateBufferRG0);
            RTHandles.Release(m_RayTracingIntermediateBufferRGBA0);
            RTHandles.Release(m_RayTracingIntermediateBufferRGBA1);
            RTHandles.Release(m_RayTracingIntermediateBufferRGBA2);
            RTHandles.Release(m_RayTracingIntermediateBufferRGBA3);

            m_RayTracingLightCluster.ReleaseResources();
            m_ReflectionDenoiser.Release();
            m_TemporalFilter.Release();
            m_SimpleDenoiser.Release();
            m_DiffuseDenoiser.Release();
            m_RayCountManager.Release();
        }
Exemplo n.º 23
0
        /// <summary>
        /// Releases all native resources allocated by this instance.
        /// </summary>
        public void Release()
        {
            if (colorRt != null)
            {
                RTHandles.Release(colorRt);
                colorRt = null;
            }

            if (depthRt != null)
            {
                RTHandles.Release(depthRt);
                depthRt = null;
            }

            if (uiRt != null)
            {
                RTHandles.Release(uiRt);
                uiRt = null;
            }
        }
Exemplo n.º 24
0
        public void Cleanup()
        {
            CoreUtils.Destroy(m_CombineLightingPass);
            CoreUtils.Destroy(m_CopyStencilForSplitLighting);

            for (int i = 0; i < k_MaxSSSBuffer; ++i)
            {
                if (!m_ReuseGBufferMemory [i])
                {
                    RTHandles.Release(m_ColorMRTs[i]);
                    if (m_MSAASupport)
                    {
                        RTHandles.Release(m_ColorMSAAMRTs[i]);
                    }
                }
            }

            RTHandles.Release(m_CameraFilteringBuffer);
            RTHandles.Release(m_HTile);
        }
Exemplo n.º 25
0
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        // Hidden foreground camera:
        var cam = GameObject.Find(kCameraTag);

        if (cam == null)
        {
            cam = new GameObject(kCameraTag);
            // cam = new GameObject(kCameraTag) { hideFlags = HideFlags.HideAndDontSave };
            cam.AddComponent <Camera>();
        }

        depthClearMaterial = new Material(Shader.Find("Hidden/Renderers/ForegroundDepthClear"));

        var trueDethBuffer = new RenderTargetIdentifier(BuiltinRenderTextureType.Depth);

        trueDepthBuffer = RTHandles.Alloc(trueDethBuffer);

        foregroundCamera = cam.GetComponent <Camera>();
    }
Exemplo n.º 26
0
        public Texture2DAtlas(int width, int height, RenderTextureFormat format)
        {
            m_Width        = width;
            m_Height       = height;
            m_Format       = format;
            m_AtlasTexture = RTHandles.Alloc(m_Width,
                                             m_Height,
                                             1,
                                             DepthBits.None,
                                             m_Format,
                                             FilterMode.Point,
                                             TextureWrapMode.Clamp,
                                             TextureDimension.Tex2D,
                                             false,
                                             false,
                                             true,
                                             false);

            m_AtlasAllocator = new AtlasAllocator(width, height);
        }
Exemplo n.º 27
0
        public override void OnEnable()
        {
            base.OnEnable();

            // HDRI sky does not have control over sun display.
            m_CommonUIElementsMask = 0xFFFFFFFF & ~(uint)(SkySettingsUIElement.IncludeSunInBaking);

            var o = new PropertyFetcher <HDRISky>(serializedObject);

            m_hdriSky                 = Unpack(o.Find(x => x.hdriSky));
            m_DesiredLuxValue         = Unpack(o.Find(x => x.desiredLuxValue));
            m_IntensityMode           = Unpack(o.Find(x => x.skyIntensityMode));
            m_UpperHemisphereLuxValue = Unpack(o.Find(x => x.upperHemisphereLuxValue));

            m_IntensityTexture = RTHandles.Alloc(1, 1, colorFormat: GraphicsFormat.R32G32B32A32_SFloat);
            var hdrp = HDRenderPipeline.defaultAsset;

            m_IntegrateHDRISkyMaterial = CoreUtils.CreateEngineMaterial(hdrp.renderPipelineResources.shaders.integrateHdriSkyPS);
            readBackTexture            = new Texture2D(1, 1, TextureFormat.RGBAFloat, false, false);
        }
Exemplo n.º 28
0
    protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
    {
        outlineShader     = Shader.Find("Hidden/Outline");
        fullscreenOutline = CoreUtils.CreateEngineMaterial(outlineShader);
        outlineProperties = new MaterialPropertyBlock();

        // List all the materials that will be replaced in the frame
        shaderTags = new ShaderTagId[3]
        {
            new ShaderTagId("Forward"),
            new ShaderTagId("ForwardOnly"),
            new ShaderTagId("SRPDefaultUnlit"),
        };

        outlineBuffer = RTHandles.Alloc(
            Vector2.one, TextureXR.slices, dimension: TextureXR.dimension,
            colorFormat: GraphicsFormat.B10G11R11_UFloatPack32,
            useDynamicScale: true, name: "Outline Buffer"
            );
    }
Exemplo n.º 29
0
        public void Cleanup()
        {
            CoreUtils.Destroy(m_StandardSkyboxMaterial);
            CoreUtils.Destroy(m_BlitCubemapMaterial);
            CoreUtils.Destroy(m_OpaqueAtmScatteringMaterial);

            RTHandles.Release(m_SkyboxBSDFCubemapIntermediate);
            CoreUtils.Destroy(m_BlackCubemapArray);

            for (int i = 0; i < m_CachedSkyContexts.size; ++i)
            {
                m_CachedSkyContexts[i].Cleanup();
            }

            m_StaticLightingSky.Cleanup();

#if UNITY_EDITOR
            CoreUtils.Destroy(m_DefaultPreviewSky);
#endif
        }
    private void InitializeBuffers()
    {
        m_ColorBuffer = RTHandles.Alloc(Vector2.one,
                                        colorFormat: SystemInfo.GetGraphicsFormat(UnityEngine.Experimental.Rendering.DefaultFormat.HDR),
                                        enableMSAA: true,
                                        bindTextureMS: false,
                                        name: "ColorBuffer");

        m_BackgroundBuffer = RTHandles.Alloc(Vector2.one,
                                             colorFormat: SystemInfo.GetGraphicsFormat(UnityEngine.Experimental.Rendering.DefaultFormat.HDR),
                                             enableMSAA: true,
                                             bindTextureMS: true, //NOTE: We resolve on final pass
                                             name: "BackgroundBuffer");

        m_StochasticColorBuffer = RTHandles.Alloc(Vector2.one,
                                                  colorFormat: SystemInfo.GetGraphicsFormat(UnityEngine.Experimental.Rendering.DefaultFormat.HDR),
                                                  enableMSAA: true,
                                                  bindTextureMS: false, //NOTE: We want to resolve before final pass
                                                  name: "StochasticColorBuffer");

        m_DepthStencilBuffer = RTHandles.Alloc(Vector2.one,
                                               depthBufferBits: DepthBits.Depth32,
                                               enableMSAA: true,
                                               name: "DepthStencilBuffer");

        m_TransmissionBuffer = RTHandles.Alloc(Vector2.one,
                                               colorFormat: UnityEngine.Experimental.Rendering.GraphicsFormat.R16_SFloat,
                                               enableMSAA: true,
                                               bindTextureMS: true,         // NOTE: We resolve on final pass
                                               name: "TransmissionBuffer"); // NOTE: No MSAA on opacity for now.

        // Alloc History Buffers
        m_HistoryBuffers = new RTHandle[2];
        for (int i = 0; i < m_HistoryBuffers.Length; ++i)
        {
            m_HistoryBuffers[i] = RTHandles.Alloc(Vector2.one,
                                                  colorFormat: SystemInfo.GetGraphicsFormat(UnityEngine.Experimental.Rendering.DefaultFormat.HDR),
                                                  enableMSAA: false,
                                                  name: "HistoryBuffer" + i);
        }
    }