public void Render(ref PipelineCommandData data, PipelineCamera cam, PropertySetEvent proper)
        {
            SSRCameraData cameraData = IPerCameraData.GetProperty(cam, getDataFunc);

            SSR_UpdateVariable(cameraData, cam.cam, ref data, proper);
            RenderScreenSpaceReflection(data.buffer, cameraData, cam);
        }
Exemple #2
0
        public void Render(ref PipelineCommandData data, PipelineCamera cam, ReflectionEvent parentEvent)
        {
            RandomSampler = GenerateRandomOffset();
            SSRCameraData cameraData = IPerCameraData.GetProperty(cam, getDataFunc, parentEvent);

            SSR_UpdateVariable(cameraData, cam.cam, ref data);
            RenderScreenSpaceReflection(data.buffer, cameraData, cam);
        }
Exemple #3
0
 public bool UpdateCameraSize(Vector2Int currentSize)
 {
     if (CameraSize == currentSize)
     {
         return(false);
     }
     CameraSize = currentSize;
     SSRCameraData.ChangeSet(SSR_PrevDepth_RT, currentSize.x, currentSize.y, 0, RenderTextureFormat.RFloat);
     return(true);
 }
        public int Render(ref PipelineCommandData data, PipelineCamera cam, PropertySetEvent proper)
        {
            SSRCameraData.GetSSRCameraData getCam = new SSRCameraData.GetSSRCameraData
            {
                currentSize = new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight),
                resolution  = 2
            };
            SSRCameraData cameraData = IPerCameraData.GetProperty <SSRCameraData, SSRCameraData.GetSSRCameraData>(cam, getCam);

            SSR_UpdateVariable(cameraData, cam.cam, ref data, proper);
            RenderScreenSpaceReflection(data.buffer, cameraData, cam);
            return(SSR_TemporalCurr_ID);
        }
        private void SSR_UpdateVariable(SSRCameraData cameraData, PropertySetEvent setEvent, Camera RenderCamera, ref PipelineCommandData data)
        {
            Vector2Int    CameraSize = new Vector2Int(RenderCamera.pixelWidth, RenderCamera.pixelHeight);
            CommandBuffer buffer     = data.buffer;

            if (cameraData.UpdateCameraSize(CameraSize, (int)RayCastingResolution))
            {
                SSR_UpdateUniformVariable();
            }
            ////////////Set Matrix
#if UNITY_EDITOR
            else if (RunTimeDebugMod)
            {
                SSR_UpdateUniformVariable();
            }
#endif
            buffer.SetGlobalVector(SSR_ScreenSize_ID, new Vector2(CameraSize.x, CameraSize.y));
            buffer.SetGlobalVector(SSR_RayCastSize_ID, new Vector2(CameraSize.x, CameraSize.y) / (int)RayCastingResolution);

            buffer.SetGlobalVector(SSR_Jitter_ID, new Vector4((float)CameraSize.x / 1024, (float)CameraSize.y / 1024, RandomSampler.x, RandomSampler.y));
            Matrix4x4 proj = GL.GetGPUProjectionMatrix(RenderCamera.projectionMatrix, false);
            buffer.SetGlobalMatrix(SSR_ProjectionMatrix_ID, proj);
            buffer.SetGlobalMatrix(SSR_ViewProjectionMatrix_ID, data.vp);
            buffer.SetGlobalMatrix(SSR_InverseProjectionMatrix_ID, proj.inverse);
            buffer.SetGlobalMatrix(SSR_InverseViewProjectionMatrix_ID, data.inverseVP);
            buffer.SetGlobalMatrix(SSR_WorldToCameraMatrix_ID, RenderCamera.worldToCameraMatrix);
            buffer.SetGlobalMatrix(SSR_CameraToWorldMatrix_ID, RenderCamera.cameraToWorldMatrix);
            buffer.SetGlobalMatrix(SSR_LastFrameViewProjectionMatrix_ID, setEvent.lastViewProjection);

            Matrix4x4 warpToScreenSpaceMatrix = Matrix4x4.identity;
            Vector2   HalfCameraSize          = new Vector2(CameraSize.x, CameraSize.y) / 2;
            warpToScreenSpaceMatrix.m00 = HalfCameraSize.x; warpToScreenSpaceMatrix.m03 = HalfCameraSize.x;
            warpToScreenSpaceMatrix.m11 = HalfCameraSize.y; warpToScreenSpaceMatrix.m13 = HalfCameraSize.y;

            Matrix4x4 SSR_ProjectToPixelMatrix = warpToScreenSpaceMatrix * proj;
            buffer.SetGlobalMatrix(SSR_ProjectToPixelMatrix_ID, SSR_ProjectToPixelMatrix);

            Vector4 SSR_ProjInfo = new Vector4
                                       ((-2 / (CameraSize.x * proj[0])),
                                       (-2 / (CameraSize.y * proj[5])),
                                       ((1 - proj[2]) / proj[0]),
                                       ((1 + proj[6]) / proj[5]));
            buffer.SetGlobalVector(SSR_ProjInfo_ID, SSR_ProjInfo);

            Vector3 SSR_ClipInfo = (float.IsPositiveInfinity(RenderCamera.farClipPlane)) ?
                                   new Vector3(RenderCamera.nearClipPlane, -1, 1) :
                                   new Vector3(RenderCamera.nearClipPlane * RenderCamera.farClipPlane, RenderCamera.nearClipPlane - RenderCamera.farClipPlane, RenderCamera.farClipPlane);
            buffer.SetGlobalVector(SSR_CameraClipInfo_ID, SSR_ClipInfo);
        }
        private void SSR_UpdateVariable(SSRCameraData cameraData, Camera RenderCamera, ref PipelineCommandData data, PropertySetEvent proper)
        {
            int           downRes    = downSample ? 2 : 1;
            Vector2Int    CameraSize = new Vector2Int(RenderCamera.pixelWidth, RenderCamera.pixelHeight);
            CommandBuffer buffer     = data.buffer;

            cameraData.UpdateCameraSize(CameraSize, 2);
            buffer.SetGlobalMatrix(ShaderIDs._VP, proper.VP);
            Matrix4x4 proj = GL.GetGPUProjectionMatrix(RenderCamera.projectionMatrix, false);
            Matrix4x4 warpToScreenSpaceMatrix = Matrix4x4.identity;
            Vector2   HalfCameraSize          = new Vector2(CameraSize.x, CameraSize.y) / downRes;

            warpToScreenSpaceMatrix.m00 = HalfCameraSize.x; warpToScreenSpaceMatrix.m03 = HalfCameraSize.x;
            warpToScreenSpaceMatrix.m11 = HalfCameraSize.y; warpToScreenSpaceMatrix.m13 = HalfCameraSize.y;

            Matrix4x4             SSR_ProjectToPixelMatrix = warpToScreenSpaceMatrix * proj;
            NativeArray <SSRData> dataArr = new NativeArray <SSRData>(1, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
            SSRData *ptr = dataArr.Ptr();

            ptr->ScreenFade         = ScreenFade;
            ptr->Thickness          = Thickness;
            ptr->HiZ_RaySteps       = HiZ_RaySteps;
            ptr->HiZ_MaxLevel       = HiZ_MaxLevel;
            ptr->HiZ_StartLevel     = HiZ_StartLevel;
            ptr->HiZ_StopLevel      = HiZ_StopLevel;
            ptr->MaximumBiasAllowed = MaximumAllowedTemporalDepthBias;
            ptr->TemporalWeight     = float2(StaticTemporalWeight, DynamicTemporalWeight);
            ptr->ScreenSize         = float2(CameraSize.x, CameraSize.y);
            ptr->rayCastSize        = float2(CameraSize.x, CameraSize.y) / downRes;
            ptr->projection         = proj;
            ptr->inverseProj        = proj.inverse;
            ptr->viewProjection     = proper.VP;
            ptr->worldToCamera      = RenderCamera.worldToCameraMatrix;
            ptr->cameraToWorld      = RenderCamera.cameraToWorldMatrix;
            ptr->projToPixelMatrix  = SSR_ProjectToPixelMatrix;
            ptr->brdfBias           = brdfBias;
            ptr->inverseLastVP      = propertySetEvent.inverseLastViewProjection;
            ssrDatas.SetData(dataArr);
            buffer.SetGlobalConstantBuffer(ssrDatas, SSRDatas, 0, ssrDatas.stride);
            dataArr.Dispose();
        }
Exemple #7
0
 public override void DisposeProperty()
 {
     SSRCameraData.CheckAndRelease(ref SSR_PrevDepth_RT);
 }
Exemple #8
0
        private void RenderScreenSpaceReflection(CommandBuffer ScreenSpaceReflectionBuffer, SSRCameraData camData, PipelineCamera cam)
        {
            Vector2Int resolution = new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight);

            //////Gte HiZ_DEPTHrt//////
            ScreenSpaceReflectionBuffer.CopyTexture(ShaderIDs._CameraDepthTexture, 0, 0, camData.SSR_HierarchicalDepth_RT, 0, 0);
            for (int i = 1; i < HiZ_MaxLevel + 1; ++i)
            {
                ScreenSpaceReflectionBuffer.SetGlobalInt(SSR_HiZ_PrevDepthLevel_ID, i - 1);
                ScreenSpaceReflectionBuffer.SetRenderTarget(camData.SSR_HierarchicalDepth_BackUp_RT, i);
                ScreenSpaceReflectionBuffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, StochasticScreenSpaceReflectionMaterial, 0, 0);
                ScreenSpaceReflectionBuffer.CopyTexture(camData.SSR_HierarchicalDepth_BackUp_RT, 0, i, camData.SSR_HierarchicalDepth_RT, 0, i);
            }
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_HierarchicalDepth_ID, camData.SSR_HierarchicalDepth_RT);

            //////Set SceneColorRT//////
            ScreenSpaceReflectionBuffer.CopyTexture(cam.targets.renderTargetIdentifier, 0, 0, cam.targets.backupIdentifier, 0, 0);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_SceneColor_ID, cam.targets.backupIdentifier);
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_Trace_ID, resolution.x / 2, resolution.y / 2, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_GetSSRColor_ID, resolution.x, resolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.SetGlobalVector(ShaderIDs._RandomSeed, (float4)(rand.NextDouble4()));
            ScreenSpaceReflectionBuffer.BlitSRT(SSR_Trace_ID, StochasticScreenSpaceReflectionMaterial, 1);
            //////GetSSRColor//////
            ScreenSpaceReflectionBuffer.BlitSRT(SSR_GetSSRColor_ID, StochasticScreenSpaceReflectionMaterial, 2);
            //////Temporal filter//////
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_TemporalCurr_ID, resolution.x, resolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_TemporalPrev_ID, camData.SSR_TemporalPrev_RT);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(ShaderIDs._LastFrameDepthTexture, prevDepthData.SSR_PrevDepth_RT);
            ScreenSpaceReflectionBuffer.BlitSRT(SSR_TemporalCurr_ID, StochasticScreenSpaceReflectionMaterial, 3);
            ScreenSpaceReflectionBuffer.CopyTexture(SSR_TemporalCurr_ID, 0, 0, camData.SSR_TemporalPrev_RT, 0, 0);
            if (prevDepthData.targetObject == this)
            {
                prevDepthData.UpdateCameraSize(resolution);
                ScreenSpaceReflectionBuffer.CopyTexture(ShaderIDs._CameraDepthTexture, 0, 0, prevDepthData.SSR_PrevDepth_RT, 0, 0);
            }
            ScreenSpaceReflectionBuffer.ReleaseTemporaryRT(SSR_Trace_ID);
            ScreenSpaceReflectionBuffer.ReleaseTemporaryRT(SSR_GetSSRColor_ID);
        }
Exemple #9
0
        private void RenderScreenSpaceReflection(CommandBuffer ScreenSpaceReflectionBuffer, SSRCameraData camData, PipelineCamera cam)
        {
            Vector2Int resolution = new Vector2Int(cam.cam.pixelWidth, cam.cam.pixelHeight);

            ScreenSpaceReflectionBuffer.CopyTexture(cam.targets.depthTexture, 0, 0, camData.SSR_HierarchicalDepth_RT, 0, 0);//TODO
            for (int i = 1; i < 5; ++i)
            {
                ScreenSpaceReflectionBuffer.SetGlobalInt(SSR_HiZ_PrevDepthLevel_ID, i - 1);
                ScreenSpaceReflectionBuffer.SetRenderTarget(camData.SSR_HierarchicalDepth_BackUp_RT, i);
                ScreenSpaceReflectionBuffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, StochasticScreenSpaceReflectionMaterial, 0, RenderPass_HiZ_Depth);
                ScreenSpaceReflectionBuffer.CopyTexture(camData.SSR_HierarchicalDepth_BackUp_RT, 0, i, camData.SSR_HierarchicalDepth_RT, 0, i);
            }
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_HierarchicalDepth_ID, camData.SSR_HierarchicalDepth_RT);

            //////Set SceneColorRT//////
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_SceneColor_ID, cam.targets.renderTargetIdentifier);

            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_Trace_ID, resolution.x / (int)RayCastingResolution, resolution.y / (int)RayCastingResolution, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_Mask_ID, resolution.x / (int)RayCastingResolution, resolution.y / (int)RayCastingResolution, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            SSR_TraceMask_ID[0] = SSR_Trace_ID;
            SSR_TraceMask_ID[1] = SSR_Mask_ID;
            //////RayCasting//////
            if (TraceMethod == TraceApprox.HiZTrace)
            {
                ScreenSpaceReflectionBuffer.BlitMRT(SSR_TraceMask_ID, SSR_TraceMask_ID[0], StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_HiZ3D_MultiSpp : RenderPass_HiZ3D_SingelSpp);
            }
            else
            {
                ScreenSpaceReflectionBuffer.BlitMRT(SSR_TraceMask_ID, SSR_TraceMask_ID[0], StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Linear2D_MultiSPP : RenderPass_Linear2D_SingelSPP);
            }
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_Spatial_ID, resolution.x, resolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.BlitSRTWithDepth(SSR_Spatial_ID, cam.targets.depthBuffer, StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Spatiofilter_MultiSPP : RenderPass_Spatiofilter_SingleSPP);
            //////Temporal filter//////
            ScreenSpaceReflectionBuffer.GetTemporaryRT(SSR_TemporalCurr_ID, resolution.x, resolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_TemporalPrev_ID, camData.SSR_TemporalPrev_RT);
            ScreenSpaceReflectionBuffer.BlitSRTWithDepth(SSR_TemporalCurr_ID, cam.targets.depthBuffer, StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Temporalfilter_MultiSpp : RenderPass_Temporalfilter_SingleSPP);
            ScreenSpaceReflectionBuffer.CopyTexture(SSR_TemporalCurr_ID, 0, 0, camData.SSR_TemporalPrev_RT, 0, 0);
        }
        private void RenderScreenSpaceReflection(CommandBuffer ScreenSpaceReflectionBuffer, SSRCameraData camData, PipelineCamera cam)
        {
            ScreenSpaceReflectionBuffer.CopyTexture(cam.targets.depthTexture, 0, 0, camData.SSR_HierarchicalDepth_RT, 0, 0);//TODO
            for (int i = 1; i < 5; ++i)
            {
                ScreenSpaceReflectionBuffer.SetGlobalInt(SSR_HiZ_PrevDepthLevel_ID, i - 1);
                ScreenSpaceReflectionBuffer.SetRenderTarget(camData.SSR_HierarchicalDepth_BackUp_RT, i);
                ScreenSpaceReflectionBuffer.DrawMesh(GraphicsUtility.mesh, Matrix4x4.identity, StochasticScreenSpaceReflectionMaterial, 0, RenderPass_HiZ_Depth);
                ScreenSpaceReflectionBuffer.CopyTexture(camData.SSR_HierarchicalDepth_BackUp_RT, 0, i, camData.SSR_HierarchicalDepth_RT, 0, i);
            }
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_HierarchicalDepth_ID, camData.SSR_HierarchicalDepth_RT);

            //////Set SceneColorRT//////
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_SceneColor_ID, cam.targets.renderTargetIdentifier);

            //////RayCasting//////
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_Trace_ID, camData.SSR_TraceMask_RT[0]);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_Mask_ID, camData.SSR_TraceMask_RT[1]);
            if (TraceMethod == TraceApprox.HiZTrace)
            {
                ScreenSpaceReflectionBuffer.BlitMRT(camData.SSR_TraceMask_ID, camData.SSR_TraceMask_RT[0], StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_HiZ3D_MultiSpp : RenderPass_HiZ3D_SingelSpp);
            }
            else
            {
                ScreenSpaceReflectionBuffer.BlitMRT(camData.SSR_TraceMask_ID, camData.SSR_TraceMask_RT[0], StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Linear2D_MultiSPP : RenderPass_Linear2D_SingelSPP);
            }
            //////Spatial filter//////
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_Spatial_ID, camData.SSR_Spatial_RT);
            ScreenSpaceReflectionBuffer.BlitSRT(camData.SSR_Spatial_RT, StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Spatiofilter_MultiSPP : RenderPass_Spatiofilter_SingleSPP);
            //////Temporal filter//////
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_TemporalPrev_ID, camData.SSR_TemporalPrev_RT);
            ScreenSpaceReflectionBuffer.SetGlobalTexture(SSR_TemporalCurr_ID, camData.SSR_TemporalCurr_RT);
            ScreenSpaceReflectionBuffer.BlitSRT(camData.SSR_TemporalCurr_RT, StochasticScreenSpaceReflectionMaterial, (RayNums > 1) ? RenderPass_Temporalfilter_MultiSpp : RenderPass_Temporalfilter_SingleSPP);
            ScreenSpaceReflectionBuffer.CopyTexture(camData.SSR_TemporalCurr_RT, 0, 0, camData.SSR_TemporalPrev_RT, 0, 0);
        }