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 `%SetProp()` drawer function #29

Closed orels1 closed 11 months ago

orels1 commented 11 months ago

There is often a need to set some property based on the value of another property. A common example: adjusting blend settings based on the desired blending mode or setting stencil refs in a user-friendly way (like for outlines).

The signature should look like this

%SetProp((<shader condition>), <prop name>, <value if true>, <value if false>);

Example:

// properties

[Toggle(OUTLINE_ENABLED)]_OutlineEnabled("Enable Outline", Int) = 0
UI_SetStencilOp("Stencil Op Settier %SetProp((OUTLINE_ENABLED), _StencilOp, 2, 0)", Int) = 0
[HideInInspector]_StencilOp("Stencil Op", Float) = 0

// below in the pass

Stencil
{
  Ref 69
  Comp Always
  Pass [_StencilOp]
}

// below in the CGPROGRAM

float _StencilOp;

This will set the Stencil Pass op (via the _StencilOp property) to 2 (Replace) if the OUTLINE_ENABLED keyword is set, or to 0 (Keep) if the keyword is not set