Is there any good solution to use light probes in a custom shader (considering making a npr rendering demo) just like SampleSH
in Unity?
AFAIK the current implementation of light probes in three.js has the following features:
- It does not have a local position, only global / infinite (same as AmbientLight or HemisphereLight.
- it is mainly intended for storing illumination (irradiance term), so for example it does not generate shadows
- only one can be used per scene, if you add more only the last one is considered.
On the other hand, if you only need to use low frequency lighting, as the ones you could store in SH coefficients, you could use another data structure that does not have these limitations.
I want to simulate the diffuse reflection of ambient light. The ambient light here refers to the light emitted by the skybox.
Because I want to make cartoon renderings for NPR, I don’t need such strong details. It would be better if there is an implementation similar to Unity that can enhance or weaken the influence of higher-order terms of spherical harmonics.
Before SH coefficients existed, people used blured versions of skyboxes to acomplish this. I gues it is still doable.
All right, but please consider that both MeshStandardMaterial and MeshPhysicalMaterial currently account for the irradiance implied by the environment map, so if you use an environment map, and at the same time store irradiance in a light probe, you will be double-counting the irradiance term (this was discussed before in this forum)
I guess that, if you don’t put lightprobes to actually work (i.e. just keep them off) and only use them as a data structure for storing light passing through space, you could use LightProbe.sh property to retrieve those stored SH coefficients and later on use them in a dedicated shader
Thanks for your reply. It seems that I still need to read more about the use and calculation of light probes in meshphysical.glsl so that I can use it in my custom shader.
Sure, it gets complex very early.
For debugging / learning purposes, if you are struggling to get your head around all the required includes, you can see this project for a ‘foldable’ view of all of them being used inside the shader, or even better this other project with the resulting fragment already compiled.