RayTracer Theory and Practice

Everything else that doesn't fall into one of the other PB categories.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

RayTracer Theory and Practice

Post 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 :P 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 :)
~Dreglor
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post 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
bye,
Daniel
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
~Dreglor
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Try the wolfenstein source code :P

It's free now!

http://www.gamespp.com/sourcecode/wolfenstein.html
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

eh is that raytracing??

edit:
@num3: you are talking about raycasting, wich is NOT the same ;)
try a search on google.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:lol: :lol: :lol:
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post 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 !


Image
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

noo that reminds me I forgot to watch the simpsons today!! :x :cry:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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??
yashaa
User
User
Posts: 19
Joined: Sun Jun 12, 2005 8:19 pm

Post 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
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

So is there any pb sources with ray tracing in them and not the ray casting
~Dreglor
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post 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
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
~Dreglor
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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"
~Dreglor
Post Reply