pmndrs / lamina

🍰 An extensible, layer based shader material for ThreeJS
MIT License
1.01k stars 41 forks source link

Possible to copy the implement of Fragment Layers to extend Three.js standard materials? #18

Closed bufffun closed 2 years ago

bufffun commented 2 years ago

Hello, I just wonder can I just copy this repo's Fragment Layers shader code to extend the three.js standard materials by your previous repo THREE-CustomShaderMaterial ?

For example, copy the glsl from Fresnel shader code , then use CustomShaderMaterial

const material = new CustomShaderMaterial({
    THREE.MeshPhysicalMaterial    // baseMaterial
    /* glsl */ ` ... `,           // Fresnel shader code from Fresnel.ts
    {
      intensity: 1           // options
      color: 0xff00ff
    }
  })
FarazzShaikh commented 2 years ago

This lib already uses CustomShaderMaterial under the hood. Using the lighting option you effectively can specify the base materials.

as you can see LayerMaterial is built on top of CSM https://github.com/pmndrs/lamina/blob/696ccc1dd0fa53ae9bd90086b1da69233f254af8/src/vanilla.ts#L36

If you want to use CSM but not lamina, then yes you can grab the underlying shader code and run it within CSM but you’ll have to correctly port it. The convinces of lamina’s Abstract class will not apply when using CSM.