Custom deferred lighting shader, custom attenuation value ignored by GI and custom light models

So, I’ve downloaded the built-in shaders. I took the CGIncludes/UnityDeferredLibrary.cginc and DefaultResourcesExtra/Internal-DeferredShading.shader files, imported them into Unity and modified them to my liking. (Shader is applied in Edit > Project Settings > Graphics.)

However, light bouncing (GI) still acts according to the default light attenuation, and shaders using custom lighting models still receive the default atten value. What do I have to change to fix that?

If you modify anything inside UnityDeferredLibrary.cginc, do not forget to define that files path inside your Internal-DeferredShading.shader, or it will continue using Unity’s built-in one.

VacuumShaders - Facebook Twitter YouTube

The deferred overrides only affect the deferred lighting, which is what you described. Custom lighting models are not deferred, they are rendered as forward passes. The only thing the deferred rendering path can render is the standard lighting model. To change the custom lighting models requires modifying the file where the various ATTENUATION macros are defined (AutoLight.cginc I think), or overriding those macros within your shader with #undef and #define.

GI is a little more difficult, perhaps impossible, depending on exactly what you want to do and what kind of features you’re using. There’s no way I know of to override the light attenuation for built in light probes or from precomputed realtime GI or for lightmaps as some of that is handled in native code. I’ve never attempted to override that side of things though so someone else might have a better idea.

1 Like

Okay, thanks! I will try to change that. If you know, can I override that file within Unity, or will I have to modify the actual Unity’s file?

That particular file isn’t as easy to override as just changing a setting in the graphics settings, but yes you can override it by replacing the file in the Unity program folder, though that means it’ll easily be lost if you upgrade Unity.

Instead you’ll want to place a copy of AutoLight.cginc into the same asset folder as your shader(s). You may also need to place copies of the full .cginc file chain. What I mean by that is some shaders have #include “AutoLight.cginc” in them directly, in which case putting the AutoLight.cginc file in the same folder will make those shaders use the copy. If the shader does not have that line but instead has a different file it links to with #include, which may link to another file, that eventually #includes “AutoLight.cginc” all of those files need to be copied.

Also if you’re using a built in shader, like the standard shader, it will not have it’s includes overridden by copies placed in the asset folders. You’ll need to make copies of the built in shaders you wish to override as well.

1 Like