Hi.
On begining I want to say "thank you" for this nice engine. I realy love LÖVE
In my project I have level like this:
And I want to limit the field of view of player to let him "see" only things not curtained by sprites. Like on screen below:
I feel that I should use raycasting to find visible part and i'm think about using shaders to cover invisible part (for example: grain effect). But I don't have an idea how to do that. Is it even possible to do it using raycasting + shaders? Or maybe my idea is wrong and there is a better way to obtain this feature?
Any constructive answer will welcome.
Thanks
Jakub
Field of view, limited by sprites
Re: Field of view, limited by sprites
Hello Irok, there is a simple way to achieve the effect you are going for without shaders or raycasting.
If you only have 1 light source (the position of the player) - you only need to draw the shadows.
This can be done by the following pseudo algorithm:
1.iterate each polygon in the environment
2.iterate each edge in the polygon
[optional optimization, ignore edges on the 'back' of polygons since they're already in the shadow, 'back' edges can be detected using the dot product]
3.draw the shadow for the edge
a) convert the vertex edge to local coords: localVector1 = vertex1 - playerPosition
b) find the length and normal of the local vector: normal = localVector1/length(localVector1)
c) extend/project the vertex away from the player using the normal vector: projected1 = normal1*castDistance
d) draw a trapezoid for each edge: vertex1,vertex2, vertex2+projected2, vertex1+projected1
code: viewtopic.php?f=14&t=78726#p173502
That's it, as long as you're working with 1 light source, the technique above should work even with concave polygons.
You can draw your shadows on top of a while radial gradient for a better effect.
If you only have 1 light source (the position of the player) - you only need to draw the shadows.
This can be done by the following pseudo algorithm:
1.iterate each polygon in the environment
2.iterate each edge in the polygon
[optional optimization, ignore edges on the 'back' of polygons since they're already in the shadow, 'back' edges can be detected using the dot product]
3.draw the shadow for the edge
a) convert the vertex edge to local coords: localVector1 = vertex1 - playerPosition
b) find the length and normal of the local vector: normal = localVector1/length(localVector1)
c) extend/project the vertex away from the player using the normal vector: projected1 = normal1*castDistance
d) draw a trapezoid for each edge: vertex1,vertex2, vertex2+projected2, vertex1+projected1
code: viewtopic.php?f=14&t=78726#p173502
That's it, as long as you're working with 1 light source, the technique above should work even with concave polygons.
You can draw your shadows on top of a while radial gradient for a better effect.
Last edited by ivan on Tue Nov 15, 2016 8:15 am, edited 5 times in total.
Re: Field of view, limited by sprites
ivan, so tell me the secret
EDIT: I didn't see full post previously, sorry and thanks.
EDIT: I didn't see full post previously, sorry and thanks.
Last edited by irok84 on Tue Nov 15, 2016 8:15 am, edited 1 time in total.
-
- Party member
- Posts: 134
- Joined: Tue Mar 29, 2011 11:05 pm
Re: Field of view, limited by sprites
drunken_munki, thanks for link, I'll try this too.
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Field of view, limited by sprites
I wonder if something like this tutorial can be done in LÖVE with shaders
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Who is online
Users browsing this forum: No registered users and 1 guest