Home

Awesome

enhanceShaderLighting - more realism in three.js

<img src="https://raw.githubusercontent.com/0beqz/enhance-shader-lighting/main/example/public/screenshots/gym.webp"> <img src="https://raw.githubusercontent.com/0beqz/enhance-shader-lighting/main/example/public/screenshots/desert.webp"> <br/>

Idea

Give the user a lot of options to tweak lighting so that a certain combination of settings will give a decent looking result.

Usage

Install enhance-shader-lighting first:

npm i enhance-shader-lighting

then use it in your project like so:

import { enhanceShaderLighting } from "enhance-shader-lighting"

material.onBeforeCompile = shader => enhanceShaderLighting(shader, options)

NOTE: three.js version 0.151.0 (released: 03.30.2023) isn't supported yet, it will be supported soon

Parameters of enhanceShaderLighting(shader, ?options)

shader: material's shader, acquired through Material.onBeforeCompile

options: An optional argument that can have the following values:

{
    aoColor: THREE.Color              = new THREE.Color(0x000000),
    hemisphereColor: THREE.Color      = new THREE.Color(0xffffff),
    irradianceColor: THREE.Color      = new THREE.Color(0xffffff),
    radianceColor: THREE.Color        = new THREE.Color(0xffffff),

    aoPower: Number                   = 1,
    aoSmoothing: Number               = 0,
    aoMapGamma: Number                = 1,
    lightMapGamma: Number             = 1,
    lightMapSaturation: Number        = 1,
    envPower: Number                  = 1,
    roughnessPower: Number            = 1,
    sunIntensity: Number              = 0,
    mapContrast: Number               = 1,
    lightMapContrast: Number          = 1,
    smoothingPower: Number            = 0.25,
    irradianceIntensity: Number       = Math.PI,
    radianceIntensity: Number         = 1,

    hardcodeValues: Boolean           = false
}

Note: Check out the demos to see what each parameter does.

Motivation

Lightmapping has always been an interesting topic in three.js. While it works well with non-PBR materials (like simple MeshBasicMaterials), it needs a lot of tweaking when you want to use it with PBR materials (e.g. MeshStandardMaterial). The enhanceShaderLighting implementation aims to make your PBR material look more realistic by:

So the aim is to get as close to the rendered reference scene as possible through giving many options to tweak all sorts of lighting in three.js.

Note

This implementation is purely arbritrary and doesn't follow any articles what so ever. Everything was implemented based on how well the scene was perceived with it and how the scene looks compared to its rendered Blender reference.

Sponsoring

If the project is useful for you and you'd like to sponsor my work:

GitHub Sponsors

If you'd like, you could also buy me a coffee:

"Buy Me A Coffee"

Credits