Controllable Shadow Generation Using Pixel Height Maps

Yichen Sheng, Yifan Liu, Jianming Zhang, Wei Yin, A. Cengiz Öztireli, He Zhang, Zhe Lin, Eli Shechtman, Bedrich Benes

Abstract

Generating realistic shadows for 2D image cutouts is a fundamental challenge in image compositing. Traditional physics-based methods require unavailable 3D geometry, while current deep-learning approaches often lack user controllability and geometric accuracy. This paper introduces a novel framework based on "Pixel Height," a 2.5D representation that enables precise shadow synthesis. By decoupling the process into a geometric projection phase and a neural softening phase, the proposed system allows for real-time adjustments of light direction and shadow softness, significantly outperforming state-of-the-art methods in both quantitative metrics and human preference studies.

Introduction

When compositing a 2D cutout—such as a person or an object—into a new background, the absence of a realistic shadow immediately breaks the illusion of presence. Creating these shadows manually is labor-intensive, and automated solutions have historically faced a trade-off between realism and control.

Physics-based rendering produces high-fidelity results but necessitates full 3D models, which are rarely available for arbitrary 2D images. Conversely, deep learning-based methods, such as Generative Adversarial Networks (GANs), can predict shadows directly from 2D inputs. However, these "black box" models offer little to no control over environmental parameters like light direction or shadow softness and frequently produce results with geometric distortions. This research bridges the gap by introducing a 2.5D proxy that combines the geometric rigor of 3D rendering with the flexibility of neural networks.

Methodology: The Pixel Height Framework

The authors propose a three-stage pipeline that separates the geometric placement of a shadow from its visual appearance.

1. Pixel Height Estimation (HENet)

The core innovation is the concept of "Pixel Height"—defined as the pixel distance between a point on an object and its vertical projection on the ground plane. The system utilizes a Height Estimation Network (HENet), built on a Mix Transformer (MiT) backbone, to predict this height map from a single RGB image. This map serves as a stable 2.5D representation of the object's spatial structure.

2. Hard Shadow Renderer (HSR)

With the predicted Pixel Height map, the system employs a Hard Shadow Renderer (HSR). This stage uses classic projective geometry to calculate the exact coordinates where a "hard" shadow would fall based on user-defined parameters, such as the light source position and the horizon line. Because this stage is purely mathematical, it allows for real-time interactivity; users can move the light source or adjust the perspective, and the shadow updates instantaneously with geometric consistency.

3. Soft Shadow Generator (SSG)

To transform the mathematically perfect hard shadow into a realistic one, the framework uses a Soft Shadow Generator (SSG). This U-Net-based generator takes the hard shadow mask and a user-defined "softness" parameter as inputs. Using Adaptive Instance Normalization (AdaIN), the network learns to apply realistic blurring and fading effects that mimic the behavior of area light sources in the real world.

Data and Evaluation

The model was trained and validated using a combination of synthetic and real-world data:

  • Synthetic60K: A dataset of 60,000 renderings of 3D human models, providing ground-truth data for both Pixel Height and shadow behavior.
  • Real1500: A benchmark of 1,500 real-world images with sparse point annotations from artists to create interpolated height maps.
  • Generalization Test: The system was further tested on 20 unique 3D models not present in the training set to ensure robustness across different shapes.

Key Results and Insights

The decoupling of physics and neural synthesis yields several significant advantages:

  • Quantitative Performance: In comparisons against the previous state-of-the-art (SSN), the proposed method reduced the Mean Absolute Error (Abs) from 0.033 to 0.024. More importantly, it improved shape similarity (ZNCC) from 0.370 to 0.788, indicating a much higher degree of geometric accuracy.
  • Handling Long Shadows: Unlike GAN-based methods that often struggle with long-distance projections, the HSR ensures that shadows remain coherent even when the light source is at a low angle.
  • User Preference: A "two-alternative forced choice" (2AFC) study revealed that human participants preferred the shadows generated by this method 74% of the time over existing techniques, citing better integration with the background and more realistic perspective.

Conclusion and Future Work

By utilizing Pixel Height as an intermediate representation, this framework provides a highly controllable and realistic solution for shadow generation. While the current model is optimized for human subjects and assumes a flat ground plane, it represents a major step forward in making professional-grade compositing tools accessible to general users. Future research may expand this approach to more complex, non-planar environments and account for the "thickness" of objects to further refine shadow accuracy for complex 3D geometries.

Summary updated

BibTeX
@inproceedings{sheng2022controllable,
  author = {Yichen Sheng and Yifan Liu and Jianming Zhang and Wei Yin and A. Cengiz Öztireli and He Zhang and Zhe Lin and Eli Shechtman and Bedrich Benes},
  title = {{Controllable Shadow Generation Using Pixel Height Maps}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-20050-2\_15},
}
Figure