Isometric shadow casting light.

Game development specific discussions.
Post Reply
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

hmmm from what I can tell, it looks like dodicats routines are more robust (can do concave polygons fully), but is significantly slower... but haven't compared apples to apples on speed yet....only took out the randomize timer and put back in the same 5 point generation, so the polygons are the same, but haven't outfitted his routine with the whole '300 loops' etc etc... i probably won't because it is good to live in my little bubble world where I can make-believe that, just once, I might have figured out a faster (but not necessarily better) way to do one specific thing... lol
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

Dodi,
your function to test if a point is inside a polygon is very interesting! Mind if I use it in my library (with credits of course!)? It seems very handy to be able to determine if a point is in a polygon or not.

I totally do not understand it though...

Code: Select all

Function inpolygon(p1() As Point,Byval p2 As Point) As Integer
    #macro Winder(L1,L2,p)
    ((L1.x-L2.x)*(p.y-L2.y)-(p.x-L2.x)*(L1.y-L2.y))
    #endmacro
    Dim As Integer index,nextindex,k=Ubound(p1)+1,wn
    For n As Integer=1 To Ubound(p1)
        index=n Mod k:nextindex=(n+1) Mod k
        If nextindex=0 Then nextindex=1
        If p1(index).y<=p2.y Then
            If p1(nextindex).y>p2.y Andalso  Winder(p1(index),p1(nextindex),p2)>0 Then wn+=1
        Else
            If p1(nextindex).y<=p2.y Andalso Winder(p1(index),p1(nextindex),p2)<0 Then wn-=1
        End If
    Next n
    Return wn
End Function
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Isometric shadow casting light.

Post by D.J.Peters »

For your shadow filler "fast filled polygon": http://www.freebasic.net/forum/viewtopi ... =7&t=23271
fastes line and polygon stuf can be found in the fbgfx addon also: http://www.freebasic.net/forum/viewtopi ... 8&p=224638&

Joshy
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

D.J.Peters wrote:For your shadow filler "fast filled polygon": http://www.freebasic.net/forum/viewtopi ... =7&t=23271
fastes line and polygon stuf can be found in the fbgfx addon also: http://www.freebasic.net/forum/viewtopi ... 8&p=224638&

Joshy
oooo lovin' it, Herr Peters! I must dissect this routine, really compact and seemingly fast... must compare apples to apples though for true test...

I understand only some of the code... can you describe how it is filling each polygon? does it do it by scanlines as mine does, or what?

in any case, very nicely done - and I love the little rotation algo you used to rotate the points of each polygon... also nice!

I see where it figures out the right graphic bit depths (8,16,24)... does it use the 24 bit mode for doing 32 bit images? or can it do 32bit images?
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

ok, I do see that you are drawing a fill line from left to right... but I absolutely do not see how you are figuring out the left and right most pixels of each scan line.. could you explain this part to me:

Code: Select all

  while t<b     '<--------------while the top is less than the bottom, I am guessing -
                               '                   the top must be used to iterate through towards the bottom, I also guess
    if t=p(lc).y then   '<------------   looks like it is checking to see if the 'top variable' has hit a vertex of the polygon for the LEFT side
        while p(lc).y=p(nlc).y   '<------ is 'nlc' the 'Next 'LEFT SIDE' vertex/corner?
             lc=nlc:nlc-=1:if nlc<0 then nlc=n
        wend
        d1=p(lc).x shl SHIFTS       '<--------------------------------------these next 3 lines must be figuring out the slope from current point to next point...
                                              '                                                am I right?
        s1=((p(nlc).x-p(lc).x) shl SHIFTS)/(p(nlc).y-p(lc).y)
        lc = nlc
    end if
    
    if t=p(rc).y then  '<------------   looks like it is checking to see if the 'top variable' has hit a vertex of the polygon for the RIGHT side
        while p(rc).y=p(nrc).y
             rc=nrc:nrc+=1:if nrc>n then nrc=0
        wend
        d2=p(rc).x shl SHIFTS
        s2=((p(nrc).x-p(rc).x) shl SHIFTS)/(p(nrc).y-p(rc).y)
        rc=nrc
    end if
looks like it is definitely figuring out the slope of both left and right polygon sides at the Y value (scanline) for EACH Y increment, I think, whereas mine pre-calcs the slope for the entire polygon side, so there is a chance my 'pseudo code' or algo might be 'faster', but your implementation is sooo very elegant! Wish I knew how you figured out the slopes... doesn't make immediate sense to me yet... also, I assume this routine requires the polygon points to already be ordered in a clockwise winding method, right?
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

I was mostly right, but partially wrong... the routine does NOT figure out the slope adj for each row (y pos) as I thought. It works just like mine except is ALOT more optimized... so it should kick my implementation in the butt! BUT, I was right that it does the polygon fill the same basic way - iterating through the Top to the bottom, keeping track of the left and right sides, and drawing a line between them... very nice! I like the 'Circle Sort' routine and how it leaves the array of points in a way that makes it more efficient to go from one to another without my 'linked list' feature... great idea!

I am having some trouble with your whole 'integer slope' method though... I understand you shift the value left a full byte to give 'room' for the fractional part, but I never see the opposite shift to get the value back to just pure integer... I must be missing something.

This is such a nice routine, Herr Peters, thank you for sharing!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Isometric shadow casting light.

Post by D.J.Peters »

leopardpm wrote:I am having some trouble with your whole 'integer slope' method though... I understand you shift the value left a full byte to give 'room' for the fractional part, but I never see the opposite shift to get the value back to just pure integer... I must be missing something.
SHR is the opposite shift ;-)

don't wory sometimes i'm blind also :-)

Joshy

Code: Select all

if t>-1 then
      l=d1 shr SHIFTS ' most left  pixel
      r=d2 shr SHIFTS ' most right pixel
      ...
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

duh! thanks
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: Isometric shadow casting light.

Post by thesanman112 »

Its been a long time since ive been in this forum...litterally years, hello to all....

I briefly looked at your code best i could on a cellphone,
Quick tip...get rid of all the else statements.....
I remember coding , havent touched it in 5 years, but i DO know that the 'else' statement is a speed killer....

Just got a new laptop so i may get back at it....who knows...
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

thesanman112 wrote:Its been a long time since ive been in this forum...litterally years, hello to all....

I briefly looked at your code best i could on a cellphone,
Quick tip...get rid of all the else statements.....
I remember coding , havent touched it in 5 years, but i DO know that the 'else' statement is a speed killer....

Just got a new laptop so i may get back at it....who knows...
welcome back! Hop right in - coding is fun, just like riding a bike
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Isometric shadow casting light.

Post by D.J.Peters »

leopardpm wrote:coding is fun
At the beginning than it's like a kind of drug you can't stop it and you need it again and again and again ! ;-)
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: Isometric shadow casting light.

Post by thesanman112 »

I just also noticed and should mention...for speed wise anyways...calling subs or macros to perform a given operation with a bunch of constants robs or steals from runtime performance....


Still reading whole post....hehehe
Trinity
Posts: 214
Joined: Sep 16, 2017 17:07

Re: Isometric shadow casting light.

Post by Trinity »

leopardpm wrote:Here is something for ya
And Here is something for ya :
Seeing the current timer frequency is easy – just run the clockres tool by sysinternals :
https://docs.microsoft.com/en-us/sysint ... s/clockres
To explore more get the Windows Timestamp Project! : http://www.windowstimestamp.com
Download : http://www.windowstimestamp.com/download
And read the G_HowTo : http://www.windowstimestamp.com/G_HowTo_0260.pdf

My entry to why I had to deal with the timer stuff were this : viewtopic.php?f=6&t=26008
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Isometric shadow casting light.

Post by leopardpm »

Trinity wrote:
leopardpm wrote:Here is something for ya
And Here is something for ya :
Seeing the current timer frequency is easy – just run the clockres tool by sysinternals :
https://docs.microsoft.com/en-us/sysint ... s/clockres
To explore more get the Windows Timestamp Project! : http://www.windowstimestamp.com
Download : http://www.windowstimestamp.com/download
And read the G_HowTo : http://www.windowstimestamp.com/G_HowTo_0260.pdf

My entry to why I had to deal with the timer stuff were this : viewtopic.php?f=6&t=26008
Whoa!? I was always wondering why sometimes my programs ran very slow and other times they were lickity fast.... sheesh!!! Thanks for ppointing this thread out to me, hopefully I will remember to look it up again when I next have a chance to code again...
Post Reply