BPR
April 5, 2021, 11:49am
1
Hi,
I would like to gain some fine control over reflection probe strength, lightprobe and lightmap intensity in one of my existing shaders.
I started adapting form this custom GI example here.
However I soon hit some walls:
I cant use a void Lighting_GI function like in the example or Unity will complain (and have no clue what to actually return there):
Shader error in ‘Skin/MinExample’: Surface shader lighting model ‘Skin’ is missing a forward or deferred function (Skin) at line 22
As soon as I add the UnityGI gi parameter to my Lighting function the output color will be black
I am general confused how the Lighting and Lighting_GI function will interact :
Do I need the UnityGI gi parameter in Lighting? Do I have to add it manually to the resulting color like c.rgb += gi.indirect.specular;
Do I need to call Lighting_GI somewhere in my code? At the moment it seems like it does nothing.
I broke my shader down to an simple minimal example, any help is greatly appreciated.
Kind regards!
7007126–828704–MinExample.shader (6.15 KB)
bgolus
April 6, 2021, 6:07pm
2
You can try looking at the code used by Unity’s own Surface Shaders:
half4 emission = half4(s.Emission, 1);
#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
emission.rgb += s.Albedo * gi.indirect.diffuse;
#endif
return emission;
}
inline void LightingLambert_GI (
SurfaceOutput s,
UnityGIInput data,
inout UnityGI gi)
{
gi = UnityGlobalIllumination (data, 1.0, s.Normal);
}
inline fixed4 LightingLambert_PrePass (SurfaceOutput s, half4 light)
{
fixed4 c;
data.specularColor = specColor;
data.smoothness = s.Smoothness;
data.normalWorld = s.Normal;
UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2);
half4 emission = half4(s.Emission + c.rgb, 1);
return emission;
}
inline void LightingStandard_GI (
SurfaceOutputStandard s,
UnityGIInput data,
inout UnityGI gi)
{
#if defined(UNITY_PASS_DEFERRED) && UNITY_ENABLE_REFLECTION_BUFFERS
gi = UnityGlobalIllumination(data, s.Occlusion, s.Normal);
#else
Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup(s.Smoothness, data.worldViewDir, s.Normal, lerp(unity_ColorSpaceDielectricSpec.rgb, s.Albedo, s.Metallic));
gi = UnityGlobalIllumination(data, s.Occlusion, s.Normal, g);
#endif
BPR
April 7, 2021, 10:17am
3
Okay I found the issue by transforming step by step between the example and my MinExample:
inline float4 LightingSkin(SurfaceOutputSkin s, fixed3 lightDir, float3 viewDir, fixed atten , UnityGI gi)
Is not recognized by Unity because of the extra paramters.
It has to be:
inline float4 LightingSkin(SurfaceOutputSkin s, float3 viewDir, UnityGI gi)
lightDir can be accessed via gi.light.dir
and attenuation seems to be already included in gi.light.color
Thanks for your time guys!