I’d like to compile two versions of a fragment shader (built via chunks), based on an #ifdef . Something similar to Unity’s Shader.SetKeyword() behaviour.
Whether or not this is defined is based on the user enabling a bool in the inspector.
My initial attempts result in undefined. I imagine it’s because I’m doing it in initialize, but I’m pretty new to js/PC, so it may be something else :
I’m basically trying to reproduce what I see here, but I’m not sure where to stick it!: engine/standard.js at f64bb6d28eeeac2598bc63ad6dae0b372c99e6ad · playcanvas/engine · GitHub
I’m wondering a couple of things:
- Are shader macros the right solution for this in Playcanvas?
- If so: Is there a way to make sure this hits the preprocessor?
- If not: What’s the recommended approach? Any examples would be much appreciated.
My backup plan is to swap entire chunks in initialize, based on the bool’s condition.
Thanks for your time