QmlMaterial 0.1.0
Loading...
Searching...
No Matches
skia_shadow.h File Reference

High-fidelity shadow rendering based on Skia's analytic shadow model. More...

#include <QRectF>
#include <QVector2D>
#include <QVector4D>
#include <QColor>
#include <optional>
#include <array>
#include "qml_material/scenegraph/geometry.h"

Go to the source code of this file.

Functions

scalar qml_material::sk::AmbientBlurRadius (scalar height)
 Calculates the blur radius for ambient shadows based on Z-height.
 
scalar qml_material::sk::AmbientRecipAlpha (scalar height)
 Calculates the reciprocal alpha for ambient shadows to adjust intensity.
 
void qml_material::sk::GetSpotParams (scalar occluderZ, scalar lightX, scalar lightY, scalar lightZ, scalar lightRadius, scalar *blurRadius, scalar *scale, QVector2D *translate)
 Calculates spot shadow parameters based on a virtual point light source.
 
void qml_material::sk::GetDirectionalParams (scalar occluderZ, scalar lightX, scalar lightY, scalar lightZ, scalar lightRadius, scalar *blurRadius, scalar *scale, QVector2D *translate)
 Calculates directional shadow parameters (simplified spot model).
 

Detailed Description

High-fidelity shadow rendering based on Skia's analytic shadow model.

Architecture Overview

This module implements a specialized mesh generator for Material Design 3 shadows. Instead of using Gaussian blur (which is expensive and hard to clip), we use:

  1. Analytic Geometry: A 9-patch mesh where corners are vertex fans.
  2. Distance Fields: Vertices carry a 2D "offset" representing the normalized distance to the nearest edge/corner.
  3. LUT-based Falloff: The fragment shader uses these offsets to sample a 1D strength texture (fade-off LUT) to create smooth, physically-accurate penumbras.

Mesh Structure (Rounded Rectangle)

The mesh consists of 4 corners (6 vertices each) and an optional inner quad for overstroked shadows.

Function Documentation

◆ GetDirectionalParams()

void qml_material::sk::GetDirectionalParams ( scalar occluderZ,
scalar lightX,
scalar lightY,
scalar lightZ,
scalar lightRadius,
scalar * blurRadius,
scalar * scale,
QVector2D * translate )

Calculates directional shadow parameters (simplified spot model).

Calculates directional shadow parameters. This is a simplified version of the spot model where the light source is assumed to be at infinity.

◆ GetSpotParams()

void qml_material::sk::GetSpotParams ( scalar occluderZ,
scalar lightX,
scalar lightY,
scalar lightZ,
scalar lightRadius,
scalar * blurRadius,
scalar * scale,
QVector2D * translate )

Calculates spot shadow parameters based on a virtual point light source.

Calculates spot shadow geometry parameters based on a point light model. zRatio determines the blur radius and the projection scale of the shadow.