| 199 | } |
| 200 | |
| 201 | void DepthOfFieldPass::Render(RenderContext& renderContext, GPUTexture*& frame, GPUTexture*& tmp) |
| 202 | { |
| 203 | DepthOfFieldSettings& dofSettings = renderContext.List->Settings.DepthOfField; |
| 204 | const bool useDoF = EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::DepthOfField) && dofSettings.Enabled; |
| 205 | if (!useDoF || !_platformSupportsDoF || checkIfSkipPass()) |
| 206 | return; |
| 207 | auto device = GPUDevice::Instance; |
| 208 | auto context = device->GetMainContext(); |
| 209 | const auto depthBuffer = renderContext.Buffers->DepthBuffer; |
| 210 | const auto shader = _shader->GetShader(); |
| 211 | PROFILE_GPU_CPU("Depth Of Field"); |
| 212 | |
| 213 | context->ResetSR(); |
| 214 | |
| 215 | // Resolution settings |
| 216 | // TODO: render depth of field in 1/4 resolution? |
| 217 | const int32 cocResolutionDivider = 1; |
| 218 | const int32 dofResolutionDivider = 1; |
| 219 | const int32 bokehResolutionDivider = 1; |
| 220 | // TODO: in low-res DoF maybe use shared HalfResDepth? |
| 221 | const int32 w1 = frame->Width(); |
| 222 | const int32 h1 = frame->Height(); |
| 223 | const int32 cocWidth = w1 / cocResolutionDivider; |
| 224 | const int32 cocHeight = h1 / cocResolutionDivider; |
| 225 | const int32 dofWidth = w1 / dofResolutionDivider; |
| 226 | const int32 dofHeight = h1 / dofResolutionDivider; |
| 227 | const int32 bokehTargetWidth = w1 / bokehResolutionDivider; |
| 228 | const int32 bokehTargetHeight = h1 / bokehResolutionDivider; |
| 229 | float textureSizeScale = (float)Math::Max(w1, h1) * (1.0f / 1920.0f); // Keep DOF blur the same no matter the image resolution is (reference FullHD res) |
| 230 | int32 blurScalePermutationOffset = 0; |
| 231 | const float sampleRadius[] = { 1.0f, 3.6f }; // This has to match CS_DepthOfField permutations |
| 232 | if (textureSizeScale > sampleRadius[0]) |
| 233 | { |
| 234 | blurScalePermutationOffset += 2; |
| 235 | textureSizeScale /= sampleRadius[1]; |
| 236 | } |
| 237 | |
| 238 | // TODO: maybe we could render particles (whole transparency in general) to the depth buffer to apply DoF on them as well? |
| 239 | |
| 240 | // Setup constant buffer |
| 241 | { |
| 242 | float nearPlane = renderContext.View.Near; |
| 243 | float farPlane = renderContext.View.Far; |
| 244 | |
| 245 | float focalRegionHalf = dofSettings.FocalRegion * 0.5f; |
| 246 | float nearFocusEnd = Math::Max(0.0f, dofSettings.FocalDistance - focalRegionHalf); |
| 247 | float nearFocusStart = Math::Max(0.0f, nearFocusEnd - dofSettings.NearTransitionRange); |
| 248 | float farFocusStart = Math::Min(farPlane - 5.0f, dofSettings.FocalDistance + focalRegionHalf); |
| 249 | float farFocusEnd = Math::Min(farPlane - 5.0f, farFocusStart + dofSettings.FarTransitionRange); |
| 250 | float depthLimitMax = farPlane - 10.0f; |
| 251 | |
| 252 | Data cbData; |
| 253 | cbData.DOFDepths.X = nearFocusStart; |
| 254 | cbData.DOFDepths.Y = nearFocusEnd; |
| 255 | cbData.DOFDepths.Z = farFocusStart; |
| 256 | cbData.DOFDepths.W = farFocusEnd; |
| 257 | cbData.MaxBokehSize = dofSettings.BokehSize; |
| 258 | cbData.BokehBrightnessThreshold = dofSettings.BokehBrightnessThreshold; |
nothing calls this directly
no test coverage detected