luruke / magicshader

🔮 Tiny helper for three.js to debug and write shaders
239 stars 14 forks source link

Apply to all threejs shaders? #1

Open luruke opened 5 years ago

luruke commented 5 years ago

Just an idea, we could plug and use the magic comments everywhere on three.js without even using the MagicShader class...

akella commented 5 years ago

i think my issue belongs here: i've been using usual ShaderMaterial, and just noticed it only works for RawShaderMaterial right now. It actually works perfectly if u just replace this dep in your code. But i guess there should be some more clever way for that. And thank you again for implementing this idea! =)

luruke commented 5 years ago

Yeah, a solution could be:

import MagicShader from 'magicshader';

const material = new MagicShader(Material)({
  fragmentShader:'...'
});

where Material can be anything that inherits from THREE.Material. But I guess it would be just useful for RawShaderMaterial and ShaderMaterial...

Or a syntax like:

import { MagicShader, RawMagicShader} from 'magicshader';

where MagicShader uses ShaderMaterial and RawMagicShader uses RawShaderMaterial