Author Topic: Raytracer :) [Update : objs/triangles make me mad]  (Read 27975 times)

0 Members and 1 Guest are viewing this topic.

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Thanks :) Here is a buggy screen of some new wip features.

- Texture mapping ('still looking for the way to properly get UV coordinates on a triangle, as you can see on the screen :S)
- Triangles intersection
- bumpmapping (this one is funny :P)

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Looks stunning mate.

The balls almost look bump mapped too.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Quote
Looks stunning mate.
Thanks ;D

Quote
The balls almost look bump mapped too.
well.. They are  xD

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Very shiny.  :clap: 

The bump mapping on the spheres looks really good.

What else are you going to add to this ray tracer?
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Looks very cool, well done Hezad :)

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Raytraced reflections usually look very synthetic because in reality there are rarely perfect mirrors.
If you're having a closer look, all surface mirror to a tiny percentage. Due to the surface's roughness, rays reflected in different directions resulting in a blurry appearance of reflected objects - the further an object is away the blurrier it appears.
Here is a wooden floor for example.
« Last Edit: September 08, 2009 by hellfire »
Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Voltage > Thanks :D Well I'd like it to be able to load some 3D models basically (that's why i'm implementing triangles). In fact I'd like to have a perfectly working basic raytracer to experiment global illumination next.,

TinDragon > Thanks ! :)

hellfire > Yep diffuse reflections are planned ;) I'm just working on bugs before implementing new stuff. Thanks for the image, it's a very attractive one :P


thanks for your kind words everyone :)

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
For your uv calculation, do a Google search for Barycentric Coordinates.

Jim
Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Jim > Yep I'm already using barycentric coordinates to intersect the triangle :) 'just don't really know how to retrieve (u,v) texels from (a,b,c) weights.

hellfire > well you tempted me xD Here is a screen of triangles(walls) and diffuse reflection in action ;D

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Raytracer :) [Update : screens (diffuse reflection)]
« Reply #49 on: September 09, 2009 »
Delicious :)

Just imagine that without coder colours!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Raytracer :) [Update : screens (diffuse reflection)]
« Reply #50 on: September 09, 2009 »
Wow, that was very rapid prototyping :)
The reflected environment looks a bit motion-blurred (like it's moving rapidly), might be due to the spherical distortion or maybe the offset of your reflection-rays prefers a certain direction?

Challenge Trophies Won:

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: Raytracer :) [Update : screens (diffuse reflection)]
« Reply #51 on: September 10, 2009 »
shockie > Thanks ;D
Quote
coder colours!
xD !


hellfire >
thanks :) well for the offset, i'm using (the_reflection_ray_itself * a_very_little_number) but I agree, it looks like a cinematic blur .. I'll try to use the normal or the "basic" reflection ray for the offset

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: Raytracer :) [Update : screens (diffuse reflection)]
« Reply #52 on: September 13, 2009 »
Hey :) I'm working on an obj loader but the loaded objects are ... wrong lol The point is I don't know if the problem is in the obj file loader or in the triangle intersection part ... I checked a lot of stuff but nothing to do, I don't find the flaw !

Attached screen : The green stuff is supposed to be a dodecahedron ><

here is the obj loading part :
Code: [Select]
Function GetWord(stri as string, nb as integer) as string

dim as integer nbchr = len(stri), curspc=0
dim as string retstr=""

for i as integer = 1 to nbchr
if mid(stri,i,1) = " " or i=nbchr then
curspc += 1
if curspc = nb then return retstr
retstr = ""
else
retstr += mid(stri,i,1)
end if
next

return "ERROR"
End function

Sub SceneT.Load_OBJ(byval filen as string,byval Mat as MaterialT, P0 as vector = type(0,0,0), scale as vector = type(1,1,1) )

dim as integer ff = freefile, nbV=0,nbtriangles
dim as string linestr

dim as vector vertexlist(MAX_VERTICE)

Open filen for input as #ff
do
Line input #ff, linestr
select case left(linestr,1)
case "v"
'' add vertex
nbV += 1

vertexlist(nbV).x = val(GetWord(linestr,2))*scale.x + P0.x
vertexlist(nbV).y = val(GetWord(linestr,3))*scale.y + P0.y
vertexlist(nbV).z = val(GetWord(linestr,4))*scale.z + P0.z

case "f"
'' add triangles
this.Add_Triangle(vertexlist(val(GetWord(linestr,2))),vertexlist(val(GetWord(linestr,3))),vertexlist(val(GetWord(linestr,4))),Mat)

end select

Loop until eof(ff)
Close #ff
end sub

and the triangle intersection part :
Code: [Select]
dim as vector u, v, n, I
    dim as Vector d, w0, w
    dim as single r, a, b

u = This.p2 - this.p1
v = this.p3 - this.p1

n = u * v

if n.x=0 and n.y=0 and n.z=0 then return 0

d = CRay.d
w0 = CRay.O - this.p1

a = -dot(n,w0)
b = dot(n,d)
if (abs(b) < .00001) then return 0

r = a / b
if (r < 0) then return 0

I = CRay.O + r * d

dim as single uu, uv, vv, wu, wv, Det
uu = dot(u,u)
uv = dot(u,v)
vv = dot(v,v)
w = I - this.p1
wu = dot(w,u)
wv = dot(w,v)
Det = uv * uv - uu * vv

dim as single s, t, _D
_D = 1/Det

s = (uv * wv - vv * wu) * _D
if (s < 0.0 or s > 1.0) then return 0

t = (uv * wu - uu * wv) * _D
if (t < 0.0 or (s + t) > 1.0) then return 0

returnT = r
return 1

Okay, there's some code here, and I know it's not easy to get what's going on in a someone else's code .. But if anyone already had this kind of problem, or have any idea, don't hestitate ;D


nb : oh ! 'forgot to post the screenshot uhuh. thanks to clyde for pointing this out :)
« Last Edit: September 13, 2009 by Hezad »

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Offtopic: What's up with the screenshots?
« Reply #53 on: September 14, 2009 »
Sorry to interrupt, but all the screenshots are a bit out of place.
Is that just a problem for me?
(WinXP, Firefox 3.5.2)



Back on topic:
"f" can specify polygons with an arbitrary number of vertices.
Are you sure your .obj-file contains only triangles?

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #54 on: September 14, 2009 »
I think the loader isn't right.  Try a simpler object, such as, say, a triangle, and use Print or a debugger to check the numbers coming out of GetWord.

Jim
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #55 on: September 14, 2009 »
Quote
Sorry to interrupt, but all the screenshots are a bit out of place.
Is that just a problem for me?
(WinXP, Firefox 3.5.2)

Nobody else has said anything, I am running XP and FF 3.52 and don't get this problem.. I know that there are some problems with this theme that need fixing.

Is this the same for you in all topics?
Shockwave ^ Codigos
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #56 on: September 14, 2009 »
Quote
Is this the same for you in all topics?
It appears to work fine in other threads (eg here).
Looks the same in Chrome.
Challenge Trophies Won:

Offline TinDragon

  • Pentium
  • *****
  • Posts: 644
  • Karma: 24
    • View Profile
    • J2K's blog
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #57 on: September 14, 2009 »
I have had some of the pictures out of place but it seems to only happen on some posts, but not others. I am on vista with FF 3.52, i considered it probably just a glitch as now for example the thread looks fine

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #58 on: September 14, 2009 »
Thanks for your answers :)

Concerning the screenshot default, I had the same bug on someone else's thread but I don't remember which :S

Quote
"f" can specify polygons with an arbitrary number of vertices.
Are you sure your .obj-file contains only triangles?
Yep, I checked all my obj files, they only use triangles and use only the stuff I'm loading (vertices/faces information)


Quote
I think the loader isn't right.  Try a simpler object, such as, say, a triangle, and use Print or a debugger to check the numbers coming out of GetWord.

I checked the GetWord function in a standalone code and it worked very well (I tried stuff like print GetWord("v 1 0.34534 34034",2) and it returned "1" well)
But, I didn't even thought about editing my own obj file with only one or two triangles >< *me stupid* I'll try that !

Thanks everyone for your answers, I'll try to edit a simpler object file to test it :)

Offline Hezad

  • Sponsor
  • Pentium
  • *******
  • Posts: 613
  • Karma: 44
  • I believe .. in Patrick.
    • View Profile
    • Hezad.com Web hosting
Re: Raytracer :) [Update : objs/triangles make me mad]
« Reply #59 on: September 15, 2009 »
Okay, my researches drive me here :

This obj file is rendered OK :
Code: [Select]
v -3 0 0
v -2 0 0
v -1 1 0

f 1 2 3

but this one cuts the right side of the triangle :
Code: [Select]
v -1 0 0
v 1 0 0
v 0 1 0

f 1 2 3

In fact, it seems like it bugs when some coordinates are the opposite sign of some others (eg : x1 = -1,x2=0, x3=1) while it works if all coordinates are the same sign ...

But the bug shouldn't be in the triangle intersection since the background wall is rendered correctly (it has some x coords = -4 and some others = 4)

hum.. right now I really don't understand :S

BTW, there was actually a bug in the GetWord() function but resolving it didn't changed the behavior of the loader ...