Double sided Shader with VFACE flipping issues

Im attempting to make a two sided PBR shader.

Ive got both sides showing using the VFACE flipping teqniue described here (Standard Shader (modified to be double sided) is very shiny on the underside - Unity Engine - Unity Discussions)

However, the issue i’m having is that the albedo of the shader is now only appearing on the underside. It doesnt matter if i just use a colour tint or apply texture, its not visible from the top.


From above


Same plane from below.

Any help would be greatly appreciated.

My shader code:

Shader "Custom/test" {
    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _NormalMap ("bump",2D) = "bump"{}
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200
        Cull Off
      
        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
                fixed facing : VFACE;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;
        sampler2D _NormalMap;  

        void surf (Input IN, inout SurfaceOutputStandard o) {
            // 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.Metallic = _Metallic;
            o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));

            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
          
          
            if (IN.facing < 0.5)
                o.Normal *= -1.0;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

Without the line

   if (IN.facing < 0.5)
                o.Normal *= -1.0;

The opposite occurs (Texture/tint only shows on the top side)

If you set the metallic & smoothness values to zero, what do you see?

Setting metalic to zero does allow some of the colour to show through, but its far less intense.

Top side of plane with red tint applied

Bottom side:

The metallic has the biggest effect, turning down the smoothness isnt really an option though as i’m wanting this for a water shader so need the reflections.

For reference this is it with both smoothness and metalic at zero:

Interestingly getting rid of the VFACE flip logic doesn’t seem change anything except cause the intenser side to now be the top of the mesh instead of bottom.

It’s acting like VFACE isn’t working at all. Are you on OSX, or is the editor running DX9? It should work fine for both of these, but there might be an issue with OSX & Metal?

No windows 10 on DX11 :confused:

If you do

o.Albedo = 0;
o.Emission = IN.facing;

what do you get? For me this makes the top of the mesh white and the bottom black. If this isn’t what you get I have no idea.

No that just gives me black on both sides :/.

Very strange, i assume that means the shader thinks both sides are the bottom for some reason

Ah very interesting, i’ve been using unity 5 but just tried it in the latest version of unity and its working as it should. Kind of annoying as id wanted to keep support for it in my asset but there you go.

Mind you my refraction code for my shader is now broken in the newest editor lol but at least VFACE is working haha.

Well i say broken, its just super weak for some reason meaning ive had to up the distortion by a factor of 10

Update:

Fixed my refraction issues.

Thanks for your help, if it hadnt been your suggestion of the black and white plane i would have probably just assumed the problem was me being an idiot and never tried a different editor version.

Now i have the fun job of trying all the different editor versions since 5.0 to see what the minimum i can provide support is. Lucky me lol

I used VFACE in multiple revisions of 5.3, 5.4, and 5.6 with out issue.

Ah right ok well thats a good starting point for me at least.

Could well just be an issue on my end with my instal of 5.0 tbf

Ok. So for anyone coming across this same issue in the future, turns out VFACE input for surface shaders was only implemented as of unity 5.1 [https://unity3d.com/unity/whats-new/unity-5.1].

So if you’re having problems on a version prior to that you just need to update your editor.