Skip to content

Instantly share code, notes, and snippets.

@sotanmochi
Created September 25, 2020 01:40
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 sotanmochi/74633f2c05e80a73818596f45149353b to your computer and use it in GitHub Desktop.
Save sotanmochi/74633f2c05e80a73818596f45149353b to your computer and use it in GitHub Desktop.
/**
* Copyright(c) Live2D Inc. All rights reserved.
*
* Use of this source code is governed by the Live2D Open Software license
* that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
*/
Shader "Live2D Cubism/UnlitReversible"
{
Properties
{
// Texture and model opacity settings.
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {}
[PerRendererData] cubism_ModelOpacity("Model Opacity", Float) = 1
// Modified by Soichiro Sugimoto
_BackFaceColor("Back Face Color", Color) = (0, 0, 0, 1)
// Blend settings.
_SrcColor("Source Color", Int) = 0
_DstColor("Destination Color", Int) = 0
_SrcAlpha("Source Alpha", Int) = 0
_DstAlpha("Destination Alpha", Int) = 0
// Mask settings.
[Toggle(CUBISM_MASK_ON)] cubism_MaskOn("Mask?", Int) = 0
[Toggle(CUBISM_INVERT_ON)] cubism_InvertOn("Inverted?", Int) = 0
[PerRendererData] cubism_MaskTexture("cubism_Internal", 2D) = "white" {}
[PerRendererData] cubism_MaskTile("cubism_Internal", Vector) = (0, 0, 0, 0)
[PerRendererData] cubism_MaskTransform("cubism_Internal", Vector) = (0, 0, 0, 0)
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Cull Off
Lighting Off
ZWrite Off
Blend [_SrcColor][_DstColor], [_SrcAlpha][_DstAlpha]
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile CUBISM_MASK_ON CUBISM_MASK_OFF CUBISM_INVERT_ON
#include "UnityCG.cginc"
// Modified by Soichiro Sugimoto
// #include "CubismCG.cginc"
#include "Assets/Live2D/Cubism/Rendering/Resources/Live2D/Cubism/Shaders/CubismCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
// Add Cubism specific vertex output data.
CUBISM_VERTEX_OUTPUT
};
sampler2D _MainTex;
fixed4 _BackFaceColor; // Modified by Soichiro Sugimoto
// Include Cubism specific shader variables.
CUBISM_SHADER_VARIABLES
v2f vert (appdata IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color;
// Initialize Cubism specific vertex output data.
CUBISM_INITIALIZE_VERTEX_OUTPUT(IN, OUT);
return OUT;
}
/**
* Modified by Soichiro Sugimoto
*/
fixed4 frag (v2f IN, fixed facing : VFACE) : SV_Target
{
fixed4 FRONT_COLOR = tex2D(_MainTex, IN.texcoord) * IN.color;
float alpha = (FRONT_COLOR.a > 0.5) ? 1.0 : 0.0;
fixed4 BACK_COLOR = _BackFaceColor * IN.color * alpha;
fixed4 OUT = (facing < 0) ? FRONT_COLOR : BACK_COLOR;
// Apply Cubism alpha to color.
CUBISM_APPLY_ALPHA(IN, OUT);
return OUT;
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment