Skip to content

Instantly share code, notes, and snippets.

@tklee1975
Last active February 29, 2020 18:01
Show Gist options
  • Select an option

  • Save tklee1975/4c3cb3c1c65adb632215e463f62066e5 to your computer and use it in GitHub Desktop.

Select an option

Save tklee1975/4c3cb3c1c65adb632215e463f62066e5 to your computer and use it in GitHub Desktop.
Skin Shader
Shader "Kencoder/skin_shader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB), Thickness (A)", 2D) = "white" {}
//_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Metallic ("Metal (R), Smoothness (A)", 2D) = "white" {}
_BumpMap ("Normal (Normal)", 2D) = "bump" {}
_Scale ("Thickness Scale", Range(0,1)) = 0.0
_Intensity ("Intensity", Float) = 1.0
_SSS_Color ("Subsurface Color", Color) = (1.0, 1.0, 1.0, 1.0)
_Diffusion ("Subsurface Diffusion", Float) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf SkinSSS fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _BumpMap;
sampler2D _MainTex;
sampler2D _Metallic;
fixed4 _SSS_Color;
float _Diffusion;
float _Intensity;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
//float3 worldPos; //added
//float3 worldNormal;
//INTERNAL_DATA
};
struct SurfaceOutputSkinSSS {
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
};
fixed4 _Color;
half _Scale;
inline fixed4 LightingSkinSSS (SurfaceOutputSkinSSS s, fixed3 lightDir,
fixed3 viewDir, fixed atten) {
half3 diffLightDir = lightDir + s.Normal * _Diffusion;
float transDot = max(0, dot(viewDir, -diffLightDir)) * _Scale;
//fixed3 transLight = transDot * _SSS_Color.rgb * atten;
fixed3 transLight = transDot * s.Alpha * _SSS_Color.rgb * atten;
fixed3 transAlbedo = transLight * s.Albedo * _LightColor0.rgb;
half3 h = normalize (lightDir + viewDir);
fixed diffuse = max(0, dot (s.Normal, lightDir));
float nh = max(0, dot(s.Normal, h));
float specular = pow (nh, s.Specular * 128.0) * s.Gloss;
fixed3 diffuseAlbedo = (s.Albedo * (_LightColor0.rgb * diffuse) +
(_LightColor0.rgb * specular));
fixed4 c;
c.rgb = (diffuseAlbedo + transAlbedo) * _Intensity;
c.a = _LightColor0.a * atten;
//c.rgb = diffuseAlbedo;
//c.a = _LightColor0.a;
return c;
}
void surf (Input IN, inout SurfaceOutputSkinSSS o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 m = tex2D (_Metallic, IN.uv_MainTex);
// float3 n = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
//float thickness = length (fwidth (WorldNormalVector (IN, n)))
// / length (fwidth (IN.worldPos)) * _Scale;
o.Albedo = c.rgb * _Color.rgb;
//o.Metallic = m.r;
//o.Smoothness = m.a;
o.Gloss = m.a * m.r;
// o.Albedo = _Color.rgb * thickness;
// Albedo comes from a texture tinted by color
//fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
//o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Alpha = _Color.a;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment