Posted By
MMS on 2024-12-08 14:22:33
| Re: Raytracer for Plus4
Wow, this is so cool!
I know that Amiga raytrace and end result is at a different level, but I remember my friend's Amiga calculated 12-16 hours a simple raytrace picture.
Here is the original code by Daniel A Nagy: I added some speeding elements I learned in the past (from differencvideos, books): -use variables whenever possible within a routine,. In this way the machine should not translate and covert the number in text into the float format every single time (for variables 5 bytes compact used) -use . instead of 0, it is evaluated faster. Maybe I should use a variable too for 0? -do not use NEXT J, just use NEXT. Faster, the machine knows where it is, less text to decode
Please let me know if any further speedup is possible. (certainly there are some, like more commands within one line) Unfortunalety my PC can speed up the Plus4emu only up to 1300%.
UPDATE Dec 8: -I used Austrospeed Compiler. We can do a benchmark with XC-BASIC then :-) -I forgot to mention the original color setup was not correct, so it had a lot of attribute clash. Not in the code below. Below you can see the proper adjusted colors, as planned by the original author. I think it makes more sense (shade) -I suppose I should check green too :-) -The picture below was done with the below code after compiled by Austrospeed.
5 color0,1:color4,1:color1,8:graphic1,1 8 om=1:tw=2:tr=3:hl=0.5 10 spheres=tw:if spheres then dim c(spheres,tr):dim r(spheres):dim q(spheres) 20 for k=1 to spheres:read c(k,om),c(k,tw),c(k,tr),r:r(k)=r:q(k)=r*r:next k 30 data -0.3,-0.8,3,0.6 40 data 0.9,-1.1,2,0.2 45 mx=319:my=199:hx=160:hy=100: 50 for i=. to my:for j=. to mx 60 x=0.3:y=-0.5:z=0:dz=375: 70 dx=j-hx:dy=i-hy:dd=dx*dx+dy*dy+dz*dz 80 gosub 100:next:next 90 stop 100 n=y>=. or dy<=.:if not n then s=-y/dy 110 for k=1 to spheres 120 px=c(k,om)-x:py=c(k,tw)-y:pz=c(k,tr)-z 130 pp=px*px+py*py+pz*pz 140 sc=px*dx+py*dy+pz*dz 150 if sc<=. then goto 200 160 bb=sc*sc/dd 170 aa=q(k)-pp+bb 180 if aa<=. then goto 200 190 sc=(sqr(bb)-sqr(aa))/sqr(dd):if sc< s or n<. then n=k:s=sc 200 next 210 if n<. then return 220 dx=dx*s:dy=dy*s:dz=dz*s:dd=dd*s*s 230 x=x+dx:y=y+dy:z=z+dz 240 if n=. then goto 300 250 nx=x-c(n,om):ny=y-c(n,tw):nz=z-c(n,tr) 260 nn=nx*nx+ny*ny+nz*nz 270 l=2*(dx*nx+dy*ny+dz*nz)/nn 280 dx=dx-nx*l:dy=dy-ny*l:dz=dz-nz*l 290 goto 100 300 for k=1 to spheres 310 u=c(k,om)-x:v=c(k,tr)-z:if u*u+v*v<=q(k) then return 320 next 330 if (x-int(x)>hl)<>(z-int(z)>hl) then draw,j,i 340 return
|