programing a raytracer

Discuss stuff not about Indigo.
User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Thu Apr 19, 2007 5:28 am

yah, but i hate working with pixels and images in graphics code, and due to speed and memory issues i had to change the 3 dimensional x y color matrix to a 2d matrix- thus i cant edit pixels verticaly, just horizontaly.

i fixed the problem with phong in my program- it wasn't phong that had the problem apparently, it was my color code which i somehow forgot to set the r g and b as public variables, thus for every light it "forgot" the color applied from the previous light.

the green on the sphere turned out to be the specular color that i had set in that sphere's declaration- the fact that it turned green in the dark had to do with loosing the rgb data.
a shiny monkey is a happy monkey

User avatar
eman7613
Posts: 597
Joined: Sat Sep 16, 2006 2:52 pm

Post by eman7613 » Thu Apr 19, 2007 1:50 pm

Your not thinking like a college bound kid ;p

the current method is less work and looks the same on paper, and has the same result. :D
Yes i know, my spelling sucks

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Thu Apr 19, 2007 3:48 pm

Your not thinking like a college bound kid ;p
Well how many college bound kids do you know who program raytracers or even know what a raytracer, or even a renderer is?

i finaly figured out how to compile the program into a jar- (they dont teach us that in java class- mostly because our teacher doesnt know how)

download the program from http://www.bluecubegraphics.com under the files section. to run it unzip it and remove the file miniTracer.jar from the archive (dont bother with the source archive its password protected and put there for my personal multicomputer access). the scene is a simple 2 ball one with a phong diffuse and specular. the only things that work on the gui are the text feilds and the render button.
a shiny monkey is a happy monkey

IanT
Posts: 153
Joined: Fri Aug 25, 2006 3:13 am

Post by IanT » Thu Apr 19, 2007 9:58 pm

Well how many college bound kids do you know who program raytracers or even know what a raytracer, or even a renderer is?

I think I was 15 when I wrote my first ray-tracer ... 8 hours to render a reflective sphere over a checkered ground plane (compared to less than a second to do the same thing now at higher resolution). Technology's amazing huh? :wink:

Re: Working with individual pixels ... making a 1D array was definitely the right decision (especially as Java's arrays are quite memory hungry) but you can easily make a couple of methods to address pixels at the x,y level with some simple maths. Once you start to make more complex scenes, you'll definitely want some way to do adaptive AA.

Ian.

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Fri Apr 20, 2007 12:05 am

I think I was 15 when I wrote my first ray-tracer ... 8 hours to render a reflective sphere over a checkered ground plane (compared to less than a second to do the same thing now at higher resolution). Technology's amazing huh? Wink
15's a little early- maybe they just teach programing late at my school. however i dont think the 3d/programing community is a good representation of the level of students/programers throughout the country- there tends to be a much larger number of "gifted" (i hate that word) people in these communities.

as for adaptive AA with 1d array- i've been thinking about it, shouldnt be as hard as i originaly thaught.
a shiny monkey is a happy monkey

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Tue Apr 24, 2007 2:05 pm

yay! i got shadows working and fixed phong-
the trace code is currently a little messy, but still incredibly workable (yay java object oriented stuff) i haven't programed in triangle intersections but thats next. does anybody have any links for methods of normal smoothing?

Image

the reason its purple is because of the ambient which i shall make accessable through the little color panel eventualy.
a shiny monkey is a happy monkey

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Tue Apr 24, 2007 2:58 pm

Image
testing the speed with more than 2 spheres- i'm quite happy to say that the memory is not sacrificed- only the speed- and only just slightly
a shiny monkey is a happy monkey

User avatar
eman7613
Posts: 597
Joined: Sat Sep 16, 2006 2:52 pm

Post by eman7613 » Wed Apr 25, 2007 4:46 am

whats with the funky shading and black spots?
Yes i know, my spelling sucks

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Wed Apr 25, 2007 4:54 am

i'm pretty sure there shadows, not sure if there working correctly though.
a shiny monkey is a happy monkey

User avatar
eman7613
Posts: 597
Joined: Sat Sep 16, 2006 2:52 pm

Post by eman7613 » Thu Apr 26, 2007 7:42 am

i know its not java, but genrealy its all good:
http://blogs.msdn.com/coding4fun/archiv ... 74685.aspx

Made in c#
Yes i know, my spelling sucks

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Thu Apr 26, 2007 8:02 am

I don't have code, but you can look at theory:
simpler, but worse looking:
Gouraud shading
a bit more complicated, but MUCH better (common way of doing it)
Phong Shading

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Thu Apr 26, 2007 1:54 pm

so with finding which triangles the vertex is in- is that something usualy put in the scene file or is that usualy somehow programed into the raytracer sceneloader?

for example when i set up how the scene file is set up would it be logical to have the vertexes first numbered and declared then triangles numbered and declared using the previously declared numbered vertexes. the triangle numbers that the vertexes are in would be added in an array to the vertex and then the raytracer would calculate the normal of the vertex based on the triangles that its in?
a shiny monkey is a happy monkey

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Thu Apr 26, 2007 2:05 pm

Image
an old new pic

Image
ambient specular test (peach fuzz)
a shiny monkey is a happy monkey

IanT
Posts: 153
Joined: Fri Aug 25, 2006 3:13 am

Post by IanT » Thu Apr 26, 2007 4:23 pm

oodmb wrote:so with finding which triangles the vertex is in- is that something usualy put in the scene file or is that usualy somehow programed into the raytracer sceneloader?

for example when i set up how the scene file is set up would it be logical to have the vertexes first numbered and declared then triangles numbered and declared using the previously declared numbered vertexes. the triangle numbers that the vertexes are in would be added in an array to the vertex and then the raytracer would calculate the normal of the vertex based on the triangles that its in?
You should probably design your scene file based on the most likely import routes. For example, the .OBJ format defines a triangle (or square, or n-gon) with indices into a global pool of vertices, normals and UVs. Other 3D modelling applications might give you a pool of vertices/normals/UVs on a per-object basis. Implementing both schemes wouldn't do any harm at all :wink:

During rendering, it's unlikely you'll ever need to know which triangles a vertex belongs too ... you'll only need it if you want to calculate smoothed normals yourself and that should only ever happen once after the scene is loaded.

Ian.

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Sun Apr 29, 2007 5:52 am

just programed plane ray intersection. however-- ERRORS!!!!! yummy.
it seems to create a grain on the plane dependent highly on the angle of the plane. the shape of the grain is also dependent on the angle
here is the collision code:

images:
Image
Image
Image

does anybody have any insights?
Last edited by oodmb on Sun Apr 29, 2007 7:39 am, edited 1 time in total.
a shiny monkey is a happy monkey

Post Reply
164 posts

Who is online

Users browsing this forum: Ahrefs [Bot] and 20 guests