////////////////////////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);
        }
示例#2
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);
        }