Last active
March 7, 2025 21:09
-
-
Save JoseMiguelPizarro/a3834fc3aa4bb5df0975443ad3c780ef to your computer and use it in GitHub Desktop.
Example of how to use the KeywordEnum shader attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/KeywordEnum" | |
{ | |
Properties | |
{ | |
[KeywordEnum(Red,Green,Blue)] _Color("Color",int) = 0 | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
HLSLPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
//Each keyword must start with the property name followed by _<Enum Value>. All in uppercase. | |
#pragma shader_feature _COLOR_RED _COLOR_GREEN _COLOR_BLUE | |
#include "UnityCG.cginc" | |
float4 vert(float4 positionOS : POSITION) : SV_POSITION | |
{ | |
return UnityObjectToClipPos(positionOS); | |
} | |
float4 frag() : SV_Target | |
{ | |
float4 color; | |
#ifdef _COLOR_RED | |
color = float4(1, 0, 0, 1); | |
#elif _COLOR_GREEN | |
color = float4(0, 1, 0, 1); | |
#elif _COLOR_BLUE | |
color = float4(0,0,1,1); | |
#endif | |
return color; | |
} | |
ENDHLSL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: make sure HLSL keywords are in UPPERCASE (aka _COLOR_RED and NOT _Color_Red or_Color_RED)
wasted a hour of my life