How can I implement a revealing light beam?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
6
down vote
favorite
In SEARCHLIGHT, you control a ray of light that illuminates incoming enemies that are otherwise invisible in the night sky. Here is an illustration:
How would I go about doing this, preferably in Unity? I imagine this is less about lighting and more about shaders, but I'm not sure on details. The fact that I know very little about coding shaders makes it worse.
If it is about shaders, what are the specifics? Is there a stretched quad that moves with said shader applied to it, or perhaps is using the Line Renderer a better option?
As a beginner, may I try to achieve a similar effect, or should I leave it for when I'm better?
(P.S.: The game was made in Unity. Here is its itch.io page.)
unity 2d shaders lighting
add a comment |Â
up vote
6
down vote
favorite
In SEARCHLIGHT, you control a ray of light that illuminates incoming enemies that are otherwise invisible in the night sky. Here is an illustration:
How would I go about doing this, preferably in Unity? I imagine this is less about lighting and more about shaders, but I'm not sure on details. The fact that I know very little about coding shaders makes it worse.
If it is about shaders, what are the specifics? Is there a stretched quad that moves with said shader applied to it, or perhaps is using the Line Renderer a better option?
As a beginner, may I try to achieve a similar effect, or should I leave it for when I'm better?
(P.S.: The game was made in Unity. Here is its itch.io page.)
unity 2d shaders lighting
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
In SEARCHLIGHT, you control a ray of light that illuminates incoming enemies that are otherwise invisible in the night sky. Here is an illustration:
How would I go about doing this, preferably in Unity? I imagine this is less about lighting and more about shaders, but I'm not sure on details. The fact that I know very little about coding shaders makes it worse.
If it is about shaders, what are the specifics? Is there a stretched quad that moves with said shader applied to it, or perhaps is using the Line Renderer a better option?
As a beginner, may I try to achieve a similar effect, or should I leave it for when I'm better?
(P.S.: The game was made in Unity. Here is its itch.io page.)
unity 2d shaders lighting
In SEARCHLIGHT, you control a ray of light that illuminates incoming enemies that are otherwise invisible in the night sky. Here is an illustration:
How would I go about doing this, preferably in Unity? I imagine this is less about lighting and more about shaders, but I'm not sure on details. The fact that I know very little about coding shaders makes it worse.
If it is about shaders, what are the specifics? Is there a stretched quad that moves with said shader applied to it, or perhaps is using the Line Renderer a better option?
As a beginner, may I try to achieve a similar effect, or should I leave it for when I'm better?
(P.S.: The game was made in Unity. Here is its itch.io page.)
unity 2d shaders lighting
unity 2d shaders lighting
edited Sep 25 at 12:00
DMGregoryâ¦
53.4k1198151
53.4k1198151
asked Sep 25 at 8:10
Demetre Saghliani
312
312
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
8
down vote
One way to implement an effect like this is with the stencil buffer.
This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.
You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader
or Pass
section:
Stencil
Ref 1
Comp always
Pass replace
This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.
Then, for objects that should only show up inside the light beam, use:
Stencil
Ref 1
Comp equal
This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.
Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
One way to implement an effect like this is with the stencil buffer.
This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.
You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader
or Pass
section:
Stencil
Ref 1
Comp always
Pass replace
This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.
Then, for objects that should only show up inside the light beam, use:
Stencil
Ref 1
Comp equal
This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.
Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.
add a comment |Â
up vote
8
down vote
One way to implement an effect like this is with the stencil buffer.
This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.
You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader
or Pass
section:
Stencil
Ref 1
Comp always
Pass replace
This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.
Then, for objects that should only show up inside the light beam, use:
Stencil
Ref 1
Comp equal
This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.
Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.
add a comment |Â
up vote
8
down vote
up vote
8
down vote
One way to implement an effect like this is with the stencil buffer.
This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.
You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader
or Pass
section:
Stencil
Ref 1
Comp always
Pass replace
This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.
Then, for objects that should only show up inside the light beam, use:
Stencil
Ref 1
Comp equal
This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.
Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.
One way to implement an effect like this is with the stencil buffer.
This is an extra few bits the renderer keeps around for every pixel in a render target, that you can use for scratch notes about what you've drawn there or are allowed to draw later.
You can create a new shader using one of Unity's built-in templates, and add some stencil operations to the top of the SubShader
or Pass
section:
Stencil
Ref 1
Comp always
Pass replace
This says "write a 1 into the stencil buffer, no matter what was there before" - put this on the shader/material that you use to render your light beam quad, and it will mark all the on-screen pixels it's touched.
Then, for objects that should only show up inside the light beam, use:
Stencil
Ref 1
Comp equal
This checks to see if the magic number 1 got written into this pixel previously (ie. is this pixel illuminated by the light beam?) - if not, the shader aborts rendering this pixel of the object, neatly clipping it to just the illuminated region of your screen.
Make sure your objects that read the stencil information render later in the queues than the objects that write it, so the information is ready for them when they look for it.
answered Sep 25 at 12:13
DMGregoryâ¦
53.4k1198151
53.4k1198151
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgamedev.stackexchange.com%2fquestions%2f163978%2fhow-can-i-implement-a-revealing-light-beam%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password