mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.71k stars 35.3k forks source link

ShaderMaterial: send lights to shader without shadow-related uniforms #19836

Closed DavidPeicho closed 4 years ago

DavidPeicho commented 4 years ago
Description of the problem

When working on a custom ShaderMaterial, it happens that I need to have lights but no shadow-related uniforms. It's actually not possible because of this part of the code.

It's actually common (for me at least) to use lights without shadow maps / shadow related uniforms. As an example, I work on a medical framework that include pathtracing and I often mix rasterization / pathtracing together and both rasterization / pathtracing can just use the light path code as-is.

This was perfectly working before the addition of things like directionalLightShadows, because now if the shader doesn't use those uniforms, the uniform setter will crash here. But in general, I guess separting shadow related stuff could be great?

Did I miss something here, or could we consider a change to make using lights in custom shader easier?

Thanks!

Temporary Fix

In the meantime, an easy fix is to simply add the appropriate chunk in shaders and expose the shadow-related uniforms, even if unused.

OS
Hardware Requirements (graphics card, VR Device, ...)

No requirement.

DavidPeicho commented 4 years ago

My bad. Some shaders chunks changed a bit and I was using an old mix between the previous DirectionalLight struct and the new one.