Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Ray tracing problem; *changed the name when changing the subject*
Topic Started: Apr 18 2009, 03:04 PM (886 Views)
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
And here's a link to help understand his post: Link
Blog|EHS
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
!!-sorry! I was away while writing this-!

Sorry skarik, but this time you are wrong. My logic is fine, but my knowledge about vector and matrix is not that good (result=logic*knowledge). I just know how to solve some somple equations.

Here is the code again, but with some more explanations (based on my knowledge!):

Code:
 

n=ScreenCoordToVector(n,xx,yy,camera); //make a vector that's pointing at a pixel on screen
NormalizeVector(n); //I thought normalizing was necessary
raylo=CalculateVectorLongitude(n); //"splitting up" the vector to get the direction and position
rayla=CalculateVectorLatitude(n);
rayx=GetVector(n,1);
rayy=GetVector(n,2);
rayz=GetVector(n,3);


dist=CheckRayIntersection(all,rayx,rayy,rayz,raylo,rayla,0); //Here I'm using the data to make a collition test (was in a hurry last time and didn't change the code back after an experiment)
if dist<100000 //check if there was a hit
{
cr+=1; //adding colors to pixel (not relevant)
cg+=1;
cb+=1;
l+=1;//adding light (not relevant)

GetRayTracingNormal(n);
//getting the values for normal of the face where the hit took place (position and direction)
rayx=GetVector(n,1);
rayy=GetVector(n,2);
rayz=GetVector(n,3);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);

succes=1;
}
else
{
//fail :(
succes=0;
}

//and then it start all over again with a similar code


I hope this was clear enough.

I think, by the way, that I have to read a little more about vectors...
Edited by Ogeon, Apr 19 2009, 09:51 PM.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
Ah fiddlesticks.

I guess it's time for me to make like a tree and get the hell out of here.
Blog|EHS
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
According to the variable n: n=-1 at creation of the tracer object, so I made no wrong there I just recycle the index.

EDIT: This topic became a little messy...
Edited by Ogeon, Apr 19 2009, 09:54 PM.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
You really should read my previous post (it's on page 1) ;) .

Anyway, here's how I would go about it. Make 2 scripts; one starts the ray tracing from the camera and calls the 2nd script, which traces recursively.

Here's the first script:
Code:
 
//Trace()
var raylo,rayla,dist;

ScreenCoordToVector(n,mouse_x,mouse_y,0);
NormalizeVector(n);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);

with (camera)
dist=CheckRayIntersection(all,x,y,z+height,raylo,rayla,0);

if (dist > 90000) exit;

var rayx,rayy,rayz;

CalculateVectorScalarProduct(n,n,dist);
rayx=GetVector(n,1)+camera.x;
rayy=GetVector(n,2)+camera.y;
rayz=GetVector(n,3)+camera.z+camera.height;
GetRayTracingNormal(n);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);

TraceRecursively(rayx,rayy,rayz,raylo,rayla);

And here's the recursive script:
Code:
 
//TraceRecursively(RayX,RayY,RayZ,RayLongitude,RayLatitude)
var dist;

CreateDirectionVector(n,argument3,argument4);

dist=CheckRayIntersection
(
all,
argument0,argument1,argument2,
argument3,argument4,0
);

if (dist > 90000) exit;

var rayx,rayy,rayz,raylo,rayla;

CalculateVectorScalarProduct(n,n,dist);
rayx=GetVector(n,1)+argument0;
rayy=GetVector(n,2)+argument1;
rayz=GetVector(n,3)+argument2;
GetRayTracingNormal(n);
raylo=CalculateVectorLongitude(n);
rayla=CalculateVectorLatitude(n);

TraceRecursively(rayx,rayy,rayz,raylo,rayla);

Sorry for the lack of comments, but it was done in a hurry :D .
Edited by MysteriXYZ, Apr 19 2009, 10:49 PM.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
Thank you MysteriXYZ! I will study your code and see if I can make this work. It was just as I thought it to be (in general), but I used the functions in the wrong way. Instead of recursive tracing where the script tells when to stop I will use a max depth to tell the ray how far to go, but it will be quite similar. Otherwise it may bounce around for ever. I will also use a difuse bounce where I make the ray leave the surface in a random direction (180 deg). May I use this method for it or will it be wrong?
Code:
 

raylo=CalculateVectorLongitude(n)-90+random(180);
rayla=CalculateVectorLatitude(n)-90+random(180);


EDIT: I changed the code above. It was a little wrong... better now.
Edited by Ogeon, Apr 20 2009, 04:47 PM.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Ogeon
Apr 20 2009, 04:29 PM
Instead of recursive tracing where the script tells when to stop I will use a max depth to tell the ray how far to go, but it will be quite similar. Otherwise it may bounce around for ever.
Yeah you're right, good point :D .

Quote:
 
I will also use a difuse bounce where I make the ray leave the surface in a random direction (180 deg). May I use this method for it or will it be wrong?
Code:
 

raylo=CalculateVectorLongitude(n)-90+random(180);
rayla=CalculateVectorLatitude(n)-90+random(180);
Simple adding to the existing longitude & latitude won't work, if you want to keep the direction within the same half-space defined by the plane that the normal is perpendicular to.
Try to visualize this in a modelling program, or using a pencil (normal) sticking out through a piece of cardboard (plane). As an example, if the plane is at a 45 degrees angle with a horizontal plane, let's say that the normal is pointing downwards (also at an angle of 45 degrees). If you add -90 degrees to the longitude of the normal, it lies in the plane and points upwards. If you then rotate the normal around the Z-axis, it will always end up at the other side of the plane.

So there's only one way to do it correctly, and that's by using... (I can hear everybody shout) ...matrices :D .

A single matrix can be used to describe the random rotation offsets, but because of the order of rotations (first rotz, then rotx and finally roty), they will be performed relative to a direction pointing to the right (positive X-axis).

To see this, just take a pencil and point it to the right. Now when you rotate it around the Y-axis (rotz), it's enough to limit that angle to the [-90,+90] range to keep the pencil from pointing to the left, no matter what angle you use to rotate it around the X-axis (rotx) after that.
That's great, but since you want these rotations relative to the positive Y-axis (whose rotx=roty=rotz=0), you still need to rotate the pencil -90 degrees around the Z-axis (roty). This compensates for having rotated the pencil from its default forwards direction by 90 degrees to the right at the start.

Knowing all that, you should be able to make sense of the following code:
Code:
 
//because of the order of rotations (first rotz, then rotx and roty last),
//creating a 3D rotation offset can be done with a single rotation matrix,
//but relative to the positive X-axis;

//first create a rotation matrix that describes a direction to the right,...
CreateRotationMatrix(dirmatr,0,90,0);

//...then another one that first performs a random rotation around
//the Y-axis, then a random rotation around the X-axis, and finally a
//rotation to the left (around the Z-axis) to compensate for the initial
//rotation to the right;...
CreateRotationMatrix(rotmatr,random(180)-90,-90,random(180)-90);

//...transform the first with the second, resulting in an offset rotation...
//(new_direction-to-normal)
TransformMatrix(rotmatr,dirmatr,rotmatr);

//...that needs to be transformed with the original direction...
//(new_direction-to-normal * normal-to-world...)
CreateRotationMatrix(dirmatr,raylo,rayla,0);

//...to obtain the final direction...
//(...=new_direction-to-world)
TransformMatrix(dirmatr,rotmatr,dirmatr);

//...which can be retrieved as a vector...
ComputeMatrixRotationAngles(n,dirmatr);

//...that contains the new longitude & latitude
raylo=GetVector(n,1);
rayla=GetVector(n,2);
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
Great thanks for your help! :mad: I actually got it to work and I got an image. I have converted it to png and attached it to this post for you.

The strange thing is circles of light and dark that seem to come from the center of the picture. They may dissappear later, but I don't know... :ermm:
Attached to this post:
Attachments: render.png (137.72 KB)
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
Ooh.

How long did it take to render that frame?
(also, what cpu do you have)


그대를 사랑해


Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
Ogeon
Apr 22 2009, 07:41 PM
The strange thing is circles of light and dark that seem to come from the center of the picture.
That's the awesomeness radiating from your render :ph43r: !

Seriously though, it could be related to rounding errors. It seems to depend on the angle of the surface to the camera, as I only see this effect on the floor object.


Very interesting image :) .
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
@ashrat3000: I don't really know... I was away when I rendered it, but the fps was about 1-4 (even smaller) and my cpu is a dual-core 1.9 GHz (just a little laptop).

@MysteriXYZ: They look like their brightnes is a sawtooth formation or a tan() function. They are getting lighter and lighter and then suddenly drop down to dark. You can see a strange "shadow" at the block behind the wall and the same kind of shadow at the floor. The wall is allso brighter at the center. I will make some changes in the code and do an other render.
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
If only we could get the color of a model's texture at a point...


그대를 사랑해


Offline Profile Quote Post Goto Top
 
skarik
Member Avatar
kitten eating scum
[ *  *  *  *  *  * ]
ashrat3000
Apr 25 2009, 01:29 AM
If only we could get the color of a model's texture at a point...


Damn. Use a DLL. Seriously. It's not that hard.
Blog|EHS
Offline Profile Quote Post Goto Top
 
ashrat3000
Member Avatar
u3d raytracer
[ *  *  *  *  *  * ]
skarik
Apr 25 2009, 01:38 AM
ashrat3000
Apr 25 2009, 01:29 AM
If only we could get the color of a model's texture at a point...


Damn. Use a DLL. Seriously. It's not that hard.
Actually, I forgot about dlls completely.

-goes off to do indirect illumination in u3d-
그대를 사랑해


Offline Profile Quote Post Goto Top
 
Ogeon
Member Avatar
Member
[ *  * ]
ashrat3000
 
If only we could get the color of a model's texture at a point...
It would be cool, but it sounds quite demanding... :unsure:

@skarik: I don't know if you remember it, but this is just a stupid experiment made for fun. ^_^ This will not be as powerful as Yaf(a)ray or any other big render engine. I'm actually quite impressed by it's performance right now. I thought it would have to go for ever to produce such an image as the one I posted before... But this doesn't make it a bad idea.

@All others: I have improved it a little and made it scan the image at first and see where it will find objects and then it will skip the parts where it doesn't find anything. I did allso invent some kind of rough anti aliasing by ofseting the pixels by +-0.5 (randomly). I will allso make it suport non glowing objects and colors.

I made it render a new verson of the first image and an other with it's new functions enabled. In The first you can see those circles at the floor and the shadow at the block and the shadow appears at the secont image too.
Attached to this post:
Attachments: render2.png (160.24 KB)
Attachments: render3.png (67.97 KB)
Do you expect a signature? Forget it!
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply