Page 6 of 9

Posted: Wed Jul 20, 2005 10:26 pm
by Dreglor
i did its above the picture :lol:

Posted: Wed Jul 20, 2005 10:46 pm
by Hades
Hm... but you must have inserted more than the last two snippets of code.

Ok, I try to get it working. :D

Edit: Now THIS is very strange! I inserted the first hit part and everything was fine. I inserted the shadow part, and it was working. But only one time! after that it crashed, even after I deleted the shadow code again. Then I got it back in and the first hit test out, and at least it doesn't crash anymore. :?

I hate it when this happens...

Posted: Thu Jul 21, 2005 12:29 am
by Dreglor
hmm it sounds a pointer problem maybe with the setting of object address :\

Posted: Thu Jul 21, 2005 12:40 am
by Hades
Solved ! :D

Yes, first I had a problem with the address, because I don't really understand what your program does. :wink:

After that was solved I saw your real problem. :shock:

It seems to be a PB-Bug.
Remove every Value after ProcedureReturn in the Test... Procedures. They seem to have sideeffects, even if you don't use them.

After that everythings fine. :D :D


Edit:
Funny... leaving a Procedure without ProcedureReturn is slower. Strange things happen here. :)

Is there a reason for the constants 2, 4, 0.5 in the TestSphere math (Could be, I'm not sure)? But without them the scene looks the same.

Code: Select all

Procedure TestSphere(*Origin.xyz,*Direction.xyz,*Sphere.Object,*result.IntersectReturn)
  ; stime.l=ElapsedMilliseconds()
  ; Debug "Entering TestSphere() With"+Hex(*Origin)+", "+Hex(*Direction)+", "+Hex(*Sphere)
  *result\result=#Miss
  offset.xyz
  offset\x=*Origin\x-*Sphere\Origin\x
  offset\y=*Origin\y-*Sphere\Origin\y
  offset\z=*Origin\z-*Sphere\Origin\z
  radius.f = PeekF(*Sphere\Primitive)
  b.f = (*Direction\x * offset\x + *Direction\y * offset\y + *Direction\z * offset\z)
  c.f = (offset\x * offset\x + offset\y * offset\y + offset\z * offset\z) - radius * radius
  d.f = b * b - c
  If d > 0 ;hit the sphere
    d=Sqr(d)
    t1.f = (-b - d) ; Could return +ve or -ve number!
    t2.f = (-b + d) ; Could return +ve or -ve number!
    If t2>0
      If t1<0
        *result\t=t2
        *result\result=#InPrimitive
        ProcedureReturn
      Else
        *result\t=t1
        *result\result=#Hit
        ProcedureReturn
      EndIf
    EndIf
  EndIf
  ; Debug "Leaving TestSphere() With"+StrF(t)
  ; etime.l=ElapsedMilliseconds()
  ; LastProcedureTime=etime-stime
  ProcedureReturn
EndProcedure
For primary rays ( form the origin ) it could be:

Code: Select all

Procedure TestSpherePrimary(*Origin.xyz,*Direction.xyz,*Sphere.Object,*result.IntersectReturn)
  ; stime.l=ElapsedMilliseconds()
  ; Debug "Entering TestSphere() With"+Hex(*Origin)+", "+Hex(*Direction)+", "+Hex(*Sphere)
  *result\result=#Miss
  offset.xyz
  offset\x=*Origin\x-*Sphere\Origin\x
  offset\y=*Origin\y-*Sphere\Origin\y
  offset\z=*Origin\z-*Sphere\Origin\z
  b.f = (*Direction\x * offset\x + *Direction\y * offset\y + *Direction\z * offset\z)
  c.f = PeekF(*Sphere\Primitive+4) ; calculated per frame
  d.f = b * b - c
  If d > 0 ;hit the sphere
    d=Sqr(d)
    t1.f = (-b - d) ; Could return +ve or -ve number!
    t2.f = (-b + d) ; Could return +ve or -ve number!
    If t2>0
      If t1<0
        *result\t=t2
        *result\result=#InPrimitive
        ProcedureReturn
      Else
        *result\t=t1
        *result\result=#Hit
        ProcedureReturn
      EndIf
    EndIf
  EndIf
  ; Debug "Leaving TestSphere() With"+StrF(t)
  ; etime.l=ElapsedMilliseconds()
  ; LastProcedureTime=etime-stime
  ProcedureReturn
EndProcedure
And for shadow testing it could be:

Code: Select all

Procedure TestSphereShadow(*Origin.xyz,*Direction.xyz,*Sphere.Object,*result.IntersectReturn)
  ; stime.l=ElapsedMilliseconds()
  ; Debug "Entering TestSphere() With"+Hex(*Origin)+", "+Hex(*Direction)+", "+Hex(*Sphere)
  *result\result=#Miss
  offset.xyz
  offset\x=*Origin\x-*Sphere\Origin\x
  offset\y=*Origin\y-*Sphere\Origin\y
  offset\z=*Origin\z-*Sphere\Origin\z
  radius.f = PeekF(*Sphere\Primitive)
  b.f = (*Direction\x * offset\x + *Direction\y * offset\y + *Direction\z * offset\z)
  c.f = (offset\x * offset\x + offset\y * offset\y + offset\z * offset\z) - radius * radius
  d.f = b * b - c
  If d > 0 ;hit the sphere
    *result\result=#Hit
  EndIf
  ; Debug "Leaving TestSphere() With"+StrF(t)
  ; etime.l=ElapsedMilliseconds()
  ; LastProcedureTime=etime-stime
  ProcedureReturn
EndProcedure
[/code]

Posted: Thu Jul 21, 2005 8:44 am
by Dreglor
wtf how the does that work!
you changed the quadatic formula and it works still :shock:

i did that and the spheres when crazy
the only diffrence is that you got a procedure return on the bottem :?

well im going to think about this while im gone for the 3 days
and also when i get back im going to finish the Obj loader i started and implement textures the right way...

while I away hades (and every one if they want), you can hack away at the latest snapshot i've uploaded

right now it under 2 seconds lets see if we can get it under 1 second (if thats possible with the current algothim :lol: )

in the near future i want to get my mind around how to transform the camera so the rays aren't spawing from one angle and one origin
althought we can move around its a little slow and you can't change the view angle

if you guys can point me to a few documents on this i be glade to make this my next addition :)

heres the source >>PBRay7-21-05.zip<<
Image


and heres a pic showing off textured triangles :D
Image

Posted: Thu Jul 21, 2005 10:32 am
by Hades
For me your last posted code takes 1156ms - 1172ms without any changes.

When rendering to screen and with ProcedureReturn and the TestSphere code I posted the lowest time was 1016ms (damn, that close :D ).

(With the TestSphereShadow code it was slower :? . Maybe an alignment or cache problem ?)

Optimizer also didn't help. :cry:

Have to check what's going on there...

Edit:
968ms

- In Object Structure all .b variables moved to the end of the structure.

- Instead of :
If IntersectionResults\result = #Hit or IntersectionResults\result = #InPrimitive
now :
If IntersectionResults\result<>#Miss

- Instead of :
Closest\t=-1.0
...
If IntersectionResults\t<Closest\t or Closest\t=-1
now:
Closest\t=10000000.0
...
If IntersectionResults\t<Closest\t

Athlon64 3200+ @2,5GHz, 1GByte, Radeon 9700 Pro

Posted: Sun Jul 24, 2005 3:21 am
by Dreglor
well i got back a little faster that I figured.

i did some coding last night as i was here,
finished the wavefront obj loader and now i can load some big models i convert from other formats (as i can't seam to find models in that particular format)

no new screen shot becasue i tried rendering a big model (2000+ trianlges) it took more than a hour to render so i cut it that

the only thing i could render in a resable time was a single triangle which work prefectly and a cube which didn't...
somthing not tottally right with the normals the cube whent black and took 11 seconds to render...

the upload i have here does have some of the modeles that were only used to verify the loaded and were not used in redering theres 2 big models i included a "creature" which has ~10,000 triangles on it and isn't somthing we should be rendering anytime soon ;)
theres a knot model that has 2600 triangles in it

>>PBRay7-23-05.zip<<
Image

edit : also im trying to do a bit opmtization using asm (not in the download). i was looking into a fast way to do a vector normilize and i found this

Code: Select all

struct cVector
{
	float x,y,z,w;
};

void main()
{
	cVector vec1;
	vec1.x=0.5;
	vec1.y=1.5;
	vec1.z=-3.141;
	vec1.w=0;

	__asm {
		movups xmm0, vec1
		movaps xmm2, xmm0
		mulps xmm0, xmm0
		movaps xmm1, xmm0
		shufps xmm0, xmm1, 0x4e
		addps xmm0, xmm1
		movaps xmm1, xmm0
		shufps xmm1, xmm1, 0x11
		addps xmm0, xmm1
		rsqrtps xmm0, xmm0 
		mulps xmm2, xmm0
		movups vec1, xmm2
	}
		
	cout << vec1.x << " " << vec1.y << " " << vec1.z << " " << vec1.w << '\n';
}
its C++
im not sure how it goes in becasue the asm keywords aren't being highlighted when i paste it in

Posted: Sun Jul 24, 2005 8:45 am
by Hades
That's SSE. PB IDE doesn't recognize it, but FAsm does, so no problem. :)
In PB it should look like this :

Code: Select all

Procedure.b VectorNormalizeSSE(*this.xyz) ; SSE Version
  !MOV  dword Eax,[Esp] 
  !movups xmm0, [Eax] 
  !movaps xmm2, xmm0 
  !mulps xmm0, xmm0 
  !movaps xmm1, xmm0 
  !shufps xmm0, xmm1, 0x4e 
  !addps xmm0, xmm1 
  !movaps xmm1, xmm0 
  !shufps xmm1, xmm1, 0x11 
  !addps xmm0, xmm1 
  !rsqrtps xmm0, xmm0 
  !mulps xmm2, xmm0 
  !movups [Eax], xmm2  
EndProcedure
BUT... You have to change your Vertex format from xyz to xyzw (put another floating point number at the end of your structure).
I didn't test it, because you have to change all your mem copy where you used constants.


With your OBJ loader you have nearly lost me. :?
Seems to me you first load vertex indices and then texture indices into the same slot.
But I may be wrong, my had is aching from that stuff. :roll:

Posted: Sun Jul 24, 2005 9:09 am
by Dreglor
oh.. thanks maybe i look up more in asm maybe do some more optimizations of my own that way
as the obj loader, yes im trying to becasue thats how the format goes

in the keyword f its arranged as such "f [vertex]\[texture]\[normal]

so they have to load the same slot
also it is becasue the textures will use the same index as the triangles

theres alot of branching here becuase the indices could be negitive telling me to use the last n vertex and also if the divider ("\") can be missing along with the data telling me only triangle face data

i don't use the normal becasue there not the type of normal i want there vertex normals insted of face normals

theres more info here http://astronomy.swin.edu.au/~pbourke/geomformats/obj/

Posted: Sun Jul 24, 2005 9:17 am
by Hades
Oh, your right. I missread your code. I thought you are overwriting something, but you don't.

At the moment I simply don't understand your obj loader fully. Maybe I try again later...

Posted: Sun Jul 24, 2005 9:41 am
by Dreglor
hmm maybe i should comment my code a little more
either that or write a big doc about raytracing in pb
(both of which i don't feel up to do)

Posted: Mon Jul 25, 2005 8:22 am
by Marcel
Should you not first write the Programm in easy readable Code until its ready with all features befor you use asm and hacks, which make the code unreadable? I think thats not so good for the developement!

I hope you did understand my bad englisch!

Posted: Mon Jul 25, 2005 3:52 pm
by Hades
@Marcel
Yes, your right.

@Dreglor
I didn't even know what your goal is. Do you want a perfect Raytracer that is extensible and able to render massive scenes with a good speed like OpenRT.
Or do you want something that is really fast and could turn into a game engine with a bit more computing power like RealStorm.
Or maybe something completely different?

Most optimizations work well for one case, but slow down the rendering in another case.
e.g.: If you have a few thousand primitives you should precompute as much as possible. But if you have some million, you probably precompute lots of primitives that are never hit by a ray, or only by one ray. Plus you have to load all the precomputed data, get lots of cache misses and in the end your scene takes much longer to render as without precomputing.
( That maybe isn't true for static Objects, but who knows... )

So, please make sure you know what you want, implement the best algorithm (you can find) for that case, and at the end check where the most of your time goes and try to turn that into assembly.

Unless you are sure you won't change it anymore, it just make no sense to turn it into assembly. :(

Posted: Mon Jul 25, 2005 6:38 pm
by Dreglor
right now my goal is real time once i get that im proably going to step off the develompent pedel some bit
most of my optimaztions are going towards things i use over and over alots of times and is part of the core that will be never dropped like some of the vector math

right now i can't do anything becasue im stuck with a problem with my microsoft windows installer where i can't install anything that uses it and that includes my video driver
so im stuck with only standard vga adpater at 640x480 mode and its almost imposible to write any code with out scolling so much

if you want to see the post on this its here
viewtopic.php?t=16036

Posted: Mon Jul 25, 2005 7:03 pm
by Hades
Uh, that sucks! :shock:

Do you use XP? Did you try SP2 then? Should give you a better video driver than VGA, and maybe even a working installer again.

I reinstall XP about once in a month. Just to have a clean, 'slim' system. :D

You should really think about reinstalling to. :wink: