Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A PBR two-sided cloth shader that works correctly with Unity's lighting.

Extended from this article

two-sided custom shader cover image

/// Created by @cortvi
Shader "Custom/Two sided"
// You can learn everything about properties here:
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Cutoff ("Cutout threshold", Range(0.0,1.0)) = 0.1
[NoScaleOffset] _SmoothnessMap ("Roughness map (A)", 2D) = "black" {}
_Smoothness ("Flat roughness", Range(0.0, 1.0)) = 0.0
[NoScaleOffset][Normal] _BumpMap ("Normal map (RGB)", 2D) = "bump" {}
_BumpScale ("Normal scale", Float) = 1.0
Tags { "Queue"="AlphaTest" "RenderType"="TransparentCutout" }
// Whatever you write inside here
// will be included in every pass
struct Input
{ float2 uv_MainTex; };
fixed4 _Color;
sampler2D _MainTex;
sampler2D _BumpMap;
float _BumpScale;
sampler2D _SmoothnessMap;
float _Smoothness;
void surf (Input IN, inout SurfaceOutputStandard o)
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
fixed3 normal = UnpackScaleNormal (tex2D(_BumpMap, IN.uv_MainTex), _BumpScale).xyz;
fixed smooth = tex2D (_SmoothnessMap, IN.uv_MainTex).a;
// Feed surface output
o.Albedo = c.rgb;
o.Normal = normal;
o.Metallic = 0.0;
o.Smoothness = lerp(smooth, 1.0, _Smoothness);
o.Alpha = c.a;
Cull Front
#pragma surface surf Standard fullforwardshadows vertex:vert alphatest:_Cutoff
#pragma target 3.0
void vert (inout appdata_full v)
v.normal = -v.normal;
Cull Back
#pragma surface surf Standard fullforwardshadows alphatest:_Cutoff
#pragma target 3.0
Fallback "Standard"
Copy link

JonRurka commented Apr 23, 2020

I can not tell you how much I would have appreciated a version with traditional frag/vert shaders. I HAVE to use them for what i'm doing (compute buffers don't work well with surf shaders), even if you cut out the lighting bit and just left the part that matters for double sided rendering.

Copy link

DoguD commented Feb 9, 2021

It works great! Thank you very much, do you have a donation link?

Copy link

foopis23 commented Apr 2, 2021

Using Unity 2020.2.6f1 and It seems to have lighting errors. Could just be something specific about my setup though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment