Hello! In my 2D platformer I am using a sprite with a custom additive shader to illuminate objects in a simple retro fashion. Currently it has the effect of illuminating the “near” background as well as the “far” background, as demonstrated in this screenshot:
I am seeking to accomplish a similar effect but without illuminating the “far” background, as illustrated in this mockup:
Here is the code for the shader:
Shader "Custom/Additive"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
[HDR]_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
ZWrite Off
Blend DstColor DstAlpha
Pass
{
CGPROGRAM
#pragma vertex SpriteVert
#pragma fragment SpriteFrag
#pragma target 2.0
#pragma multi_compile_instancing
#pragma multi_compile_local _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#include "UnitySprites.cginc"
ENDCG
}
}
}
So far I’ve explored multiple-camera solutions to no avail, and my understanding of shaders is unfortunately very rudimentary. I expect the simplest solution would be to change the sky background shader. The tilemaps and objects in the scene use a modified sprite shader that allows basic pallette swapping, and the sky background uses the default sprite shader. All renderers are on the default Sorting Layer, and arranged using the Order in Layer value. A highly performant solution is especially preferable as I am targeting lower-end hardware.
Thanks!