Unity's Reflective/Diffuse is Broken. Here's the Fix.

The Reflective/Diffuse shader shipping with Unity 2.6.0 (haven’t checked 2.6.1 just yet) does not work properly when the object is lit exclusively with vertex lighting. Here’s how you fix it – it’s just one line.

Shader "MrJoy/Reflective/Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
_MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
_Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
SubShader {
LOD 200
Tags { "RenderType"="Opaque" }
UsePass "Reflective/VertexLit/BASE"
UsePass "Reflective/VertexLit/" // <-- This is the new line.
UsePass "Diffuse/PPL"
FallBack "Reflective/VertexLit", 1

Basically, the Reflective/VertexLit shader has two passes, not one and the Diffuse shader is only including the first one – the one used for the reflective term. The additional line adds in the second pass, and all is well.

EDIT: This only resolves the case where the object is lit ONLY by vertex lighting. In the event of pixel + vertex lighting, it still behaves as if only the pixel light was hitting it. Bah. Will suss it out later.

unity 178 words, est. time: 35 seconds.

« A Brief Treatise on Events and the Object Lifecycle in Unity Prefab Overrides Considered Harmful »


Copyright © 2018 - Jon Frisby - Powered by Octopress