Skip to content

Instantly share code, notes, and snippets.

@johans2
Created August 17, 2018 11:42
Show Gist options
  • Save johans2/c80e2b4f80300aab1e7d552d10e164e3 to your computer and use it in GitHub Desktop.
Save johans2/c80e2b4f80300aab1e7d552d10e164e3 to your computer and use it in GitHub Desktop.
Subsurface scattering shader
Shader "Custom/SSS" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NormalMap ("MormalMap", 2D) = "white" {}
_Thickness ("Thickness", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_Distortion("Distortion", Range(0,1)) = 0.0
_Power("Power", Range(0,10)) = 0.0
_Scale("Scale", Range(0,10)) = 0.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf StandardTranslucent fullforwardshadows
#pragma target 3.0
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _Thickness;
struct Input {
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
float _Distortion;
float _Power;
float _Scale;
float thickness;
#include "UnityPBSLighting.cginc"
inline fixed4 LightingStandardTranslucent(SurfaceOutputStandard s, fixed3 viewDir, UnityGI gi)
{
// Original colour
fixed4 pbr = LightingStandard(s, viewDir, gi);
// --- Translucency ---
float3 L = gi.light.dir;
float3 V = viewDir;
float3 N = s.Normal;
float3 H = normalize(L + N * _Distortion);
float VdotH = pow(saturate(dot(V, -H)), _Power) * _Scale;
float3 I = (VdotH + unity_AmbientSky) * thickness;
// Final add
pbr.rgb = pbr.rgb + gi.light.color * I;
return pbr;
}
void LightingStandardTranslucent_GI(SurfaceOutputStandard s, UnityGIInput data, inout UnityGI gi)
{
LightingStandard_GI(s, data, gi);
}
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
//o.Normal = tex2D (_NormalMap, IN.uv_MainTex);
thickness = tex2D (_Thickness, IN.uv_MainTex).r;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment