Point Light Attenuation (Deferred rendering path)

Hello, I am beginner at shader writing and I want to achieve a specific result, but I do not have enough knowledge to complete my progress. Can someone please help me?

Firstly, the objective
Link 1:Screenshot by Lightshot
Link 2:Screenshot by Lightshot

The screenshot above shows a light that that is made of multiple circles and when two lights overlap they nicely merge instead of overlapping.

Now I did some research and followed the threads below.http://forum.unity3d.com/threads/ea…ation-with-deferred-path.254337/#post-1681835Changing point light falloff for standard shader? - Unity Engine - Unity Discussions

Secondly, the results achieved
Preview: Screenshot by Lightshot
Also please find a Unity 5.3 project attached. The achieved results produce the single circle of lights, but upon overlapping lights do not merge.

Finally, I will really appreciate it if someone could guide me through this and help to achieve the desired result.

2627929–184671–Point Light Atenuation.zip (1.83 MB)

I don’t think you can simply modify Unitys internal deferred lighting shader, because each light is applied separately to the background.
I think what you want is to render all your lighting of this type into a separate buffer, and then apply it to the background at once in one pass.

When rendering into your separate lighting buffer, you should probably change the blend mode from normal additive to
BlendMode Max
this will store the brightest value from any light at a pixel, instead of a sum of all the lights hitting that pixel.
Try doing some experiments with shaders with that blendmode. Just drawing shapes with custom shaders into a rendertexture.
Once you understand how that works, you need to render shapes actually corresponding to the lights that you want and with the correct intensity that you want, and this has to be rendered against the depth buffer, just like the code in UnityDeferredLibrary does. In fact you might be able to use that library in your shader, but instead of waiting for Unity to call it as part of the pipeline, you will be calling your own shader to render the point lights into your temporary lighting rendertexture.
Once that is done (and you can admire the lighting in your rendertexture), it is time to make a full screen pass where you multiply the lighting in your buffer with the colours/textures of the scene stored in the G-buffer.

This stuff doesn’t deal with reflection. You are on your own there.

1 Like

Thank you for the reply, but I have no idea how to do all of those things, I tried researching as to how to create a separate buffer or what it is but with no results. I also do not understand what type of shader should I be modifying or creating.

Such a buffer would be a RenderTexture. To learn a bit about how rendertextures work, try creating a rendertexture, create an extra camera, and try setting the “targetTexture” of the camera to the rendertexture.
However, I think what you are trying to do is a bit above your current skill level.
Modifying the internal workings of the lighting is quite a tricky and advanced thing to do.
Maybe experiment with some simpler stuff first and see if you can find a similar looking cool effect?

I managed to create a camera render texture without any problems and the effect is easy to understand Outcome: http://prntscr.com/b2k3y6.

However I do not see how RenderTexture will produce this kind of effect: https://twitter.com/hydezeke/status/716021439250493442.

Also I need specifically this effect, maybe there is an easier way of achieving it than modifying the internal workings of the lighting, but so far that is the only method I was able to find.

Previously I have followed the guide linked below step by step but got stuck on the last point of the second option. The guide told to create a C# script with a provided snippet of code but it did not specify what to do with that script so I got stuck.
http://forum.unity3d.com/threads/easiest-way-to-change-point-light-attenuation-with-deferred-path.254337/#post-1681835

The code in the example from the other thread should be put inside a Start() function (not OnStart, he made a mistake)
And that code should be put on some object in your scene. That is what you do with MonoBehaviour scripts.

A RenderTexture can be used to hold intermediate graphics calculations, such as a picture of all the the lighting before the lighting is combined with the background. That would be its role in my original explanation.

Sorry, but it would take me longer to explain to you step by step how to do this, than to code the whole thing myself.
And coding it myself would probably take between half a day and a whole day.

1 Like

I understand. Thank you very much for helping, I played around with the code a bit and managed to get this which is close to the desired result. Screenshot by Lightshot

I will keep trying to figure it out and maybe if i poke it enough I will get what i want : )