Last active
December 19, 2016 02:36
-
-
Save EsProgram/8830dfd6a074e43e4d1a to your computer and use it in GitHub Desktop.
UnityのShader Variantについて調べてみた ref: http://qiita.com/Es_Program/items/79edf9f8fca786b365aa
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
#pragma multi_compile _ Lighting_ON Lighting_OFF |
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
#ifdef Lighting_ON | |
//ライティングONの時の処理 | |
#elif Lighting_OFF | |
//ライティングOFFの時の処理 | |
#endif |
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/Test1" | |
{ | |
SubShader | |
{ | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert_img | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#pragma multi_compile RED GREEN BLUE | |
#pragma debug | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed4 col = float4(0, 0, 0, 1); | |
#ifdef RED | |
col = float4(1, 0, 0, 1); | |
#elif GREEN | |
col = float4(0, 1, 0, 1); | |
#elif BLUE | |
col = float4(0, 0, 1, 1); | |
#endif | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
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
#pragma multi_compile RED GREEN BLUE |
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
#ifdef RED | |
col = float4(1, 0, 0, 1); | |
#elif GREEN | |
col = float4(0, 1, 0, 1); | |
#elif BLUE | |
col = float4(0, 0, 1, 1); | |
#endif |
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
// Compiled shader for custom platforms, uncompressed size: 6.4KB | |
Shader "Unlit/Test1" { | |
SubShader { | |
// Stats for Vertex shader: | |
// d3d11 : 4 math | |
Pass { | |
GpuProgramID 59568 | |
Program "vp" { | |
SubProgram "d3d11 " { | |
// Stats: 4 math | |
Keywords { "RED" } | |
Bind "vertex" Vertex | |
Bind "texcoord" TexCoord0 | |
ConstBuffer "UnityPerDraw" 352 | |
Matrix 0 [glstate_matrix_mvp] | |
BindCB "UnityPerDraw" 0 | |
" | |
~省略~ | |
" | |
} | |
SubProgram "d3d11 " { | |
// Stats: 4 math | |
Keywords { "GREEN" } | |
Bind "vertex" Vertex | |
Bind "texcoord" TexCoord0 | |
ConstBuffer "UnityPerDraw" 352 | |
Matrix 0 [glstate_matrix_mvp] | |
BindCB "UnityPerDraw" 0 | |
" | |
~省略~ | |
" | |
} | |
SubProgram "d3d11 " { | |
// Stats: 4 math | |
Keywords { "BLUE" } | |
Bind "vertex" Vertex | |
Bind "texcoord" TexCoord0 | |
ConstBuffer "UnityPerDraw" 352 | |
Matrix 0 [glstate_matrix_mvp] | |
BindCB "UnityPerDraw" 0 | |
" | |
~省略~ | |
" | |
} | |
} | |
Program "fp" { | |
SubProgram "d3d11 " { | |
Keywords { "RED" } | |
" | |
~省略~ | |
" | |
} | |
SubProgram "d3d11 " { | |
Keywords { "GREEN" } | |
" | |
~省略~ | |
" | |
} | |
SubProgram "d3d11 " { | |
Keywords { "BLUE" } | |
" | |
~省略~ | |
" | |
} | |
} | |
} | |
} | |
} |
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
using System.Collections; | |
using UnityEngine; | |
public class NewBehaviourScript : MonoBehaviour | |
{ | |
public void OnGUI() | |
{ | |
KeywordButtonGUI("RED"); | |
KeywordButtonGUI("GREEN"); | |
KeywordButtonGUI("BLUE"); | |
} | |
private void KeywordButtonGUI(string keyword) | |
{ | |
if(GUILayout.Button(keyword + " : ON")) | |
Shader.EnableKeyword(keyword); | |
if(GUILayout.Button(keyword + " : OFF")) | |
Shader.DisableKeyword(keyword); | |
GUILayout.Label(keyword + " Enabled : " + Shader.IsKeywordEnabled(keyword).ToString()); | |
} | |
} |
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
#pragma shader_feature FANCY_STUFF |
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
#pragma multi_compile A B C | |
#pragma multi_compile D E |
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/Test1" | |
{ | |
Properties{ | |
[KeywordEnum(RED,GREEN,BLUE)] | |
_COLOR("COLOR KEYWORD", Float) = 0 | |
} | |
SubShader | |
{ | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert_img | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#pragma multi_compile _COLOR_RED _COLOR_GREEN _COLOR_BLUE | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
fixed4 col = float4(0, 0, 0, 1); | |
#ifdef _COLOR_RED | |
col = float4(1, 0, 0, 1); | |
#elif _COLOR_GREEN | |
col = float4(0, 1, 0, 1); | |
#elif _COLOR_BLUE | |
col = float4(0, 0, 1, 1); | |
#endif | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment