2009-09-22

improved interactive raytracer

I added some features to my raytracer: reflections, refractions, hard shadows, fresnel effect. It's also possible now to previsualize the scene and the raytracing process using sandy3d (the gray line is the primary ray, the red ones the shadow rays, the green ones the reflected rays and the blue ones the refracted rays). This was very useful to me for debugging.



Here's the script used for the rendering above:

scene.maxReflection = 1;
scene.maxRefraction = 3;
scene.eye = new Vector(0, 30, -500);
var s1 = new Sphere(100, new Vector(0, 0, 200), new Vector(255));
s1.refrIndex = 1.;
var s2 = new Sphere(50, new Vector(0, 0, 500), new Vector(0, 255));
var l = new Light(new Vector(0, 500, -500));
var p = new Plane(new Vector(0, 1), -100, new Vector(0, 0, 255));
scene.addPrimitive(s1);
scene.addPrimitive(s2);
scene.addLight(l);
scene.addPrimitive(p);

2009-08-07

interactive raytracing

I find coding in haxe every day more enjoyable! I scripted my raytracer using hscript, so now scenes can be described and rendered directly in the browser.



The classes available for scripting are:

Primitive:
- new(position)
- position:Vector
- color:Vector
- difusse, specular, power: Float
Primitive -> Sphere:
- new(radius:Float, position:Vector)
Primitive -> Plane:
- new(normal:Vector, distance:Float)
Scene:
- setBackground(color:Vector)
- setDimensions(width:Float, height:Float)
- addPrimitive(p:Primitive)
- addLight(l:Primitive)
Vector:
- x, y, z:Float

The Math's methods and the trace function are also available.
There are some known bugs and I'm working on crashing them. I also plan to add shadows, reflection, refraction etc to the raytracer.

Here's an example script:

function rand(n1,n2){
return Math.floor(Math.random()*(n1-n2+1))+n2;
}

scene.eye.set(0, 0, -500);
scene.setDimensions(300, 300);
var i = 0;
var x = -50;
var y = 100.0;
var z = -100.0;
while(i<360){ var deg = i * Math.PI / 180.0; var s = new Sphere(20, new Vector(x += Math.cos(deg) * 50, y -= 15, z += Math.sin(deg) * 130)); s.color = new Vector(rand(0, 255), rand(0, 255), rand(0, 255)); trace(s.color); scene.addPrimitive(s); i += 30; } scene.addLight(new Primitive(new Vector(0, 500, -500)));

2009-08-04

raytracing in haxe

As I've started to learn haxe, I wrote a very basic raytracer



It can go real-time too, if you dont care much about the image quality. And here are the sources.

2009-05-07

shadows part ll: stress test

Although there are some rough edges and the FPS is pretty low, I'm quite pleased with the results.
Use the 'L' key to stop/start the light orbiting, 'A' to stop/start the animation and the UP/DOWN arrows to change the light altitude.

2009-04-23

shadows

Today I've played with rays again:

2009-03-22

sandy quake (kind of)

Here's something I've been working on these days; it was a good opportunity to improve my actionscript skills, to learn more sandy3d and to test my engine. Dont expect much, it is WIP, the enemies are completely dumb (and their willing to die seems quite big), there's no goal in the game, you just can go around and shoot stuff... Well, hopefully it will improve, eventually.

2009-03-07

a really simple raytracer

...made off in about 20 lines of code (the intersection stuff was already there). There's a simple sandy3d scene and, in the upper left corner of the window, is its raytraced approximation.

2009-02-26

back to work

...hopefuly. I've been quite busy lately, changing job (actually just quiting the old one), changing home, city, even country. Nevertheless, I managed to do some work on the c++ version of my project. Basically, it is just particles - plane collision, but I've elaborated it a bit, just for fun: it will draw an image (have to be 128x128, 24b/pixel; it will use any "image.bmp" found in the current directory or a bmp file given as parameter, like painter animage.bmp)  with a "beam cutting through steel" like effect. Use the pagedown/pageup keys to increase/decrease the beam velocity.

Click the image below to download the executable (win32) . You can get the sources as well. You will need my old windows wrapper library if you want to build it yourself.