Easy3D 2.6.1
Loading...
Searching...
No Matches
SoftShadow Class Reference

An implementation of the Percentage-Closer Soft Shadows. More...

#include <easy3d/renderer/soft_shadow.h>

Inheritance diagram for SoftShadow:
Shadow

Public Types

enum  SamplePattern {
  SP_Poisson_25_25 = 0 , SP_Poisson_32_64 = 1 , SP_Poisson_64_128 = 2 , SP_Poisson_100_100 = 3 ,
  SP_Regular_49_225 = 4
}
 The sample pattern used for blocker search and PCF filtering. More...
 

Public Member Functions

 SoftShadow (Camera *cam)
 Constructor.
 
 ~SoftShadow () override=default
 Destructor.
 
float softness () const
 Get the softness of the shadow.
 
void set_softness (float s)
 Set the softness of the shadow.
 
SamplePattern sample_pattern () const
 Get the sample pattern used for blocker search and PCF filtering.
 
void set_sample_pattern (SamplePattern pattern)
 Set the sample pattern used for blocker search and PCF filtering.
 
- Public Member Functions inherited from Shadow
 Shadow (Camera *cam)
 Constructor.
 
bool virtual_background () const
 
void set_virtual_background (bool b)
 Enable/Disable the virtual background.
 
const vec4virtual_background_color (const vec4 &c)
 Query the virtual background color.
 
void set_virtual_background_color (const vec4 &c)
 Set the virtual background color.
 
int shadow_map_size () const
 Query the size of the shadow map. The shadow is assumed to be square.
 
void set_shadow_map_size (int size)
 Set/Change the size of the shadow map. The shadow is assumed to be square. Default: 1024 by 1024.
 
float light_distance () const
 The distance of the light source to the scene (w.r.t. the scene radius).
 
void set_light_distance (float dist)
 
float darkness () const
 
void set_darkness (float darkness)
 
void draw (const std::vector< TrianglesDrawable * > &surfaces)
 Rendering the surfaces.
 

Detailed Description

An implementation of the Percentage-Closer Soft Shadows.

SoftShadow implements the Percentage-Closer Soft Shadows technique. See

— Overview — This sample demonstrates two techniques for rendering soft shadows: Percentage Closer Filtering (PCS) with a uniform kernel size and Percentage-Closer Soft Shadows (PCSS) with a variable kernel size. This sample is assuming the shadow map is a regular depth buffer (non-linear depths), and the shadow-map is generated using a perspective projection with the center of projection at the center of the area light simulated by PCSS. The sample uses a gradient-based depth bias to scale the depth bias based on the uv-space distance from the center of the kernel. To avoid self-shadowing artifacts, an additional depth bias may also been applied while writing depth into the shadow map.

— Percentage Closer Filtering (PCF) — The Percentage Closer Filtering technique uses a uniform size filter kernel, resulting in shadows with a uniformly soft edge. The PCF algorithm is very straightforward and fast, but does not achieve a realistic contact hardening effect. Also, while the kernel size and penumbra width is uniform, the kernel can be scaled to accommodate different sized lights.

— Percentage-Closer Soft Shadows (PCSS) — Soft shadows are typically rendered in games by using shadow mapping and Percentage Closer Filtering with a uniform kernel size. The Percentage-Closer Soft Shadows (PCSS) algorithm computes a variable kernel size based on the distance between the relative position of the receiver point, an approximation of the blocker, and the area light. It produces perceptually plausible soft shadows that harden on contact.

Optimization tips: rendering with multi-effects (e.g., shadowing, SSAO) can benefit from sharing the same geometry pass.

Examples
Tutorial_503_SoftShadow/main.cpp.

Member Enumeration Documentation

◆ SamplePattern

The sample pattern used for blocker search and PCF filtering.

Enumerator
SP_Poisson_25_25 

25 samples for the blocker search, 25 samples in the PCF filtering, all samples using a Poisson disk

SP_Poisson_32_64 

32 samples for the blocker search, 64 samples for the PCF filtering, all samples using a Poisson disk

SP_Poisson_64_128 

64 samples for the blocker search, 128 samples for the PCF filtering, all samples using a Poisson disk

SP_Poisson_100_100 

100 samples for the blocker search, 100 samples for the PCF filtering, all samples using a Poisson disk

SP_Regular_49_225 

49 samples for the blocker search, 225 samples for the PCF filtering, all samples using regular sampling (faster than Poisson disk)

Constructor & Destructor Documentation

◆ SoftShadow()

SoftShadow ( Camera * cam)
explicit

Constructor.

Parameters
camThe camera used in the view.

Member Function Documentation

◆ sample_pattern()

SamplePattern sample_pattern ( ) const
inline

Get the sample pattern used for blocker search and PCF filtering.

Returns
The sample pattern.

◆ set_sample_pattern()

void set_sample_pattern ( SamplePattern pattern)
inline

Set the sample pattern used for blocker search and PCF filtering.

Parameters
patternThe sample pattern.

◆ set_softness()

void set_softness ( float s)
inline

Set the softness of the shadow.

Parameters
sThe softness of the shadow, must be in the range [0, 1].

◆ softness()

float softness ( ) const
inline

Get the softness of the shadow.

Returns
The softness of the shadow, in the range [0, 1]. Default is 0.5.

The documentation for this class was generated from the following files: