Easy3D 2.6.1
|
An implementation of the Percentage-Closer Soft Shadows. More...
#include <easy3d/renderer/soft_shadow.h>
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. | |
![]() | |
Shadow (Camera *cam) | |
Constructor. | |
bool | virtual_background () const |
void | set_virtual_background (bool b) |
Enable/Disable the virtual background. | |
const vec4 & | virtual_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. | |
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.
enum SamplePattern |
The sample pattern used for blocker search and PCF filtering.
|
explicit |
Constructor.
cam | The camera used in the view. |
|
inline |
Get the sample pattern used for blocker search and PCF filtering.
|
inline |
Set the sample pattern used for blocker search and PCF filtering.
pattern | The sample pattern. |
|
inline |
Set the softness of the shadow.
s | The softness of the shadow, must be in the range [0, 1]. |
|
inline |
Get the softness of the shadow.