orels1 / orels-Unity-Shaders

A collection of practical Unity shaders for your next project
https://shaders.orels.sh
Other
168 stars 13 forks source link

Add support for Template Features #34

Closed orels1 closed 11 months ago

orels1 commented 11 months ago

Sometimes there is a need to include a whole Template section per-shader conditionally.

E.g. a special pass for a shader that needs it.

While it can be done with PrePasses and PostPasses that is very limited as it doesn't utilize the actual template logic (although maybe it should!

A solution to this could be created in a form of Template Features.

E.g. you add a block to the template that looks something like this

%TemplateFeature("MyFeature")
{
  // some feature code
}

%TemplateFeature("MyOtherFeature")
{
  // some feature code
}

And then in the shader code you simply add

TemplateFeatures("MyFeature", "MyOtherFeature")

And that automatically includes those scoped blocks in the main template before it gets processed.

An example of this used in practice is a conditional Depth PrePass for shaders that need it