March 18, 2025

Standard Effect modularization

The latest Evergine release introduces a significant advancement in shader architecture through the new Library Effect asset. Designed specifically to enhance code readability and facilitate extensive reuse across multiple projects, this novel asset addresses the common challenges encountered during shader development, such as redundant patterns and utility functions.

Within Evergine, the primary built-in shader is known as the Standard Effect. By default, this versatile shader is utilized whenever a 3D model is loaded into an Evergine scene. Engineered to accommodate numerous configurations, the Standard Effect functions as an “Uber Shader,” offering over 18 million possible combinations to create diverse material effects. Historically, this shader was structured monolithically, encompassing over two thousand lines of code, which introduced considerable complexity in maintenance and customization.

To overcome these challenges, the Evergine team undertook a substantial restructuring initiative, segmenting the Standard Effect into modular libraries. This modularization significantly enhances maintainability, clarity, and ease of reuse. The newly modularized Standard Effect comprises the following distinct libraries:

  • Structures: Defines essential shader structures utilized throughout StandardEffect (e.g., LightProperties).
  • Common: Houses common engine directives and frequently used utility methods (e.g., gamma-linear conversions).
  • Material: Includes essential methods for physically-based rendering (PBR) material generation.
  • Lighting: Contains comprehensive methods for calculating various lighting models (Directional, Point, Spot, and Area lights).
  • Shadow: Provides dedicated methods for calculating shadow contributions from different light sources.

The updated Standard Effect now references these individual libraries directly, significantly simplifying shader code and promoting efficient development practices.

A critical aspect of this modularization is its transparency from the user’s perspective. Developers can continue to seamlessly employ the Standard Effect in their existing projects without observing any functional changes. However, the newly organized library structure enables developers to effortlessly create custom shaders that leverage these standardized libraries, ensuring easy integration with Evergine’s sophisticated lighting and shadow systems.

Moreover, to further empower developers, the Evergine team is actively developing an additional specialized lighting model library. This supplementary library includes widely recognized lighting algorithms, designed explicitly to streamline custom shader integration into complex lighting environments. Given that the original lighting library within the Standard Effect requires handling numerous parameters, this dedicated library provides simpler integration paths and clearer implementation strategies.

Currently, the available lighting models provided by this supplementary library are:

  • Phong
  • Blinn-Phong
  • Cook-Torrance
  • Oren-Nayar

All these enhanced modular libraries, including the newly developed lighting model library, are conveniently included within the core Evergine.Core package, readily available in every standard Evergine project.

Creating Custom Shaders with Lighting and Shadow Support

With the new modular shader libraries, developing custom shaders integrated with advanced lighting and shadows becomes significantly simpler. To create a custom shader incorporating these features, follow these steps:

Include Essential Libraries

Integrate the Lighting Models and Shadow libraries into your shader.

Add Shadow and Lighting Resources

Add necessary resources to your resource layout:

Implement ShadowMap Pass

Include a dedicated pass to render geometry into the shadow map texture:

Define Surface and Pixel Structures

Populate Surface and Pixel structures using provided shadow library methods:

Select and Apply a Lighting Model

Choose from available lighting models to calculate the final color:

Calculate Shadow Terms

Apply shadow calculations using the Shadow library:

Below is an example demonstrating the final result:

You can review the complete custom shader implementation [here].

 

The Evergine Team greatly values your feedback regarding the new modular shader system and eagerly anticipates the creative and innovative shaders you will develop with these enhanced capabilities.

Jorge Canton
Author
Jorge Cantón
Plain Concepts Research

Wait! Don't leave yet.

Sign up for our monthly newsletter to be updated on all the latest news, case studies, and more.

We don't send spam and you can unsubscribe at any time.