I am trying to do the same, but using Light Probes for affecting the dynamic characters with the baked lighting. It doesn't work with the SkeletonLit shader though. The built-in Standard shader does work, so I do believe it is just a limitation of the SkeletonLit shader.
Has anyone had success with lighting a character with Baked GI?
Also, if I use realtime lighting, my character is lit only when the light source has a greater z-index. When the skeleton is flipped (i.e. moving left) he is only lit when the light source has a lower z-index value.
03 Mar 2016 12:12 am
Hey,
I've gotten a partially working solution. I hacked together the existing Spine/SkeletonLit shader with the built-in Unity Standard shader, and now the baked lighting with light probes casts light onto the dynamic characters. This is the shader (I have only rudimentary shader knowledge, so if anyone can improve this, that would be great - note it still contains some cruft that isnt used from the Standard shader, but I am still fiddling on my end).
Shader "Spine/Skeleton Lit Unity"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
// Blending state
[HideInInspector] _Mode ("__mode", Float) = 0.0
[HideInInspector] _SrcBlend ("__src", Float) = 1.0
[HideInInspector] _DstBlend ("__dst", Float) = 0.0
[HideInInspector] _ZWrite ("__zw", Float) = 1.0
}
CGINCLUDE
#define UNITY_SETUP_BRDF_INPUT MetallicSetup
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// Spine
Cull Off
ZWrite On
Blend One OneMinusSrcAlpha
Pass {
Tags { "LightMode"="Vertex" }
ColorMaterial AmbientAndDiffuse
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
//
---
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma target 3.0
// TEMPORARY: GLES2.0 temporarily disabled to prevent errors spam on devices without textureCubeLodEXT
#pragma exclude_renderers gles
//
---
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma multi_compile_fwdbase
#pragma vertex vertForwardBase
#pragma fragment fragForwardBase
#include "UnityStandardCore.cginc"
ENDCG
}
}
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 150
// Spine
Cull Off
ZWrite On
Blend One OneMinusSrcAlpha
Pass {
Tags { "LightMode"="Vertex" }
ColorMaterial AmbientAndDiffuse
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
//
---
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma target 2.0
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile_fwdbase
#pragma vertex vertForwardBase
#pragma fragment fragForwardBase
#include "UnityStandardCore.cginc"
ENDCG
}
}
FallBack "VertexLit"
CustomEditor "StandardShaderGUI"
}
You then just set up your probes as describe on the Unity docs. I laid out probes at the same z-index as the hero, and equal distance farther and closer to the camera to create my volume. The other thing to be sure to do is set the anchor override to the SkeletonUtility-Root so that the same interpolation point will be used no matter which way your skeleton mesh is facing.
I haven't figured out shadows yet, hopefully I can get those working with baked lighting as well.