Skip to content

Instantly share code, notes, and snippets.

@atori708
Created November 12, 2017 08:03
Show Gist options
  • Save atori708/e23cb10c764d74c8ed790ca7f4dd8068 to your computer and use it in GitHub Desktop.
Save atori708/e23cb10c764d74c8ed790ca7f4dd8068 to your computer and use it in GitHub Desktop.
表面と裏面で描画を変えるUnityのシェーダコード 2パスで描画版とVFACEセマンティクス使った板
Shader "Unlit/TwoPasses"
{
Properties
{
_FrontColor("Front Color", Color) = (1,1,1,1)
_BackColor("Back Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
fixed4 _FrontColor;
fixed4 _BackColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = _FrontColor;
return col;
}
ENDCG
}
Pass
{
Cull back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
fixed4 _FrontColor;
fixed4 _BackColor;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = _BackColor;
return col;
}
ENDCG
}
}
}
Shader "Unlit/NewUnlitShader"
{
Properties
{
_FrontColor("Front Color", Color) = (1,1,1,1)
_BackColor("Back Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Cull off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
fixed4 _FrontColor;
fixed4 _BackColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag (v2f i, fixed facing : VFACE) : SV_Target
{
fixed4 col = facing > 0 ? _FrontColor : _BackColor;
return col;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment