This post may prove helpful: viewtopic.php?p=198669#p198669
Edit: Proof of concept attached. I've reduced the opacity of the mask canvas to let something be seen through.
Flashlight Effect
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Flashlight Effect
- Attachments
-
- flashlight-POC.love
- (142.68 KiB) Downloaded 437 times
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: Flashlight Effect
Thanks! This really workspgimeno wrote:This post may prove helpful: viewtopic.php?p=198669#p198669
Edit: Proof of concept attached. I've reduced the opacity of the mask canvas to let something be seen through.
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: Flashlight Effect
Another help.pgimeno wrote:This post may prove helpful: viewtopic.php?p=198669#p198669
Edit: Proof of concept attached. I've reduced the opacity of the mask canvas to let something be seen through.
I want to add a beam/ray effect from the player's position to the light, I have this code that achieves that
Code: Select all
love.graphics.polygon("fill", lightX + light:getWidth()/2,lightY, player.x + player.w/2,player.y+player.h/2, lightX + light:getWidth()/2, lightY + light:getHeight())
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Re: Flashlight Effect
In your post from that other thread, you saypgimeno wrote:This post may prove helpful: viewtopic.php?p=198669#p198669
Edit: Proof of concept attached. I've reduced the opacity of the mask canvas to let something be seen through.
Can you explain why you think that shader is not the best solution here? It seems more elegant to me, but I'm absolutely no reference so I wonderpgimeno wrote:You can mimic subtractive mode using a shader, if you absolutely must, but I think the effect you're after is best accomplished the above way.
Thanks
Re: Flashlight Effect
You gonna have to pass current canvas into shader and compute proper texture coordinates and there will be blurring due to interpolation, plus you can't write to the canvas you read from so you'll need to duplicate it first.
Re: Flashlight Effect
To yetneverdone:
You probably want the effect to cover the tangent to the circle, not the height. That requires some maths, to figure out the tangent point for a given cast point. Not trivial at all, especially selecting the cast points and the tangent points. If your player is taken as another circle, things may be a bit simpler. See http://mathworld.wolfram.com/Circle-CircleTangents.html. If you can make a mock-up image of what exactly you want, I may be able to help better.
To sherpal:
The transparency is given by the alpha argument to setColor.yetneverdone wrote: Another help.
I want to add a beam/ray effect from the player's position to the light, I have this code that achieves thatBut the problem is that I dont know where to put it, i want it to have a similar transparency effect.Code: Select all
love.graphics.polygon("fill", lightX + light:getWidth()/2,lightY, player.x + player.w/2,player.y+player.h/2, lightX + light:getWidth()/2, lightY + light:getHeight())
You probably want the effect to cover the tangent to the circle, not the height. That requires some maths, to figure out the tangent point for a given cast point. Not trivial at all, especially selecting the cast points and the tangent points. If your player is taken as another circle, things may be a bit simpler. See http://mathworld.wolfram.com/Circle-CircleTangents.html. If you can make a mock-up image of what exactly you want, I may be able to help better.
To sherpal:
Whenever something can be easily done without a shader, I prefer that way. That leaves the shader available for other effects.sherpal wrote:Can you explain why you think that shader is not the best solution here? It seems more elegant to me, but I'm absolutely no reference so I wonder
- yetneverdone
- Party member
- Posts: 448
- Joined: Sat Sep 24, 2016 11:20 am
- Contact:
Re: Flashlight Effect
The transparency is given by the alpha argument to setColor.pgimeno wrote:To yetneverdone:yetneverdone wrote: Another help.
I want to add a beam/ray effect from the player's position to the light, I have this code that achieves thatBut the problem is that I dont know where to put it, i want it to have a similar transparency effect.Code: Select all
love.graphics.polygon("fill", lightX + light:getWidth()/2,lightY, player.x + player.w/2,player.y+player.h/2, lightX + light:getWidth()/2, lightY + light:getHeight())
The code i posted already works, it draws lines from the top of the circle, to the player, then to the bottom of the circle, i tried checking without the blend modes, it created a triangle similar to what i want to achieve. The only thing i need is to make the inside of the triangle to blend like the circle.You probably want the effect to cover the tangent to the circle, not the height. That requires some maths, to figure out the tangent point for a given cast point. Not trivial at all, especially selecting the cast points and the tangent points. If your player is taken as another circle, things may be a bit simpler. See http://mathworld.wolfram.com/Circle-CircleTangents.html. If you can make a mock-up image of what exactly you want, I may be able to help better
My GameDev Website
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Going Home:A Pixelated Horror Game
My Repositories!
Follow me lovingly!
Nga pala, pinoy ako.
Re: Flashlight Effect
raidho36 wrote:You gonna have to pass current canvas into shader and compute proper texture coordinates and there will be blurring due to interpolation, plus you can't write to the canvas you read from so you'll need to duplicate it first.
Thanks, it's clearerpgimeno wrote:Whenever something can be easily done without a shader, I prefer that way. That leaves the shader available for other effects.
Who is online
Users browsing this forum: Google [Bot] and 5 guests