Skip to content

Instantly share code, notes, and snippets.

@keijiro
Last active March 24, 2023 00:43
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save keijiro/22cba09c369e27734011 to your computer and use it in GitHub Desktop.
Save keijiro/22cba09c369e27734011 to your computer and use it in GitHub Desktop.
Shows how to use the Toggle material property drawer in a shader. See the reference manual for further details: http://docs.unity3d.com/ScriptReference/MaterialPropertyDrawer.html
Shader "ToggleTest"
{
Properties
{
[Toggle(FILL_WITH_RED)]
_FillWithRed ("Fill With Red", Float) = 0
}
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma shader_feature FILL_WITH_RED
#include "UnityCG.cginc"
float4 vert(appdata_base v) : POSITION
{
return mul(UNITY_MATRIX_MVP, v.vertex);
}
half4 frag(float4 position : POSITION) : SV_Target
{
#ifdef FILL_WITH_RED
return float4(1, 0, 0, 1);
#else
return (float4)1;
#endif
}
ENDCG
}
}
}
@smkplus
Copy link

smkplus commented Dec 2, 2017

Hi i collected useful material property drawers here:
https://gist.github.com/smkplus/2a5899bf415e2b6bf6a59726bb1ae2ec

16999105_467532653370479_4085466863356780898_n

@FNGgames
Copy link

Thanks for this, solved my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment