Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075932 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:14:49 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Rendering only the edges of a light cone made by raytracing
Pages: [1]
Print
Author Topic: Rendering only the edges of a light cone made by raytracing  (Read 832 times)
Pineapple
Level 10
*****


Love, love is a verb Love is a doing word ~♪


View Profile WWW
« on: September 20, 2013, 04:41:58 PM »

One time I had an idea for a game and I kid you not the thing that ultimately made me too discouraged to keep making it was because I couldn't figure out how I'd do this. Older, marginally smarter me had a go at it and got nowhere.

I wanna draw the white lines:



How even? I mean I could do flood fill and render the borders or just iterate to find each leftmost/rightmost/topmost/bottommost pixel on each axis but that seems really inefficient.
Logged

DelishusCake
Guest
« Reply #1 on: September 20, 2013, 05:42:40 PM »

Raycasting is probably the thing you're going to want to look into. Although I've never delved too deeply into the subject myself, a quick google search lead me to this article which looks similar to what you're looking for.
Logged
surt
Level 5
*****


Meat by-product.


View Profile Email
« Reply #2 on: September 20, 2013, 05:54:19 PM »

Cast ray
Start segment
Ray hits solid
End segment
Draw segment
Continue casting until ray doesn't hit
Repeat
Logged

Real life would be so much better with permadeath.
PJ Gallery - OGA Gallery - CC0 Scraps
Pineapple
Level 10
*****


Love, love is a verb Love is a doing word ~♪


View Profile WWW
« Reply #3 on: September 20, 2013, 06:43:30 PM »

Raycasting is probably the thing you're going to want to look into. Although I've never delved too deeply into the subject myself, a quick google search lead me to this article which looks similar to what you're looking for.

Yeah, I know that much. The hard part is the specific method of rendering just the outline.

Cast ray
Start segment
Ray hits solid
End segment
Draw segment
Continue casting until ray doesn't hit
Repeat

It really isn't that simple.
Logged

Quarry
Level 10
*****



View Profile WWW
« Reply #4 on: September 21, 2013, 04:58:07 AM »

You can try something like this;

cast ray
if it doesn't hit anything, do nothing
if it hits something cast a new ray with the same direction but the origin at the hit point + ray direction * arbitrary treshold
if that second line hits the same thing then render a line from first origin to hit point
Logged

 
rundown
Level 5
*****



View Profile WWW Email
« Reply #5 on: September 21, 2013, 05:10:20 AM »

if you care about rendering speed you could use rays and make a mask out of them.
There is no need to use over a thousand rays like previously mentioned.
Logged

epcc
Level 1
*


View Profile Email
« Reply #6 on: September 21, 2013, 05:33:59 AM »

Can't you do it in GPU? This seems like a job for stencil buffers.

for all shadow casters:
1)Extrude shadow volumes from the shadow caster
2)draw outlines where the stencil buffer is not 1
2)draw filled shadow volume to stencil buffer.

I'm a bit tired, so I might be missing something.
Logged

Whiteclaws
Level 10
*****


Caus' Why Not ?


View Profile Email
« Reply #7 on: September 21, 2013, 06:04:49 AM »

Shoot rays
Lets say 100

If hit , shoot two rays around the ray that just hit
And draw lines if ray hits ...

Or ... Find the vertex of each polygons and draw a line from vertex.x/y to center.x/y + cos/sin(angle from center to vertex)*radistance
Logged

Polar bears are fun ! * Mah Blog *
Xienen
Level 3
***


Greater Good Games


View Profile WWW
« Reply #8 on: September 21, 2013, 06:22:16 AM »

I agree that this can be done rays:
1. Cast a ray from light position along each edge of cone
2. If it hits a piece of geometry, draw a line and then find the corner/edge of geometry nearest the center of the light cone(imagine a line running from the light position straight out in the light's direction)
3. Cast a ray from that corner/edge of the geometry straight away from the light's position

And just repeat this until you reach the end of the desired light cone
Logged

raigan
Level 4
****


View Profile
« Reply #9 on: September 21, 2013, 07:35:23 AM »

Rendering the light/shadows to a separate buffer and running an edge-detection post-process on that is maybe a bit wasteful, but sooooo much simpler than trying to explicitly generate the edge geometry, you might as well try it first and change it later if it's a problem.
Logged
Zaphos
Level 5
*****



View Profile WWW Email
« Reply #10 on: September 21, 2013, 08:32:24 AM »

Raycasting is probably the thing you're going to want to look into. Although I've never delved too deeply into the subject myself, a quick google search lead me to this article which looks similar to what you're looking for.

Yeah, I know that much. The hard part is the specific method of rendering just the outline.
Not sure why that's hard with that algorithm?

I mean, the algo from the end of that article is:
Code:
var endpoints;      # list of endpoints, sorted by angle
var open = [];      # list of walls, sorted by distance

loop over endpoints:
    remember which wall is nearest
    add any walls that BEGIN at this endpoint to 'walls'
    remove any walls that END at this endpoint from 'walls'
   
    SORT the open list
   
    if the nearest wall changed:
        fill the current triangle and begin a new one

You just need to to change the bit that says "fill the current tri" to instead say "draw a segment along this angle from the *old* nearest wall to the *new* nearest wall" (and of course if that line would be zero length, because the walls are contiguous, you draw nothing)
Logged

Polly
Level 4
****


View Profile
« Reply #11 on: September 21, 2013, 11:30:59 AM »

First render your "regular" flood-light result to a stencil / frame / whatever buffer and then render a line from each vertex outwards relative to the light-source using that buffer as a mask ( and don't forget the light-cone lines themselves ).

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic