My procedural game has blocks that can be selected. When selected, I'd like them to to fade a bit; I can achieve such an effect in Shader Graph by applying a Blend → Lighten operation to the block shader (blending with white).

However I'm a bit stuck on how I would make this effect happen dynamically when the block is selected. All blocks within a chunk are part of the same mesh; I'm using a separate submesh for each different block type. So although I've considered using a property to conditionally apply the blend operation, I believe that would affect all the other blocks using that shader?

I've considered making a selected variant of each shader and swapping them upon object selection, but there are dozens of block types so I don't know if that's the best method.

What is the recommended approach here? Is there a way I can simply "apply" some shader operation on top of whatever the existing shader is?

  • \$\begingroup\$ "Is there a way I can simply "apply" some shader operation on top of whatever the existing shader is?" No. Have you considered simply rendering a separate mesh over your selected block to modify its appearance instead? You can modify the colour value of pixels already written to the frame buffer, even if you can't intercept them in the middle of a different shader's execution. \$\endgroup\$ – DMGregory Mar 15 at 17:38
  • \$\begingroup\$ @DMGregory - Yes, that was a last resort approach I thought of but didn't list as it seemed like a bit of a hack. Thanks for confirming it's valid. \$\endgroup\$ – Matt Mar 15 at 17:42
  • \$\begingroup\$ A selection cursor/overlay mesh is pretty standard. I'd expect it will be less grief than hacking together shader variants for every case you need. \$\endgroup\$ – DMGregory Mar 15 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.