• Welcome to Dark Bit Factory & Gravity.
 

Raytracer :) [Update : objs/triangles make me mad]

Started by Hezad, August 16, 2009

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Jim

In your Plane Intersection you need to be more careful when the 'denom' part of the calculation is 0 (division by 0) or very near to 0 (numeric overflow).  Better to ensure the intersection actually happens before working out the intersection point.

Jim
Challenge Trophies Won:

ferris

http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Hezad

Jim > Yep I forgot this case ! Thanks a lot for pointing this :) 'just updated the code. Anyway, the glitch is stil here. Just for information, I will post 2 screens to show the bug (on the first screen, there is a plane at x=-5 and on the second screen, a plane at y=10, whatever is the sense of the normal. the last screen is the normal scene with only one plane at y=-5)

Ferris > Thanks !  :D
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

va!n

@Hezad:
New screenshots are amazing! Hoewever i have possible some nice / interesting links for you:

http://fuzzyphoton.tripod.com/howtowrt.htm

Esp following link seems to be very usefull - its from 2004 and shows how to code realtime raytracer... exe and source available...

http://homepages.paradise.net.nz/nickamy/raytracer/raytracer.htm
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Hezad

Very very interresting links, thanks Vain !
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Hezad

#25
Erm.. Okay, I need help (again..)

I spent days to search where the glitch come from ... I have a problem with my plane intersection routine (or plane normal maybe ? I don't know..).

The point is some planes are ok but some others are rendered very weirdly : It looks like the raytracer doesn't find the closest point on SOME PART of thoses planes (and not all the plane ..) The first image posted is the one with the "ok-planes". The second one is with a plane added on the right side of the image (I don't show you when I put a plane behind the objects .. it's awful).

Here is the "plane part" of the GetNormal and GetIntersection functions :

GetNormal :
normal = -sgn(dot(type<vector>(this.A,this.B,this.C),CRay.d))*type<vector>(this.A,this.B,this.C)

return normal

(the sgn(...) is to ensure the normal faces the ray direction, without it, it's worse)

GetIntersection :
dim as single tempT, num, denum

num = -(A*CRay.O.x+B*CRay.O.y+C*CRay.O.z)+D
denum = (A*CRay.d.x + B*CRay.d.y + C*CRay.d.z)

if ((denum<.0001) and (denum>-.0001)) then return 0
if ((num<.0001) and (num>-.0001)) then return 0

TempT = num/denum

if TempT < 0 then
return 0
else
returnT = TempT
return 1
End if


I tried a LOT of different ways to get the plane intersection (algebric, geometric, Vectorial eq..) but the glitch is always *almost* the same. Bis repetitam about GetNormal().

I also looked in the " Closest Point in the Closest Primitive finding " part of the tracer but I don't see where it could bug. Anyway, here is that part :


dim as single calcT=100000000, oldCalcT
intersectedprimitive = -1

For k as integer = 0 to Scene.nb_primitives-1

oldCalcT=calcT

if Scene.s_primitive[k].GetIntersection(MainRay, calcT) then
if CalcT<=oldCalcT then
MainRay.Update(calcT)
IntersectedPrimitive = k
end if
End If
next


If someone gets the problem here, he will avoid me to pull out more hair and will have my eternal gratitude  ;)

Attached :
1) no bug screen
2) buggy screen
3) the source used for the screenshots


Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Jim

if ((num<.0001) and (num>-.0001)) then return 0
I don't understand what this is for.

if (denum == 0) then plane is parallel to the ray and there's no intersecion
if (denum < 0) then the plane faces away from the ray
if (num/denum < 0) then the intersection is behind the origin

Check that both your normal and your ray are unit vectors.

Jim

Challenge Trophies Won:

Hezad

Thanks for your answer Jim :)

if ((num<.0001) and (num>-.0001)) then return 0

I don't understand what this is for.

if (denum == 0) then plane is parallel to the ray and there's no intersecion
if (denum < 0) then the plane faces away from the ray
if (num/denum < 0) then the intersection is behind the origin


Well because I thought num would never equal 0 but would approach it a lot. So I compare between very small values instead of comparing with 0. But maybe it's useless :P

Check that both your normal and your ray are unit vectors.
Checked several times, but checked again and yep, they are unit vectors :S
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Hezad

Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

TinDragon

Image looks fantastic to me, but I am a sucker for these simple raytraced scene's of sphere's :)
I look forward to seeing how your progressing with this, are you going to add some form of texture mapping in ?

va!n

@Hezad:
Still following your progress and i must say, screens are really cool!

Does the links helped you a bit, to optimize calculation/rendering? ^^
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Jim

Quote
Quote

if ((num<.0001) and (num>-.0001)) then return 0

I don't understand what this is for.
Well because I thought num would never equal 0 but would approach it a lot. So I compare between very small values instead of comparing with 0. But maybe it's useless
I think num will be 0 when the eye lies on the plane.  It's not going to make the calc unstable, unlike when denum is at or near 0.

Good progress on the reflections :)

Jim
Challenge Trophies Won:

benny!

Screenshot / Progress are looking fabulous. Very good work, Hezad!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Shockwave

That image would make a great desktop background.
Shockwave ^ Codigos
Challenge Trophies Won:

Hezad

TinDragon > Thanks :D Yep texture mapping is planned (bumpmapping too :)). I'd like to work on procedural textures too, but I want to fix the plane problem before all that ;)

Va!n > Thanks ! The links didn't help yet, I haven't red everything, but i'm sure the source code will be useful when I'll seriously start the optimisation part ;)

Jim > You're right, I suppressed that comparison. Thanks :)

Benny, shockie > Thanks ! ;D
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

I for one would love to see that image rendered with the spheres closer to the camera and in 1024*768 resolution so I can have it on my desktop, especially with a red/blue and silver colour scheme :)
Shockwave ^ Codigos
Challenge Trophies Won:

Hezad

Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won:

Hezad

Thanks to you :) 'glad you liked it ^^

and now, an very very very very AWESOME new (at least for me :p) :


The "planes bug" IS SOLVED !!! oh gosh, i'm so glad  :updance: :updance: I spent the last week to verify my code and the bug was really .. stupid (my object sorting method was wrong).

There are still some things with the planes normal and the refraction calculus to verify but that would be a less motivation-collapsing task ;D A little screen (not really cute, but hey, the planes ARE WELL SORTED !!!)

Anyway, I guess you will understand with this post that I'M GLAD ! I'll post the updated source once the refraction and the the normals are okay :)
Music + Coding :
http://Hezad.no-ip.org

Hosting / Hébergement :
www.hezad.com

Shockwave

Shockwave ^ Codigos
Challenge Trophies Won: