Exemple #1
0
        private void RenderSSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer           = data.buffer;
            int2          renderResolution = int2(cam.cam.pixelWidth, cam.cam.pixelHeight);

            buffer.GetTemporaryRT(_GTAO_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear);
            buffer.GetTemporaryRT(_BentNormal_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            AO_BentNormal_ID[0] = _GTAO_Texture_ID;
            AO_BentNormal_ID[1] = _BentNormal_Texture_ID;
            //Resolve GTAO
            buffer.BlitMRT(AO_BentNormal_ID, cam.targets.renderTargetIdentifier, GTAOMaterial, 0);

            //Spatial filter
            //------//XBlur
            buffer.GetTemporaryRT(_GTAO_Spatial_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf);
            buffer.BlitSRTWithDepth(_GTAO_Spatial_Texture_ID, cam.targets.depthBuffer, GTAOMaterial, 1);
            //------//YBlur
            buffer.CopyTexture(_GTAO_Spatial_Texture_ID, AO_BentNormal_ID[0]);
            buffer.BlitSRTWithDepth(_GTAO_Spatial_Texture_ID, cam.targets.depthBuffer, GTAOMaterial, 2);

            //Temporal filter
            buffer.SetGlobalTexture(_PrevRT_ID, historyData.prev_Texture);
            buffer.GetTemporaryRT(_CurrRT_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf);
            buffer.BlitSRTWithDepth(_CurrRT_ID, cam.targets.depthBuffer, GTAOMaterial, 3);
            buffer.CopyTexture(_CurrRT_ID, historyData.prev_Texture);

            buffer.ReleaseTemporaryRT(_GTAO_Spatial_Texture_ID);
            buffer.ReleaseTemporaryRT(_CurrRT_ID);
            buffer.ReleaseTemporaryRT(_Combien_AO_RT_ID);
            buffer.ReleaseTemporaryRT(_GTAO_Texture_ID);
            buffer.ReleaseTemporaryRT(_BentNormal_Texture_ID);
            buffer.SetGlobalTexture(ShaderIDs._AOROTexture, historyData.prev_Texture);
        }
Exemple #2
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            AOHistoryData historyData = IPerCameraData.GetProperty(cam, (c) => new AOHistoryData(c.cam.pixelWidth, c.cam.pixelHeight), this);

            UpdateVariable_SSAO(historyData, cam, ref data);
            RenderSSAO(historyData, cam, ref data);
        }
Exemple #3
0
        private void RenderSSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data, int2 renderResolution, int2 originResolution)
        {
            CommandBuffer buffer = data.buffer;

            buffer.GetTemporaryRT(_GTAO_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear);
            buffer.GetTemporaryRT(_BentNormal_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Bilinear, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
            AO_BentNormal_ID[0] = _GTAO_Texture_ID;
            AO_BentNormal_ID[1] = _BentNormal_Texture_ID;
            //Resolve GTAO
            buffer.BlitMRT(AO_BentNormal_ID, _GTAO_Texture_ID, GTAOMaterial, 0);

            //Spatial filter
            //------//XBlur
            buffer.GetTemporaryRT(_GTAO_Spatial_Texture_ID, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf);
            buffer.BlitSRT(_GTAO_Spatial_Texture_ID, GTAOMaterial, 1);
            //------//YBlur
            buffer.CopyTexture(_GTAO_Spatial_Texture_ID, AO_BentNormal_ID[0]);
            buffer.BlitSRT(_GTAO_Spatial_Texture_ID, GTAOMaterial, 2);
            buffer.GetTemporaryRT(_UpSampleRT, renderResolution.x, renderResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf);
            buffer.BlitSRT(_UpSampleRT, GTAOMaterial, 4);
            //Temporal filter
            buffer.SetGlobalTexture(_PrevRT_ID, historyData.prev_Texture);
            buffer.GetTemporaryRT(_CurrRT_ID, originResolution.x, originResolution.y, 0, FilterMode.Point, RenderTextureFormat.RGHalf);
            buffer.BlitSRT(_CurrRT_ID, GTAOMaterial, 3);
            buffer.CopyTexture(_CurrRT_ID, historyData.prev_Texture);
            buffer.ReleaseTemporaryRT(_GTAO_Spatial_Texture_ID);
            buffer.ReleaseTemporaryRT(_CurrRT_ID);
            buffer.ReleaseTemporaryRT(_UpSampleRT);
            buffer.ReleaseTemporaryRT(_GTAO_Texture_ID);
            buffer.ReleaseTemporaryRT(_BentNormal_Texture_ID);
            buffer.SetGlobalTexture(ShaderIDs._AOROTexture, historyData.prev_Texture);
            //     buffer.Blit(historyData.prev_Texture, BuiltinRenderTextureType.CameraTarget, debugMat, 0);
        }
        ////////////////////////SSAO Function////////////////////////
        private void UpdateVariable_SSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data)
        {
            CommandBuffer buffer           = data.buffer;
            int2          renderResolution = int2(cam.cam.pixelWidth, cam.cam.pixelHeight);

            buffer.SetGlobalMatrix(ShaderIDs._VP, data.vp);
            buffer.SetGlobalMatrix(_WorldToCameraMatrix_ID, cam.cam.worldToCameraMatrix);
            buffer.SetGlobalMatrix(_CameraToWorldMatrix_ID, cam.cam.cameraToWorldMatrix);
            buffer.SetGlobalMatrix(_ProjectionMatrix_ID, GL.GetGPUProjectionMatrix(cam.cam.projectionMatrix, false));;
            buffer.SetGlobalMatrix(_View_ProjectionMatrix_ID, data.vp);
            buffer.SetGlobalMatrix(_Inverse_View_ProjectionMatrix_ID, data.inverseVP);
            buffer.SetGlobalMatrix(_LastFrameViewProjectionMatrix_ID, propertySetEvent.lastViewProjection);

            //----------------------------------------------------------------------------------
            buffer.SetGlobalFloat(_AO_DirSampler_ID, DirSampler);
            buffer.SetGlobalFloat(_AO_SliceSampler_ID, SliceSampler);
            buffer.SetGlobalFloat(_AO_Intensity_ID, Intensity);
            buffer.SetGlobalFloat(_AO_Radius_ID, Radius);
            buffer.SetGlobalFloat(_AO_Power_ID, Power);
            buffer.SetGlobalFloat(_AO_Sharpeness_ID, Sharpeness);
            buffer.SetGlobalFloat(_AO_TemporalScale_ID, TemporalScale);
            buffer.SetGlobalFloat(_AO_TemporalResponse_ID, TemporalResponse);
            buffer.SetGlobalInt(_AO_MultiBounce_ID, MultiBounce ? 1 : 0);


            //----------------------------------------------------------------------------------
            float   fovRad        = cam.cam.fieldOfView * Mathf.Deg2Rad;
            float   invHalfTanFov = 1 / Mathf.Tan(fovRad * 0.5f);
            Vector2 focalLen      = new Vector2(invHalfTanFov * ((float)renderResolution.y / (float)renderResolution.x), invHalfTanFov);
            Vector2 invFocalLen   = new Vector2(1 / focalLen.x, 1 / focalLen.y);

            buffer.SetGlobalVector(_AO_UVToView_ID, new Vector4(2 * invFocalLen.x, 2 * invFocalLen.y, -1 * invFocalLen.x, -1 * invFocalLen.y));

            //----------------------------------------------------------------------------------
            float projScale;

            projScale = renderResolution.y / (Mathf.Tan(fovRad * 0.5f) * 2) * 0.5f;
            buffer.SetGlobalFloat(_AO_HalfProjScale_ID, projScale);

            //----------------------------------------------------------------------------------
            oneOverSize_Size = new Vector4(1 / (float)renderResolution.x, 1 / (float)renderResolution.y, (float)renderResolution.x, (float)renderResolution.y);
            buffer.SetGlobalVector(_AO_RT_TexelSize_ID, oneOverSize_Size);

            //----------------------------------------------------------------------------------
            float temporalRotation = m_temporalRotations[m_sampleStep % 6];
            float temporalOffset   = m_spatialOffsets[(m_sampleStep / 6) % 4];

            buffer.SetGlobalFloat(_AO_TemporalDirections_ID, temporalRotation / 360);
            buffer.SetGlobalFloat(_AO_TemporalOffsets_ID, temporalOffset);
            m_sampleStep++;

            //----------------------------------------------------------------------------------
            //TODO
            //Resize
            historyData.UpdateSize(renderResolution.x, renderResolution.y);
        }
Exemple #5
0
        public override void FrameUpdate(PipelineCamera cam, ref PipelineCommandData data)
        {
            int2         res       = int2(cam.cam.pixelWidth, cam.cam.pixelHeight);
            int2         originRes = int2(cam.cam.pixelWidth, cam.cam.pixelHeight);
            GetDataEvent evt       = new GetDataEvent
            {
                res = res
            };
            AOHistoryData historyData = IPerCameraData.GetProperty <AOHistoryData, GetDataEvent>(cam, evt);

            UpdateVariable_SSAO(historyData, cam, ref data, res, originRes);
            RenderSSAO(historyData, cam, ref data, res, originRes);
        }
Exemple #6
0
        ////////////////////////SSAO Function////////////////////////
        private void UpdateVariable_SSAO(AOHistoryData historyData, PipelineCamera cam, ref PipelineCommandData data, int2 renderResolution, int2 originResolution)
        {
            CommandBuffer buffer = data.buffer;
            Vector4       oneOverSize_Size;
            //----------------------------------------------------------------------------------
            float   fovRad        = cam.cam.fieldOfView * Mathf.Deg2Rad;
            float   invHalfTanFov = 1 / Mathf.Tan(fovRad * 0.5f);
            Vector2 focalLen      = new Vector2(invHalfTanFov * ((float)renderResolution.y / (float)renderResolution.x), invHalfTanFov);
            Vector2 invFocalLen   = new Vector2(1 / focalLen.x, 1 / focalLen.y);

            //----------------------------------------------------------------------------------
            float projScale;

            projScale = renderResolution.y / (Mathf.Tan(fovRad * 0.5f) * 2) * 0.5f;

            //----------------------------------------------------------------------------------
            oneOverSize_Size = new Vector4(1 / (float)renderResolution.x, 1 / (float)renderResolution.y, (float)renderResolution.x, (float)renderResolution.y);
            //----------------------------------------------------------------------------------
            float temporalRotation = m_temporalRotations[m_sampleStep % 6];
            float temporalOffset   = m_spatialOffsets[(m_sampleStep / 6) % 4];

            m_sampleStep++;
            NativeArray <AOData> datas = new NativeArray <AOData>(1, Allocator.Temp);
            AOData *dataPtr            = datas.Ptr();

            dataPtr->worldToCamera     = cam.cam.worldToCameraMatrix;
            dataPtr->cameraToWorld     = cam.cam.cameraToWorldMatrix;
            dataPtr->inverseVP         = proper.inverseVP;
            dataPtr->dirSampler        = DirSampler;
            dataPtr->sliceSampler      = SliceSampler;
            dataPtr->intensity         = Intensity;
            dataPtr->radius            = Radius;
            dataPtr->power             = Power;
            dataPtr->sharpness         = Sharpeness;
            dataPtr->temporalScale     = TemporalScale;
            dataPtr->temporalResponse  = TemporalResponse;
            dataPtr->uvToView          = new Vector4(2 * invFocalLen.x, 2 * invFocalLen.y, -1 * invFocalLen.x, -1 * invFocalLen.y);
            dataPtr->halfProjScale     = projScale;
            dataPtr->texelSize         = oneOverSize_Size;
            dataPtr->temporalDirection = temporalRotation / 360;
            dataPtr->temporalOffset    = temporalOffset;
            dataBuffer.SetData(datas);
            datas.Dispose();
            buffer.SetGlobalConstantBuffer(dataBuffer, _AOData, 0, dataBuffer.stride);
            //----------------------------------------------------------------------------------
            //TODO
            //Resize
            historyData.UpdateSize(originResolution.x, originResolution.y);
        }