Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   WIP: My Raytracer (https://simplymaya.com/forum/showthread.php?t=20118)

MattTheMan 03-02-2006 09:29 PM

WIP: My Raytracer
 
Ok, this is a work in progress. I am programming a raytracer in c++. I will post a first update tonight, with diffuse shading. I will be using two lights, and will mostly be working along with the method described at www.flipcode.com, an excellent tutorial for raytracer programming.

This will include diffuse lighting, reflections, phong effects, refractions, soft shadows, fixed grid spatial subdivisions, and diffuse reflections.

Then I will do some research and apply things like LDR Image Based lighting, Monte Carlo GI, caustics, and KD-Tree tracing algorithms. Finally, I will add skylights, object lights, and, possibly, polygon handling on basic things like cubes, cylinders, and spheres.

Also, I will be posting up sections of my code for help and stuff. I know a bunch of you peeps are programmers, so I can use the help (im 13 :p).

As for the algorithms, I will just be applying the best ones I find, since I have very little knowledge of linear algebra, and the only formula I know is the reflection one: R= V*2 - (V dotproduct N) * N

Alright, then, update tonight.

EDIT: I am biting off a heck of a lot more then I can chew. But I will not quit. I am not a quitter

cya later,
Matt :alien:

MattTheMan 04-02-2006 01:19 AM

Hmm.. seems VERY hard. I don't know where to start. It will be a while before my first update.

MattTheMan 04-02-2006 02:29 AM

1 Attachment(s)
Alright, I started coding. I'm doing this for all of the vector classes (no matrices yet) including ray, camera, and primitives.
also I have the color definition and the color on screen stuff done too
Here is what I am aiming for, as a first goal: this is done in Maya

a sphere, with diffuse shading.

edit\\ Alright, so I got some algorithms from the nice people at CGtalk.com, for normal calculating, and also I figured out my previos problem with the vector extrusion.

MattTheMan 09-02-2006 01:16 AM

1 Attachment(s)
Yay! I got some work done! Here is a screenshot (just some normal calculations)

MattTheMan 10-02-2006 02:43 AM

1 Attachment(s)
Hmmm... can't say I'm satisfied, this does work... but not so great.
It tests if a point is on a plane or not. I'm pretty sure this is wrong, I will try normalizing all vectors first, that might give me more accurate results, and I will post my results

MattTheMan 10-02-2006 02:57 AM

Yeeah... I will have to rewrite that code, its seriously f***ed up. I think it does sumthing much more advanced then what I want it to do :p, and takes it as not an infinite plane, but instead as a LINE between the two vectors(which its processing as points).

Oh, DUH!!!! I'm only taking into account the two vectors for the cross product for the normal! I'm using the WRONG PLANE EQUATION!!!! :headbang: will fix tomorrow....

MattTheMan 11-02-2006 07:50 PM

Alright, now everything, instead of working with a ton of floats, works with the typedef class

vector3d{
public: float x, float y, float z
};

And all of the funcs, instead of taking (example)

DOT(float ax, float ay, float az, float bx, float by, float bz)

it takes

DOT(vector3d V, vector3d, U).

This is a whole lot faster on me, like when I have the following function

RectAndL-Intersect(float ax, float ay, float az, float bx, float by, float bz, float cx, float cy, float cz, float dx, float dy, float dz, float testx, float testy, float testz)

Which took 15 float values. Instead, now it works like:

RectAndL-Intersect(point A, point B, point C, point D, point Test)

Still takes 15 float values, but they are stored inside 5 point values. Point values have

typdef class point{
public: float x, y, z;
};

Next up: Point-Plane tests, followed by Ray-Plane intersection tests, my first intersection tests!

Cya Later Peeps,
Matt :alien:
Update soon.

Tim_LIVID 11-02-2006 08:59 PM

I can appreciate the skill that is involved but I have to ask the question ... why are you doing this?

It seams a case of reinventing the wheel.

MattTheMan 11-02-2006 09:41 PM

Yeah... see this is in the programming TO DO list on everyone that's learning c++. It gives a fine grasp of c++, using all of its functions, as well as giving the programmer more of an understanding of linear algebra.

In most programming courses at uinversities or colleges, programming a raytracer is something that they have to do, and often its within the first month or two of class.

So, basically, I want to understand c++ and linear algebra/vector calculus better, and also, I find it kinda fun, doing this reinventing the wheel thing. :p

Update to come... my point-plane function is saying everything is on a plane :(

cya later,
Matt :alien:

MattTheMan 11-02-2006 10:08 PM

1 Attachment(s)
It works! So happy :attn: :attn: !
I won't test it in too many directions, because I can't calculate that much in my head to verify if its right or wrong.

Also, at first, all I will use this for will be directly on an axis, and first as an infinite ground plane.

Next up: Ray-Plane intersection tests!

MattTheMan 12-02-2006 12:30 AM

1 Attachment(s)
OH! OH YEAH! Take a look at the following tightness! I'm on a roll!:attn: :attn:

Tim_LIVID 12-02-2006 10:41 AM

I'm sorry, I use to be a programmer years ago but this means nothing to me. I'm sure it's very good.

Maybe when you have finished it you could upload it and we could all give it a test.

MattTheMan 12-02-2006 03:32 PM

sure, yeah, but very soon I will have my first image, with a sphere and a plane

and of course I will upload it here

\\edit The ray-plane intersection right now can tell if the ray really hits, like a car going foreward and hitting a truck, or if it is just Not Paralell to the plane, but really doesn't intersect the plane in the direction it was going.

MattTheMan 12-02-2006 09:17 PM

1 Attachment(s)
update - the pic explains itslef

magicsy 12-02-2006 09:24 PM

hey matt lost me with this one but i have a question for you, how come i never seem to see you working on anything. i apart from ure wacom u did i aint really seen any of ure work hope u start gettin some up in the Wip.

gster123 12-02-2006 09:25 PM

Your well gettin into hte programming!! Have you done much in MEL??

My C++ was object orientated where you used a blank form and created an interface using the different user imputed attributes to calcualte/look up values, Might try and get back into it using MEL

MattTheMan 12-02-2006 11:35 PM

thanks, and no, i dont know MEL

And magicsy, I have to finish this first, before realyl getting into maya/3ds max again

MattTheMan 13-02-2006 02:05 AM

1 Attachment(s)
Haha! Check dis out!:attn:

MattTheMan 17-02-2006 09:22 PM

1 Attachment(s)
And now it does collisions with spheres too.

MattTheMan 20-02-2006 12:31 AM

Ok, this is the last update before I can render out a picture.

I have a function that shoots 800 x 600 rays (480,000) tests them each against every primitive, finds a collision, gets the primitive color, and (very soon) will apply that color to a pixel.

I just need to find an easy to use graphics library for c++ and I'll show you. Then right after that I will add diffuse shading.

MattTheMan 25-02-2006 06:27 PM

1 Attachment(s)
MY FIRST IMAGE! YAY YAY YAY :attn: :attn:

its not much... but I know how to add diffuse shading, and it will happen a bit later today.

MattTheMan 25-02-2006 08:25 PM

1 Attachment(s)
And diffuse shading. Next up: reflections! :attn:

Tim_LIVID 25-02-2006 08:36 PM

Fast work there Matt

MattTheMan 25-02-2006 08:44 PM

1 Attachment(s)
thanks: and to show you that I added perspective (like, the farther an object is away from the camera, the smaller it appears) a while ago: here

I moved the sphere about 80 units away form the camera and about 30 units to the side

The bad quality is not my raytracer's fault, it is bad JPG compression that MS Paint does.

MattTheMan 26-02-2006 02:40 AM

1 Attachment(s)
And now: The plane reflects! In about 30 minutes, the sphere might reflect too!

and I have to say that it runs waaaaaaaaaaaaaay faster then the Maya Software Renderer. I acheived almost the exact same effect in Maya SR, and it took about 10 seconds to work.

Mine rendered in less then half a second.

MattTheMan 26-02-2006 03:26 PM

1 Attachment(s)
umm... I didnt add sphere reflections, though I have been working on it I have to restart it because it is seriously f***ed up

I added the characteristic that a reflective material adds its color onto the color of the reflected object

MattTheMan 26-02-2006 06:14 PM

1 Attachment(s)
before I make the spheres reflect, I decided to optimize my main rendering code and to add another sphere (so the sphere reflcetions look cooler)

Well, I could add as many primitives as I want now, but it took me a while to do...

I might make the light a white sphere, so you can see where it is.

I need to make the blue sphere reflect off of the plane though

MattTheMan 26-02-2006 06:54 PM

1 Attachment(s)
and the second sphere is reflected too

gster123 27-02-2006 06:01 PM

Cool work man, keep going!

Falott 27-02-2006 07:13 PM

respect mat!

if you are 13 and doin stuff like this now, you´ll earn a heck lot of money later in your life! keep it comin!

MattTheMan 27-02-2006 11:56 PM

thanks guys

i traced through my program and found that my sphere collision code never brings up a miss, so I have to erwrite it

(how its worked so far I dont know, but it became obvious when writing my sphere reflection code, which i havent finished)

but I dont have time to work on during the weekdays, so ill update this weekend

thanks
Matt :alien:

t1ck135 28-02-2006 11:49 AM

nice work MattTheMan
stuff like this really interests me but I never get the time to do anything. I started writing a 3D vector calculating system in actionscript2 (flash) but then started learning maya and that took all my time up.

Keep going at it and if you have any website links to the theory of how to write the equations/calculations then post them up. Not saying I'll be able to understand any of it though...

junkyBob 01-03-2006 05:44 AM

Hmm.
I wonder if the algrithims you are using could be applied to shockwave? That would be awsome considering that shockwave still does not support shadows or any sorts of raytracing at all.

Maybe we 2 could put our brains together by you coming up with the calculations, and I do the scripting langauge in Director and sell it as a library script where we would split the profits. Hehe :D

gster123 01-03-2006 10:54 PM

Programming does that to ya man, it works for so long then you add somthing no where near related to what your working on it and if F***s up.

Your doing mint dude keep it up!

MattTheMan 01-03-2006 11:59 PM

http://www.flipcode.com/articles/art...ytrace01.shtml

excellent site, but I dont use their code or anything, I use a completely diff. method- and I wont be using a photon mapper, ill b using monte carlo GI-

plus most of the algorithms that I use arent up ther.

heres a cool sphere-ray collision site:

http://www.ccs.neu.edu/home/fell/CSU...ngFormulas.htm

GREAT overview here:
http://www.siggraph.org/education/ma...ce/rtrace1.htm

and as for code porting-

of couse it can be done in shockwave/whatever. Its math: if shockwave can do +, -, divide, multiply, it can do raytracing.

its the combination of +, -, \, * that counts.

Of course, in C++ its nice, you can write your own operators:

i have ones that make it so when adding vectors for instance:

instead of

new.x = v.x + w.x;
new.y = v.y + w.y;
new.z = v.z + w.z;

i do

vector3d new = v + w;

Also, in shockwave, i dont think u can do that, you wuill have to have spereate variables for

vx, vy, vz, wx, wy, wz, newx, newy, newz

which getts really, really annoying+confusing.

then again, raytracing over all is really, really annoying+confusing.

raytracing has a fault though- it is painfully slow. A scene with 20 objects, with a screen of 800x600 has 9,600,000 intersection tests.

Then lets say a ground plane is reflective, which means half of those rays hit the plane, and each reflected ray is tested against each object: 14,000,000 intersection tests. ouch.


but thanx for the nice wurds peeps, I appreciate it.

l8er,
Matt :alien:

moldy530 02-03-2006 12:35 AM

Man i respect what ur doin and all, but ur 13 (i think) you need other focuses right now. *cough* SOCIAL LIFE *cough*

No offense to anyone that does this (well not the ones that are good at this at least. If your as bad as i am give up its not worth the work.) You are all prob gonna make a lot of money off of this, but still you got to live life to love life.

MattTheMan 03-03-2006 12:57 AM

i do this on sunday nights- and what the f** can you do on a sunday night?
I go out with friends/gf on fridays and saturday nights, and I can do these things like... on sunday and sturday mid day and stuf

so go shoot yourself moldy (kidding :p)

cya later
matt :alien:

darijo203 04-03-2006 04:33 PM

I uset to hang out all the time but now...I'm sick of it, waste of money and quality time.

I go out maybe 2 times in 3 monthes, rest od the days I spend playing football, go somewhere in nature for a day or two with my friends...


Keep going...you cant go wrong when learning programming, it will give you more solutions!

moldy530 04-03-2006 05:26 PM

Ya u cud go with programming but what about doctors, they too make a lot of money and u dont have to worry bout ur training untill ur 18

this leaving u more time to be a kid when ur younger

Matt btw i was jk up top. This ^ is an arguement with the last guys reply

MattTheMan 04-03-2006 05:56 PM

well im openin both options- doctor and programmer. And for programmers dont have to do this crap till like... sophomore college year, so I just like to do this and I luv 3d so... i couldnt resist. It was either this or a 3d modeling prog called Angel3d Written in OpenGl.


All times are GMT. The time now is 12:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018