• Postprocess

Simple depth of field parameters

By: SKY ENGINE AI
scroll down ↓to find out moresimple-depth-of-field-parameters_2_resourcesTutorial

Simple Depth of Field Postprocess step parameters

In this case we will present you how to parametrize Simple Depth of Field step.

Agenda:

  • SimpleDepthOfFieldPostprocess parameters
  • Focus distance manipulation
  • dof manipulation

SimpleDepthOfFieldPostprocess parameters

We can modify the SimpleDepthOfFieldPostprocess step with different parameters.

  • focus_distance - distance from the lens to the focus plane in mm. Objects in this distance will be the sharpest
  • dof - rough estimate of desired depth of field in mm.
  • specific_heat - numeric value of the specific heat used by the diffusion simulation.
  • alpha_threshold - threshold for calculating blurring contribution in the diffuse
    simulation. Pixels with a circle of confusion above this value would not be additionally blurred.

Scene setup

Let's use custom scene composer to set up the scene.
Scene consists of:

  • 3 shaderballs - locations: (0, 0, 0), (2, 0, 4), (4, 0, 8),
  • camera - location: (2, 1, 12)
  • direction light - direction: (1, -1, -1)
from skyrenderer.cases.utils import DepthOfFieldSceneComposer scene_composer = DepthOfFieldSceneComposer() scene_composer.setup_scene()
2025-02-04 15:02:19,403 | skyrenderer.scene.renderer_context | INFO: Root paths: - root path: /dli/skyenvironment/skyrenderer/skyrenderer - assets path: /dli/mount/assets - config path: /dli/skyenvironment/skyrenderer/skyrenderer/config - gpu sources path: /dli/skyenvironment/skyrenderer/skyrenderer/optix_sources/sources - cache path: /dli/mount/cache - ptx cache path: compiled_ptx/ptx - ocio path: ocio_configs/aces_1.2/config.ocio top_node |-- shaderball_GEO |-- camera_target_NUL +-- camera_origin_NUL

Focus distance manipulation

We will generate two renders using different focus_distance parameter.
Two renders will show furthest and closest shaderball as the sharpest.

from skyrenderer.render_chain.postprocess_steps.simple_depth_of_field import SimpleDepthOfFieldPostprocess from skyrenderer.render_chain import RenderChain

Create first render - focus on the furthest shaderball

distance_to_furthest = 12201 dof_params = SimpleDepthOfFieldPostprocess.create_parameter_provider( scene_composer.renderer_context, dof=3000, focus_distance=distance_to_furthest ) simple_dof_step = SimpleDepthOfFieldPostprocess(scene_composer.renderer_context, parameter_provider=dof_params) scene_composer.renderer_context.define_render_chain( RenderChain( render_steps=[scene_composer.visible_light_render_step, simple_dof_step], width=800, height=800, ), ) furthest_render = scene_composer.get_render()
2025-02-04 15:02:19,836 | skyrenderer.utils.time_measurement | INFO: Setup time: 385 ms 2025-02-04 15:02:22,647 | skyrenderer.utils.time_measurement | INFO: Context update time: 2.81 seconds 2025-02-04 15:02:26,154 | skyrenderer.utils.time_measurement | INFO: Key points calculation time: 0 ms 2025-02-04 15:02:26,155 | skyrenderer.utils.time_measurement | INFO: Render time: 3.51 seconds

Create second render - focus on the closest shaderball

distance_to_closest = 4583 dof_params = SimpleDepthOfFieldPostprocess.create_parameter_provider( scene_composer.renderer_context, dof=3000, focus_distance=distance_to_closest ) simple_dof_step = SimpleDepthOfFieldPostprocess(scene_composer.renderer_context, parameter_provider=dof_params) scene_composer.renderer_context.define_render_chain( RenderChain( render_steps=[scene_composer.visible_light_render_step, simple_dof_step], width=800, height=800, ), ) closest_render = scene_composer.get_render() render_dict = {"Focus on furthest": furthest_render, "Focus on closest": closest_render} scene_composer.visualize_grid_desc(render_dict, shape=(800, 1600), n_cols=2)
simple-depth-of-field-parameters_1_resourcesTutorial
2025-02-04 15:02:26,244 | skyrenderer.utils.time_measurement | INFO: Setup time: 60 ms 2025-02-04 15:02:29,162 | skyrenderer.utils.time_measurement | INFO: Context update time: 2.92 seconds 2025-02-04 15:02:32,531 | skyrenderer.utils.time_measurement | INFO: Key points calculation time: 0 ms 2025-02-04 15:02:32,532 | skyrenderer.utils.time_measurement | INFO: Render time: 3.37 seconds

dof manipulation

The next two renders will show the effect of manipulation of dof parameter.
On the second render the objects will be more blurred.

Create first render - the furthest shaderball will be just slightly blurred

dof_params = SimpleDepthOfFieldPostprocess.create_parameter_provider( scene_composer.renderer_context, dof=4000, focus_distance=distance_to_closest ) simple_dof_step = SimpleDepthOfFieldPostprocess(scene_composer.renderer_context, parameter_provider=dof_params) scene_composer.renderer_context.define_render_chain( RenderChain( render_steps=[scene_composer.visible_light_render_step, simple_dof_step], width=800, height=800, ), ) slight_blur_render = scene_composer.get_render()
2025-02-04 15:02:32,768 | skyrenderer.utils.time_measurement | INFO: Setup time: 54 ms 2025-02-04 15:02:35,641 | skyrenderer.utils.time_measurement | INFO: Context update time: 2.87 seconds 2025-02-04 15:02:38,822 | skyrenderer.utils.time_measurement | INFO: Key points calculation time: 0 ms 2025-02-04 15:02:38,823 | skyrenderer.utils.time_measurement | INFO: Render time: 3.18 seconds

Create second render - focus on the closest shaderball

dof_params = SimpleDepthOfFieldPostprocess.create_parameter_provider( scene_composer.renderer_context, dof=2000, focus_distance=distance_to_closest ) simple_dof_step = SimpleDepthOfFieldPostprocess(scene_composer.renderer_context, parameter_provider=dof_params) scene_composer.renderer_context.define_render_chain( RenderChain( render_steps=[scene_composer.visible_light_render_step, simple_dof_step], width=800, height=800, ), ) strong_blur_render = scene_composer.get_render() render_dict = {"DOF: 4000": slight_blur_render, "DOF: 2000": strong_blur_render} scene_composer.visualize_grid_desc(render_dict, shape=(800, 1600), n_cols=2)
simple-depth-of-field-parameters_2_resourcesTutorial
2025-02-04 15:02:38,891 | skyrenderer.utils.time_measurement | INFO: Setup time: 53 ms 2025-02-04 15:02:41,739 | skyrenderer.utils.time_measurement | INFO: Context update time: 2.85 seconds 2025-02-04 15:02:44,945 | skyrenderer.utils.time_measurement | INFO: Key points calculation time: 0 ms 2025-02-04 15:02:44,946 | skyrenderer.utils.time_measurement | INFO: Render time: 3.21 seconds

Summary

In this section you have learnt:

  • You can set focus on an object or objects you choose using focus_distance parameter.
  • You can modify the blurriness of objects closer or further from focus_distance using dof parameter.