Skip to content

Instantly share code, notes, and snippets.

@baobao
Last active December 7, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/cc73950d7cf710df352024bbb4c5e477 to your computer and use it in GitHub Desktop.
Save baobao/cc73950d7cf710df352024bbb4c5e477 to your computer and use it in GitHub Desktop.
// シェーダのマクロショートコード
Shader "MacroTest"
{
Properties
{
}
SubShader
{
CGINCLUDE
#include "UnityCG.cginc"
#ifdef SHIBUYA24
#define TEST_MACRO(abc) abc.x = 0;
#else
#define TEST_MACRO(abc) abc.z = 0;
#endif
fixed4 frag (v2f_img i) : SV_Target
{
fixed4 col = fixed4(1,1,1,1);
// マクロ適用
TEST_MACRO(col);
return col;
}
ENDCG
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
// 下記のように書いてしまうとSHIBUYA24が存在しないShaderがコンパイルされない
// #pragma multi_compile SHIBUYA24
#pragma multi_compile _ SHIBUYA24
ENDCG
}
}
}
using UnityEngine;
public class MacroTest : MonoBehaviour
{
public Material mat;
bool m_enableShibuya24;
void OnGUI ()
{
if (GUILayout.Button("Change"))
{
if(m_enableShibuya24)
mat.DisableKeyword("SHIBUYA24");
else
mat.EnableKeyword("SHIBUYA24");
m_enableShibuya24 = !m_enableShibuya24;
}
GUILayout.Label("m_enableMacro : " + m_enableShibuya24);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment