• Shader

Skin shader

By: SKY ENGINE AI
scroll down ↓to find out moreskin-shader_2_resourcesTutorial

SkinShader

In this tutorial you will get familiar with SkinShader, which is a crucial aspect of rendering realistic human
characters in SkyRenderer as it involves simulating how light interacts with the unique properties of skin.

Agenda:

  • Skin shading theory
  • SkinShader basic usage

Scene setup

Let's use custom scene composer to set up the scene.

    from skyrenderer.cases.utils import HeadSceneComposer
    scene_composer = HeadSceneComposer(antialiasing_level=32)
    scene_composer.setup_scene(width=1400, height=900)
    scene_composer.visualize()
skin-shader_1_resourcesTutorial
2025-02-05 08:37:00,101 | 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

2025-02-05 08:37:01,895 | skyrenderer.utils.time_measurement |  INFO: Setup time: 1.02 seconds

2025-02-05 08:37:02,137 | skyrenderer.utils.time_measurement |  INFO: Context update time: 241 ms

2025-02-05 08:37:15,413 | skyrenderer.utils.time_measurement |  INFO: Key points calculation time: 0 ms

2025-02-05 08:37:15,416 | skyrenderer.utils.time_measurement |  INFO: Render time: 13.28 seconds

Skin shading theory

Skin shading is a crucial aspect of rendering realistic human characters in computer graphics, as it involves
simulating how light interacts with the unique properties of skin. Human skin consists of multiple layers, each
with varying optical characteristics that affect light absorption, scattering, and reflection. Unlike opaque
surfaces, where light primarily reflects off the surface, skin allows light to penetrate its layers, creating
soft, diffused lighting effects. This interaction between light and skin's subsurface layers, including the
epidermis and dermis, results in phenomena like subsurface scattering (SSS), which gives skin its natural,
translucent appearance. Accurate skin shading models are essential for achieving lifelike visuals, particularly
in photorealistic rendering and character animation.

The Subsurface Scattering (SSS) Random Walk implementation of SkinShader models the complex interaction of
light within translucent materials, such as human skin. Subsurface scattering occurs when light penetrates a
surface, scatters internally, and exits at a different point. This effect is crucial for realistic rendering
of materials like skin, where light bounces between multiple layers.

In a full Monte Carlo approach, photons are traced as they randomly walk through the medium. Each photon path
is simulated by probabilistically scattering or absorbing based on the material's optical properties - such as
scattering coefficient, absorption coefficient, and phase function. The random walk continues until the photon
is either absorbed or exits the material, contributing to the final shading result. SkinShader uses this
Monte Carlo random walk model to simulate subsurface scattering more accurately than approximate diffusion
methods. This technique accounts for various skin layers, each with unique optical properties, and generates
a realistic soft appearance, particularly important for human skin in physically based rendering (PBR).

In SkyRenderer, SkinShader implements full Monte Carlo SSS to accurately simulate light transport within
translucent materials, leveraging physical properties of skin to achieve photorealistic results in real-time
applications.

Here are a few references that provide further information on skin shading and subsurface scattering techniques:

  1. Habel, R., & Jensen, H. W. (2010). Geometrically Based Photon Mapping for Accurate Subsurface Scattering. ACM
    Transactions on Graphics (TOG), 29(6), 1-10.
    2.Krayevoy, V., & Geiss, R. (2018). Efficient Random-Walk Subsurface Scattering. ACM SIGGRAPH 2018 Talks.
  2. Habel, R., Borsdorf, J., & Wimmer, M. (2013). Physically Based Real-Time Translucency for Single Scattering
    with Light Impacts. Computer Graphics Forum, 32(4), 189-199.

SkinShader basic usage

Let's create a Material Definition using SkinShader and assign this material to the head.
To assign the material we will use RendererContext's set_material_definition() method.
In order to check, how different parameters affects SkinShader appearance, see SHADER_SkinShaderParameters
tutorial.

    from skyrenderer.scene.scene_layout.layout_elements_definitions import MaterialDefinition
    from skyrenderer.basic_types.procedure.shader.basic_shaders import SkinShader
    from skyrenderer.basic_types.provider import FileTextureProvider
    skin_shader = SkinShader(scene_composer.renderer_context)
    skin_parameter_provider = SkinShader.create_parameter_provider(
        scene_composer.renderer_context,
        specular_factor=0.15,
        normal_map_gain=0.6,
        ss_gain=0.2,
        ior=1.4,
        fresnel_factor=0.25,
        use_reflections=True,
    )
    material_definition = MaterialDefinition(
        shader=skin_shader,
        parameter_set=skin_parameter_provider,
        texture_provider=FileTextureProvider(scene_composer.renderer_context, "seeing_machines_dms/HeadOnly"),
    )
    scene_composer.renderer_context.set_material_definition(
        node_name="OnlyHead_GEO_HeadOnly", material_definition=material_definition
    )
    scene_composer.visualize()
skin-shader_2_resourcesTutorial
2025-02-05 08:37:15,744 | skyrenderer.utils.time_measurement |  INFO: Setup time: 75 ms

2025-02-05 08:37:17,973 | skyrenderer.utils.time_measurement |  INFO: Context update time: 2.23 seconds

2025-02-05 08:38:13,448 | skyrenderer.utils.time_measurement |  INFO: Key points calculation time: 0 ms

2025-02-05 08:38:13,450 | skyrenderer.utils.time_measurement |  INFO: Render time: 55.48 seconds

Summary

In this section you have learnt:

  • Skin shading is a crucial aspect of rendering realistic human characters as it involves simulating how light
    interacts with the unique properties of skin.
  • SkinShader is defined in the same way as any other procedure.