I’m trying to create a PBL shader that uses vertex colors to control texture splatting. I’ve got the blending working, but my shader is letting shadows shine through solid geometry somehow:
This is the shader code (also uploaded to PasteBin in case of copy/paste trouble)
Shader "Custom/PBS Splat (Premultiplied)" {
Properties {
//_Color("Color", Color) = (1,1,1)
_MainTex("Layer 1 Diffuse", 2D) = "white" {}
[NoScaleOffset] _MainBump("Layer 1 Normals", 2D) = "bump" {}
[NoScaleOffset] _MainSpecular("Layer 1 Specular", 2D) = "white" {}
[NoScaleOffset] _MainOcclusion("Layer 1 Occlusion", 2D) = "white" {}
_SecondTex("Layer 2 Diffuse", 2D) = "white" {}
[NoScaleOffset] _SecondBump("Layer 2 Normals", 2D) = "bump" {}
[NoScaleOffset] _SecondSpecular("Layer 2 Specular", 2D) = "white" {}
[NoScaleOffset] _SecondOcclusion("Layer 2 Occlusion", 2D) = "white" {}
_ThirdTex("Layer 3 Diffuse", 2D) = "white" {}
[NoScaleOffset] _ThirdBump("Layer 3 Normals", 2D) = "bump" {}
[NoScaleOffset] _ThirdSpecular("Layer 3 Specular", 2D) = "white" {}
[NoScaleOffset] _ThirdOcclusion("Layer 3 Occlusion", 2D) = "white" {}
//_BumpScale("Scale", Float) = 1.0
//[NoScaleOffset] _EmissionMap("Emission", 2D) = "black" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
#define _GLOSSYENV 1
#include "UnityPBSLighting.cginc"
sampler2D _MainTex;
sampler2D _MainBump;
sampler2D _MainSpecular;
sampler2D _MainOcclusion;
sampler2D _SecondTex;
sampler2D _SecondBump;
sampler2D _SecondSpecular;
sampler2D _SecondOcclusion;
sampler2D _ThirdTex;
sampler2D _ThirdBump;
sampler2D _ThirdSpecular;
sampler2D _ThirdOcclusion;
//sampler2D _EmissionMap;
//fixed4 _Color;
//half _BumpScale;
struct Input {
float2 uv_MainTex : TEXCOORD;
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 l1 = tex2D (_MainTex, IN.uv_MainTex);
fixed4 l2 = tex2D (_SecondTex, IN.uv_MainTex);
fixed4 l3 = tex2D (_ThirdTex, IN.uv_MainTex);
o.Albedo = ((l1 * IN.color.r) + (l2 * IN.color.g) + (l3 * IN.color.b)).rgb;
l1 = tex2D(_MainBump, IN.uv_MainTex);
l2 = tex2D(_SecondBump, IN.uv_MainTex);
l3 = tex2D(_ThirdBump, IN.uv_MainTex);
//o.Normal = normalize(UnpackScaleNormal(tex2D(_BumpMap, IN.uv_MainTex), _BumpScale));
o.Normal = ((l1 * IN.color.r) + (l2 * IN.color.g) + (l3 * IN.color.b)).rgb;
l1 = tex2D(_MainSpecular, IN.uv_MainTex);
l2 = tex2D(_SecondSpecular, IN.uv_MainTex);
l3 = tex2D(_ThirdSpecular, IN.uv_MainTex);
fixed4 specular = (l1 * IN.color.r) + (l2 * IN.color.g) + (l3 * IN.color.b);
o.Specular = specular.rgb;
o.Smoothness = specular.a;
l1 = tex2D(_MainOcclusion, IN.uv_MainTex);
l2 = tex2D(_SecondOcclusion, IN.uv_MainTex);
l3 = tex2D(_ThirdOcclusion, IN.uv_MainTex);
o.Occlusion = ((l1 * IN.color.r) + (l2 * IN.color.g) + (l3 * IN.color.b)).g;
}
ENDCG
}
}
I’m targeting WebGL, so I assume it’s forward and not deferred rendering, thus I’ve enabled all forward shadow types in the shader.
Does anyone have an idea why the shadow is showing through the mesh?

