Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created August 10, 2017 12:53
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 tsubaki/3b3be95a409821541b4edbb2f042c20c to your computer and use it in GitHub Desktop.
Save tsubaki/3b3be95a409821541b4edbb2f042c20c to your computer and use it in GitHub Desktop.
Position as UV1のテスト
Shader "Custom/UV1Sample" {
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_SubTex("SubTexture", 2D) = "white"{}
_Size("Size", Float) = 0.1
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_ColorMask ("Color Mask", Float) = 15
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Stencil
{
Ref [_Stencil]
Comp [_StencilComp]
Pass [_StencilOp]
ReadMask [_StencilReadMask]
WriteMask [_StencilWriteMask]
}
Cull Off
Lighting Off
ZWrite Off
ZTest [unity_GUIZTestMode]
Fog { Mode Off }
Blend One Zero
ColorMask [_ColorMask]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
half2 texcoord1 : TEXCOORD1; // new!
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 uv1 : TEXCOORD0;
half2 uv2 : TEXCOORD1; // new!
};
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.uv1 = IN.texcoord;
OUT.uv2 = IN.texcoord1; // new!
#ifdef UNITY_HALF_TEXEL_OFFSET
OUT.vertex.xy -= (_ScreenParams.zw-1.0);
#endif
OUT.color = IN.color;
return OUT;
}
sampler2D _MainTex;
sampler2D _SubTex;
float _Size;
fixed4 frag(v2f IN) : SV_Target
{
half4 color = tex2D(_MainTex, IN.uv1) * IN.color;
color.a = color.a * tex2D(_SubTex, IN.uv2 * _Size).a; // new!
clip (color.a - 0.01);
return color;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment