Basic shader setup

I always stumble when I try to remember everything that’s needed for basic shader initialization, especially when I’m using mesh instances, so I made this playground as a starting point. (edit: updated to Evgeni’s cleaner version)

Just look at the “uncomment this” parts of the code if you want to use your shader with instances.

Hope someone finds it helpful.


Nice of you!

Note that you don’t need to comment the includes and you don’t need to pass #define INSTANCES: the engine will be smart enough to not add the shader code if the mesh is not using instances, and it will automatically add the define if the mesh is using them.

So you can simply do:

You can comment the lines 69 and 70 and notice it still works.


That’s super helpful, thank you.

Any performance cost to having the instance stuff in the shader even when not using instances? (But really instances are almost always the way to go, anyway!)

No performance cost, if your mesh has no instances, the shader code for instances won’t be injected.

This is very helpful thanks!!

Plenty thanks