Page 1 of 9
RayTracer Theory and Practice
Posted: Mon Jun 13, 2005 12:43 am
by Dreglor
Im, doing a bit of research into ray tracing in writing one eventually
i can at least try and write a pretty low quality raytracer using longs and floats

then later convert to double when 4.0 comes out.
so im kinda new on RayTracing and im just starting to grasp the idea so could you point me into any good papers code that would be helpsful
even writing a bit of code to help start it off

Posted: Mon Jun 13, 2005 6:23 am
by DarkDragon
In the german forum NicTheQuick has made the best Raytracing results. Then there's Deeem2031 and me.
Here is the Topic:
http://forums.purebasic.com/german/viewtopic.php?t=3505
It's about realtime Raytracing with Adaptive Subsampling. NicTheQuick works on it right now, I have no time and I don't know how it is about deeem.
Uhm and here a useful link:
http://www.demoscene.hu/~picard/h7/subs ... ample.html
[EDIT]
VERY SHORT Explanation:
We send our rays from the screen out to the world and check if it collides with objects. If yes we draw the pixel on our screen. If not: we don't do so.
In my example you can see the tracemap and manipulate the adaptive subsampling through key 1, 2, 3, (maybe implemented) 4
Posted: Mon Jun 13, 2005 6:33 am
by Dreglor
I been Looking around and i found some sources for ray tracers (in c++) but i find it difficult to convert it
i know of a raytracer called realstorm
http://www.realstorm.com/
cheack it out it very fast compared to that ray tracer.
the problem i have under standing the core of ray tracing mathimaticly
Posted: Mon Jun 13, 2005 10:16 am
by Num3
Posted: Mon Jun 13, 2005 10:52 am
by thefool
eh is that raytracing??
edit:
@num3: you are talking about raycasting, wich is NOT the same

try a search on google.
Posted: Mon Jun 13, 2005 11:29 am
by dagcrack
Posted: Mon Jun 13, 2005 11:55 am
by Num3
thefool wrote:eh is that raytracing??
edit:
@num3: you are talking about raycasting, wich is NOT the same

try a search on google.
DOH !

Posted: Mon Jun 13, 2005 12:07 pm
by dagcrack
noo that reminds me I forgot to watch the simpsons today!!

Posted: Mon Jun 13, 2005 8:27 pm
by Trond
VERY SHORT Explanation:
We send our rays from the screen out to the world and check if it collides with objects. If yes we draw the pixel on our screen. If not: we don't do so.
Why isn't raytracing and raycasting the same?
Raytracing: You send rays from the screen and trace them "backwards" towards objects and light sources.
Raycasting: You cast rays from the screen and trace them backwards towards objects and light sources.
????????? What I am doing wrong??
Posted: Mon Jun 13, 2005 9:04 pm
by yashaa
Raycasting is more "simpler" while raytracing considers a lot of variables (i.e. type of material, lights attributes), and the ray bouces in many ways too...
Instead, raycasting draws many rays just to see if a certain object (i.e. wall) can be seen (drawn) from the player point of view...
I M H O
Posted: Mon Jun 13, 2005 9:16 pm
by GedB
Posted: Tue Jun 14, 2005 1:26 am
by Dreglor
So is there any pb sources with ray tracing in them and not the ray casting
Posted: Tue Jun 14, 2005 8:55 am
by Blade
Never seen a PB example, but just googled "simple raytracing" and found this:
http://wiki.tcl.tk/10857
seems pretty easy to convert too. (see the "mathematical details" for a scaring explaination

)
Otherwise search for the freeware (and poweful) POV raytracer sources. Expect a huge and complex C code...
http://www.povray.org
Posted: Tue Jun 14, 2005 2:47 pm
by Dreglor
hmm well at least its a small example
that i can at least understand
and the mathicmatical details provide a better explaination than most sites
Posted: Mon Jun 20, 2005 7:12 am
by Dreglor
Hmm, i tried 2 examples from
http://wiki.tcl.tk/10857 and
http://www.devmaster.net/articles/raytracing/
Both were failing to work
here is some code that i have that i did from the devmaster tutorial
Code: Select all
#ScreenWidth=320
#ScreenHieght=240
#Tolarance=0.0001
Structure xyz
x.f
y.f
z.f
EndStructure
Structure Sphere
center.xyz
radius.f
EndStructure
Procedure VectorNormalize(*this.xyz)
m.f = Sqr(*this\x * *this\x + *this\y * *this\y + *this\z * *this\z)
If m < =#Tolarance
m = 1
EndIf
*this\x = *this\x / m
*this\y = *this\y / m
*this\z = *this\z / m
If *this\x < #Tolarance
*this\x = 0
EndIf
If *this\y < #Tolarance
*this\y = 0
EndIf
If *this\z < #Tolarance
*this\z = 0
EndIf
EndProcedure
Procedure.f TestSphere(*Direction.xyz,*Origin.xyz,*Sphere.Sphere)
dirx=*Direction\x
diry=*Direction\y
dirz=*Direction\z
Originx=*Origin\x
Originy=*Origin\y
Originz=*Origin\z
Spherex=*Sphere\center\x
Spherey=*Sphere\center\y
Spherez=*Sphere\center\z
;a.f=Pow(*Direction\x,2)+Pow(*Direction\y,2)+Pow(*Direction\z,2)
;b.f=2*(*Direction\x*(*Origin\x-*Sphere\center\x)+*Direction\y*(*Origin\y-*Sphere\center\y)+*Direction\z*(*Origin\z-*Sphere\center\z))
;c.f=Pow(*Origin\x-*Sphere\center\x,2)+Pow(*Origin\y-*Sphere\center\y,2)+Pow(*Origin\z-*Sphere\center\z,2)
a.f=Pow(dirx,2)+Pow(diry,2)+Pow(dirz,2)
b.f=2*(dirx*(Originx-Spherex)+diry*(Originy-Spherey)+dirz*(Originz-Spherez))
c.f=Pow(Originx-Spherex,2)+Pow(Originy-Spherey,2)+Pow(Originz-Spherez,2)
D.f=Pow(b,2)-4*a*c
If D>0 ;hit the sphere
t.f=(-b-Sqr(D))/(2*a)
ElseIf D=0 ;glazing the sphere
t.f=-1
ElseIf D<0 ;missed completely
t.f=-2
EndIf
ProcedureReturn t
EndProcedure
Origin.xyz
Direction.xyz
Test.Sphere
Origin\x=0
Origin\y=0
Origin\z=-256
InitSprite()
OpenWindow(0,0,0,#ScreenWidth,#ScreenHieght,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"Ray Test")
StartDrawing(WindowOutput())
Repeat
For y=-#ScreenHieght/2 To (#ScreenHieght/2)-1 Step 1
For x=-#ScreenWidth/2 To (#ScreenWidth/2)-1 Step 1
Direction\x=x
Direction\y=y
Direction\z=256
VectorNormalize(Direction)
t.f=TestSphere(Direction,Origin,Test)
If t>0
posx=x+(#ScreenWidth/2)
posy=y+(#ScreenHieght/2)
Plot(posx,posy,RGB(255,0,0))
ElseIf t=-1
posx=x+(#ScreenWidth/2)
posy=y+(#ScreenHieght/2)
Plot(posx,posy,RGB(0,255,0))
ElseIf t=-2
posx=x+(#ScreenWidth/2)
posy=y+(#ScreenHieght/2)
Plot(posx,posy,RGB(0,0,255))
Else
posx=x+(#ScreenWidth/2)
posy=y+(#ScreenHieght/2)
Plot(posx,posy,RGB(255,255,255))
EndIf
Next x
Next y
Until WindowEvent()=#PB_Event_CloseWindow
oddly window rendering gives a bit of the clear screen color o_O
anyways, most of the main code is from the document the vector procedure is from another program i did while back
the problem i see with the code is that radius it not account for in the equasion im wondering where does it go? the tutorial only has a small part at the end of the sphere intersection about it but thats for the normal but that is only for lighting calulcations.
the other tutoral with the code when i converted it returned "behind origin" which i thought i converted wrong, because the code is very odd
im wondering whats missing...
edit : changed the code to fix a few dumb problems but it still returns -2 (glazing the sphere) until the right side of the screen where it returns "missed completely"