Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Improvements...
#1
If anyone has some ideas to allow TC-Ray to get recursive, I'll be really glad to read him (or her :wink: )...

I finally managed to allow an object to self shadow and self reflect, and I'm doing my best to gest rid of wrong shadows, false transparencies, etc... as you can see on these two pics.

Before:
[Image: TcRay1.jpg]
After:
[Image: TcRay1a.jpg]

Note: I had a lot of wrong pixels with the 4th degree shapes. There was a real stupid typing error in the code! :rotfl:
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#2
What do you mean by recursive...

How is your code structured....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
My "Draw.Space" module does this:

1 - Probe space with a ray coming from the camera, probe all the shapes, and stores the data from the closest shape (hitpoint)

2 - If a shape is hit, send a ray from the light point towards the hitpoint, to check if a shadowing must be applied

3 - Send one more ray , calculated by reflection on the hitpoint, to check if another shape is here, and merge the colour from hitpoint with the colour from the second shape.

And that's it. It's non recursive.

Recursive would mean : " I send a ray from the camera, and this ray will reflect, fade and shadow a couple of times until it dies"...

The problem is 1) I never used recursive coding, 2) TC-Ray is already very heavy, I'm not sure recursiveness would be acceptable in terms of rendering time...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#4
Just for pleasure and fun: it's the first time I plot greyscaled shapes! 8)

[Image: TcRay6.jpg]
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#5
You just need to optimize....

What you need to do is to create several arrays holding individual characteristics of each ray. (NOT a type, just arrays, types are bad..) (You set some reailstic limit to that array) Then you set a start point and and end point. At the start, the start and end points are both 1. (starting from 1 in the array). When you go through the array from the start to the end, you compute the start conditions of the further rays starting from (end point + 1). Call that current.point.

When you finish going through the first array, you set the start point as the current (end point + 1) and the end as current.point. You then set current point equal to (end point + 1), etc etc etc.

When any of these array indexes go over the array limit, you wrap around them. You could do this with an if statement but also with MOD:

a = (a + 1) mod 64.

Using powers of two for array maximums makes your recursion go faster:

a = (a + 1) and 63.

(I believe that and the one before is equivalent)..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
I'll try to integrate that arrays logics in my own logics :lol:

Hope this will not slow down the prog too much, though: for an average view, let's say 640x480, I already have something like 900000 potential rays...
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#7
One thing you could do is integrate your rays so that they all come out as one equation thing........ :|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#8
I don't know if you've seen the code of Tc-Ray, Aga. Just have a look and tell me what you think about that... There are tons of equations in my prog!

http://mandelbrot.dazibao.free.fr/Tcray/TcRay21.zip
hink Global, Make Symp' All ! ®
[Image: Banner.gif]
Reply
#9
You can do some work on your ORs: instead of OR, rewrite the code twice. The first time have it goto a spot so that it skips the second test (if the first test says T)

Also in your box24 sub:
Code:
FOR x% = x1% TO x2%
IF Pattern% = 0 OR (x% AND Pattern%) THEN Pset24 x%, y1%
NEXT x%
FOR x% = x1% TO x2%
IF Pattern% = 0 OR (x% AND Pattern%) THEN Pset24 x%, y2%
NEXT x%

you can change it to this, if pset24 doesn't change pattern%:

Code:
IF pattern% = 0 THEN
FOR x% = x1% TO x2%: pset24b x%, y1%, y2%: NEXT x%
ELSE
FOR x% = x1% TO x2%
IF (x% AND pattern%) THEN pset 24b x%, y1%, y2%: NEXT x%
NEXT x%
END IF

SUB pset24b (x%, y1%, y2%)
' Plots a pixel using the current RGB combination

CONST Ww = &HFFFF&

IF x% < xPlotMin% THEN EXIT SUB
IF x% > xPlotMax% THEN EXIT SUB
IF y1% < yPlotMin% THEN EXIT SUB
IF y1% > yPlotMax% THEN EXIT SUB
IF y2% < yPlotMin% THEN EXIT SUB
IF y2% > yPlotMax% THEN EXIT SUB

DEF SEG = &HA000

Offset& = xBpp&(x%) + yLut(y1%).Offset
Bank% = yLut(y1%).Bank%

IF Offset& > Ww THEN
  Offset& = Offset& AND Ww
  Bank% = Bank% + 1
END IF
IF Bank% <> CurBank% THEN
  CurBank% = Bank%
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Blue%
Offset& = Offset& + 1
IF Offset& > Ww THEN
  Offset& = Offset& AND Ww
  CurBank% = CurBank% + 1
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Green%
Offset& = Offset& + 1
IF Offset& >= Ww THEN
  Offset& = Offset& AND Ww
  CurBank% = CurBank% + 1
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Red%

Offset& = xBpp&(x%) + yLut(y2%).Offset
Bank% = yLut(y2%).Bank%

IF Offset& > Ww THEN
  Offset& = Offset& AND Ww
  Bank% = Bank% + 1
END IF
IF Bank% <> CurBank% THEN
  CurBank% = Bank%
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Blue%
Offset& = Offset& + 1
IF Offset& > Ww THEN
  Offset& = Offset& AND Ww
  CurBank% = CurBank% + 1
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Green%
Offset& = Offset& + 1
IF Offset& >= Ww THEN
  Offset& = Offset& AND Ww
  CurBank% = CurBank% + 1
  Regs.ax = &H4F05
  Regs.bx = 0
  Regs.dx = CurBank%
  CALL INTERRUPT(&H10, Regs, Regs)
END IF
POKE Offset&, Red%
END SUB

You might also want to check the "IF offset& >= Ww" thing... looks suspicious.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#10
Also, you might want to consider changing ellipse24 to this:

Code:
SUB ellipse24 (cx1%, cy1%, cx2%, cy2%, pattern%)
' Plots the ellipse included in the rectangle between two points
' Patterns are managed as in the Line24 and Circle 24 routines
' Colour is defined by the shared variables Red%, Green% and Blue%

x1% = cx1%: x2% = cx2%: y1% = cy1%: y2% = cy2%

IF x1% = x2% THEN
IF y1% = y2% THEN Pset24 x1%, y1%: EXIT SUB
Line24 x1%, y1%, x2%, y2%, pattern%: EXIT SUB
END IF
IF y1% = y2% THEN Line24 x1%, y1%, x2%, y2%, pattern%: EXIT SUB

IF x1% > x2% THEN SWAP x1%, x2%
IF y1% > y2% THEN SWAP y1%, y2%

x0% = INT((x1% + x2%) / 2 + .5): Rx% = x0% - x2%
y0% = INT((y1% + y2%) / 2 + .5): Ry% = y0% - y2%

IF pattern% = 0 THEN
x% = 0: y% = Ry%
rxsq& = (Rx% / Ry%) ^ 2
DO WHILE x% <= rxsq& * y%
y% = INT(Ry% * SQR(1 - (x% / Rx%) ^ 2) + .5)
Pset24 x% + x0%, y% + y0%
Pset24 x% + x0%, -y% + y0%
Pset24 -x% + x0%, y% + y0%
Pset24 -x% + x0%, -y% + y0%
x% = x% + 1
LOOP
y% = 0: x% = Rx%
rysq& = (Ry% / Rx%) ^ 2
DO WHILE y% <= rysq& * x%
x% = INT(Rx% * SQR(1 - (y% / Ry%) ^ 2) + .5)
Pset24 x% + x0%, y% + y0%
Pset24 x% + x0%, -y% + y0%
Pset24 -x% + x0%, y% + y0%
Pset24 -x% + x0%, -y% + y0%
y% = y% + 1
LOOP
ELSE
x% = 0: y% = Ry%
rxsq& = (Rx% / Ry%) ^ 2
DO WHILE x% <= rxsq& * y%
y% = INT(Ry% * SQR(1 - (x% / Rx%) ^ 2) + .5)
IF (x% AND pattern%) THEN
Pset24 x% + x0%, y% + y0%
Pset24 x% + x0%, -y% + y0%
Pset24 -x% + x0%, y% + y0%
Pset24 -x% + x0%, -y% + y0%
END IF
x% = x% + 1
LOOP
y% = 0: x% = Rx%
rysq& = (Ry% / Rx%) ^ 2
DO WHILE y% <= rysq& * x%
x% = INT(Rx% * SQR(1 - (y% / Ry%) ^ 2) + .5)
IF (y% AND pattern%) THEN
Pset24 x% + x0%, y% + y0%
Pset24 x% + x0%, -y% + y0%
Pset24 -x% + x0%, y% + y0%
Pset24 -x% + x0%, -y% + y0%
END IF
y% = y% + 1
LOOP
END IF

END SUB
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)