StrandedKitty / three-csm

☀️ Cascaded shadow maps (CSMs) implementation for Three.js
MIT License
296 stars 21 forks source link

setupMaterial() overrides a material's onBeforeCompile function if it already exists #26

Closed itsdouges closed 1 year ago

itsdouges commented 1 year ago

Heya! Currently setup material will overrides the function if it already exists which isn't ideal. The solution would be to compose it, something like:

if (material.onBeforeCompile) {
  const previousOnBeforeCompile = material.onBeforeCompile;

  const newOnBeforeCompile = (shader, renderer) => {
    // csm logic
    previousOnBeforeCompile(shader, renderer);
  };

  material.onBeforeCompile = newOnBeforeCompile;
}

For context this is set because I'm using https://github.com/FarazzShaikh/THREE-CustomShaderMaterial/ which sets it and allows you to re-use standard three materials with custom shaders.

StrandedKitty commented 1 year ago

Thank you. Fixed in v3.1.1.