No BackFace Culling Shader for Unity

Unity doesn’t have a way within the program to turn off BackFace culling. You can do it but it requires code. There is no little button to check. Like most others, I didn’t realize this until I already had spent many long hours optimizing the model with the assumption that I could just change the setting as in other 3d applications.

In my case it was the hair I wanted to show backfaces on. And I really didn’t want to double the amount of faces because I had to go a little high to begin with in order to get the style I wanted. For this character, I wanted a fiery redhead.

Anyway, as a matter of principle I needed to solve the problem. But have been putting it off so I could complete the level. The level is done, and I am on to the character. I finally figured out how to do it and the code is below, just in case you are stuck on the same problem.

Github Download Link:

Here is the Before and after photo.



As a Brunette
















You can see that half of my hairstyle disappears with the standard shaders

















HERE IS MY CODE: JUST in case you are having the same problem


Shader "Hair-Shader-No-BackFace-Culling" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
_BumpMap ("Normalmap", 2D) = "bump" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5

SubShader {
Cull Off
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 400

#pragma surface surf BlinnPhong alphatest:_Cutoff
#pragma exclude_renderers flash

sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
half _Shininess;

struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;

void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = tex.rgb * _Color.rgb;
o.Gloss = tex.a;
o.Alpha = tex.a * _Color.a;
o.Specular = _Shininess;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));

FallBack "Transparent/Cutout/VertexLit"

Code Screenshot (In Full Technicolor)


Cow Game In C++

This was the animation from the last project I was working on.  I got the graphics from reiner’s tilesets he does really nice work, and offers it free of charge for game developers.  I will probably be using some of the stuff I found on his site in upcoming projects.  I really like the idea of a cow as a main character for a video game.  That is probably not what it was intended for in the set, but it works for me.