Page 2 of 2
Re: Flashlight Effect
Posted: Sun Oct 23, 2016 7:05 pm
by pgimeno
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.
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 4:08 am
by yetneverdone
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.
Thanks! This really works
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 6:40 am
by yetneverdone
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.
Another help.
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())
But the problem is that I dont know where to put it, i want it to have a similar transparency effect.
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 10:09 am
by sherpal
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.
In your post from that other thread, you say
pgimeno 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.
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
Thanks
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 2:34 pm
by raidho36
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
Posted: Mon Oct 24, 2016 2:46 pm
by pgimeno
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 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())
But the problem is that I dont know where to put it, i want it to have a similar transparency effect.
The transparency is given by the alpha argument to setColor.
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:
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
Whenever something can be easily done without a shader, I prefer that way. That leaves the shader available for other effects.
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 3:16 pm
by yetneverdone
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 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())
But the problem is that I dont know where to put it, i want it to have a similar transparency effect.
The transparency is given by the alpha argument to setColor.
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
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.
Re: Flashlight Effect
Posted: Mon Oct 24, 2016 5:42 pm
by sherpal
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.
pgimeno wrote:Whenever something can be easily done without a shader, I prefer that way. That leaves the shader available for other effects.
Thanks, it's clearer