Jump to content
  • Advertisement
Sign in to follow this  

Writing a raytracer

This topic is 3829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Nice, I've been wanting to experiment with ray-tracing myself (as well as ray-casting and old-school voxels, as I'm interested in low-level graphics programming) and now that I've got a multi-core CPU the prospect has become all the more interesting.

Congrats, it looks great so far. I wonder how long it'll take me to match up :)

Share this post

Link to post
Share on other sites
I've been working on a raytracer myself in my spare time. So far, it's very basic. It has support for diffuse and specular material properties, directional and positional light sources, reflection and (hard) shadows. It supports planes, spheres, and triangular meshes as primitives right now and reads the scene from a well formed XML scene description file. The implementation of what I have now was pretty straight forward, but I want to move in the direction of implementing global illumination next, and it's not nearly so straight forward. Implementing global illumination, it seems, changes the core algorithm significantly. I was thinking I was going to take the photon mapping approach; any suggestions?

Share this post

Link to post
Share on other sites
I haven't got that far yet myself. All I've got that you don't is soft shadows and normal maps, and I don't have triangle meshes yet. I'm going to be looking into bi-directional ray tracing soon, though.

Share this post

Link to post
Share on other sites
I suppose that perhaps path tracing would be easier to implement than photon mapping (I mean, I suppose that PT would require less changes to the code...)

To Deya: Have you already implemented Fresnel to get physically based reflection/transmission coefficents (with vary with the incident angle and the material)? If not, give it a look: it is not hard to implement at all, and if you set up a nice small scene, it provides a really more realistic look to a glass sphere.
I would like to show you the difference with my rt, but when I started it from scratch I messed up the old code, so it doesn't even compile right now :-(

Anyway, I've found two images. The first one is from one of my first attempt to do RT (no fresnel), while the second the latest before restarting from scratch (with fresnel).
Unlukily I've had the bad idea to use normal mapping on that sphere, but if you look carefully, you will see that the sphere becomes darker on the borders: this is due to the fact that fresnel law leads to a higher reflection (wich means less transmission) and the sphere reflect the black enviroment more than at the 'center'.


Share this post

Link to post
Share on other sites
Great shots guys, it definetly makes me want to finish my raytracer.

One question I do have is that as far as the material properties go, what kinds of materials do you all use? Are they one's that you have found on the net or are they things you messed around in an app with before hand and just imported them?

Share this post

Link to post
Share on other sites
Materials are just a collection of properties.

Vector3 color;
float diffuse;
float reflection;
float specular;
float refraction;
float refraction_index;
Jemgine::Flat::Surface texture;
Jemgine::Flat::Surface normal_map;
Jemgine::Flat::Surface specular_map;
Jemgine::Deadlock::CriticalSection protect_texture;

Share this post

Link to post
Share on other sites
Nice images. I'm also implementing a raytracer (as everyboby else, it seems to me :D ), I have some images rendered here. I plan to implement normal maps, and seeing your pictures I'll consider specular maps too. Currently I'm working on adding an acceleration structure (most probably BIH) to speed up triangle-mesh rendering.

Share this post

Link to post
Share on other sites
The last ray tracer i built, it's features were:

Primitives : unit sphere, unit cube, torus with unit major radius, double infinite unit cone, unit infinite cylinder, plane, heightmap terrain.

CSG operations : AND, OR, XOR, XNOR, NAND, NOR, and Merge (AND but removes inner surfaces)

All primitives themselves, and any further CSG operations built with them can have their own transformations for scaling, rotating and translation done upon them.

Primitives and CSG operations also have a refractive index defined for them.

Primitives and CSG operations are added to a list, and then there is another list in which you add the objects that are actually to be rendered, so you can reuse objects aswell without defining more of them, in the display list, only that object's refractive index is used, the refractive index of any sub-objects from CSG operations is ignored.

Each primitive has a list of maps that can be applied, each list is undeterminate size, all maps can have seperately their own transformations applied to them.

texture maps:
TEX_SOLID (solid colour)
TEX_CHECK (checkerboard colour)
TEX_JPEG (jpeg image loaded in for texture map)
When adding them to the list, they are added with an operation to be performed when it is evaluated with various blend modes so you can combine texture maps

normal maps: (tangent space)
these can also be combined for the sake of it, it takes the average of the normals when evaluated

property maps: (RGB map, R for diffuse, G for specular, B for transmission)
these can also be combined, and with a simple checkerboard one, you could have a checkerboard pattern on a plane of being totally diffuse, or totally specular for example.

point lights, position, with colour and intensity (For fall-off of light)
spot lights, position, with colour and intensity, cone radius, cone fall-off, and direction obviously.

Photon mapping, i never got around to adding proper caustic renderings, but after adding this i left the ray tracing behind and moved onto something else, i also never got around to adding area lights, soft shadows, soft reflections etc.

(in chronological order!)
reflections, and multiple texture mapping.

refractions, and normal mapping.

refractions, propert mapping on inner cube.

heightmap terrain, reflections, CSG operation (Torus is subtracted from terrain)

spot lights, refractive spheres, reflective tori.

photon mapping, the little bit of soft-shadowing is done by having multiple point lights :P, the cube is partially refractive, the sphere partially reflective, the wall is completely diffuse, textured for each wall being the colour it primarily shows, with normal mapping.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!