Showing posts with label ray tracing. Show all posts
Showing posts with label ray tracing. Show all posts

Wednesday, December 31, 2014

RealBengine Ported to OpenFL

Quite a long time since I released the first demo of RealBengine, which is written in HaXe and based on NME. Now I ported the demo to the newest OpenFL, almost with no extra effort. The good thing is now it can compile to the HTML5 target directly, thanks to jgranick's setPixels fix for the HTML5 target: http://community.openfl.org/t/bitmapdata-setpixels-doesnt-work-in-html5/348/3

RealBengine is the candidate of the future version of my voxel render Bengine, it is based on software ray tracing and it has 6 degree of freedom.

However, there is almost no noticeable performance improvement from NME to OpenFL. The Win32 binary still runs at 10~15 FPS, Flash target is about 5 FPS, and HTML5 target is only 0~1 FPS, so lots of optimizations are needed. I'm planning to re-implement to algorithm in LIME/GLSL shaders for a speedup.

DEMO (Win32 binary):
https://drive.google.com/folderview?id=0B5V2PrQ8xX_Ed0sxQkNFM0RGLWs&usp=sharing

DEMO (HTML5):
https://googledrive.com/host/0B5V2PrQ8xX_Ec3J4VzJYcFhrUzQ
Controls:

W/S Arrow UP/Down - Move Forward/Back
Arrow Left/Right - Move Left/Right
Q/E - Move Up/Down
A/D - Look Up/Down

Saturday, April 12, 2014

RealBengine - When Bengine Goes to Real 3D

This maybe the future version of my voxel based rendering engine Bengine, code name "RealBengine". Different from the current version of Bengine, which use ray-casting and is 2.5D, RealBengine will use ray-tracing and hence you will have 6 degree of freedom instead only 4. That means you can look up and down freely without any limit. The current version of Bengine can simulate look up and down a little bit using the distorted projection trick, but this is very limited - about +/-30 degree rotation around the X-Y plane at most. What's more, in RealBengine, you're working with real 3D, so most of the algorithm has been simplified because now you're using 3D vectors rather than fake 3D trick math.

And because of the essential difference in the rendering core, RealBengine will be a totally different engine and will be written from scratch in the future. However, RealBengine is not my priority for now. A similar example with source code using ray-tracing for voxel rendering can be found at:
http://bruce-lab.blogspot.com/2011/08/simple-ray-tracing-voxel-demo.html



An old working demo of RealBengine(Win32 binary):
https://drive.google.com/file/d/0B5V2PrQ8xX_EaEZ0ai1hblMwZGc/edit?usp=sharing

This demo was written in HaXe/NME and compiled to the CPP target some time ago. This is just a simple quick proof of the ray-tracing voxel rendering algorithm. The demo needs optimization as it is slow (about 10~15 FPS in my test). A Flash/SWF version exists but too slow now.

Thursday, August 25, 2011

Simple Ray Tracing Voxel Demo


Just a simple demo using Ray Tracing to render Voxels.
I use a 1D array - voxelData[] to represent voxels/3D points with colors. It's easier for understanding if I use a 3D array, voxelData[x][y][z], where x, y, z is the position of the voxel in 3D space and the value of the array is color for that voxel. Note that voxelData[x][y][z] = voxelData[x<<16|y<<8|z] if the dimension is set to 256 at max.

The rendering idea is simple, since we want to fill the screen using colors, for each pixel in the screen, trace a ray, and march the ray in the voxel space, until the ray hit a voxel, then we get the color and write it to the screen. This is the so-called "first-hit" algorithm.

Ray tracing is slow,  a fast way to render voxel is ray casting, such as the algorithm used in Bengine. But using ray tracing, you can easily add some reflection/shadow effect after calculate normal vectors of the voxels.

Source code: https://flaswf.googlecode.com/svn/trunk/RaytracingVoxel
(similar to the source code of the voxel ray tracing demo in my earlier post)

====================
 Update: November, 27, 2011
====================

Ray Tracing Voxel Demo using 3D DDA/Bresenham's line algorithm


Source code: https://flaswf.googlecode.com/svn/trunk/RaytracingVoxel/3DDDA
More about Bresenham's line algorithm:
http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
http://www.cobrabytes.com/index.php?topic=1150.0
http://www.jonof.id.au/forum/index.php?topic=1338.msg9213;topicseen#msg9213

Friday, April 17, 2009

Ray Tracing - Voxel Rendering in Flash

I did some experiments on ray tracing in as3 before and I'm interested in this technology because it is simple but can create convincing 3D effects like shadows and reflections.
The problem is efficiency, real time rendering for complicated objects seems impossible for
hardware limitations nowadays.

Voxel rendering is another interesting thing, I once played with voxel terrains, you can find some work here:
http://bruce-lab.blogspot.com/2009/01/terrain-rendering-in-flash.html
http://bruce-lab.blogspot.com/2008/10/open-source-as30-voxel-terrain-engine.html

Voxel rendering for 3d objects -volume rendering is something a little different.
Mr doob gave us a very impressive demo(with source):http://www.mrdoob.com/blog/post/571
That swf load a confusing "data.v" file, at first I thought it is a Vista/Lipsia medical CT data format file, but now I think I was wrong. It is just a compressed bytearray data storing the voxel head data -x,y,z and colour values of voxels, please check the loading part of the source code for details. I don't know how they created such data file, maybe use some other software or mybe just by as3. That source is not very readable, what's more I can't figure out how to get those voxel data.

After I saw zevan's work http://shapevent.com/sketchbook/2008/12/28/voxel-play/

and this Isometric Voxels: http://actionsnippet.com/?p=431 (with code)

I decide to do something myself. I tried a simple way - create my own voxel data and use ray tracing to render it. Ray tracing is slow, so I give up real time. I can only create some simple voxel object - cube&sphere, I used six pictures as textures, five for cube and one for the sphere. I use 256*256*256 voxels to represent a simple scene - a sphere in a cube and stored the values in an array, convert and compress it into a bytearray and then save it as 'cube_sphere.vd'. The data file is still large - 3.23MB! The 'voxel_data_tracer.swf' loads this voxel data file and renders the voxels.

This is what I got:

You can download the demo here:
http://flaswf.googlecode.com/files/raytracing%20voxel%20rendering.zip
but it is NOT RECOMMEND, it is slow and eats too much, too much memory - about 200,000k when initing, cpu 50% and more than 120,000k memory needs while rendering.
Source code needs too much optimization so I can't put it here now.
[Update:2011/08/26] Source code for the demo:
http://bruce-lab.blogspot.com/2011/08/simple-ray-tracing-voxel-demo.html
--------------------------------------------
Ken Silverman created a fast cpu based voxel 3d engine -Voxlap using C and DirectX.
http://www.advsys.net/ken/voxlap/voxlap05.htm

The world of Voxlap is fully destructible, yes , you can destroy everything there!
That is the most exciting part of voxels!
Voxlap is open source, but God understands what those crazy codes mean!

An open source game using Voxlap is V O X E L S T E I N 3 D - a FPS game inspired by Wolfenstein 3D.
http://voxelstein3d.blogspot.com/
http://voxelstein3d.sourceforge.net/
Links:
A minecraft level render in flash:
http://liquify.eu/flash/MCExplorer
http://www.minecraftforum.net/viewtopic.php?f=25&t=96591

Monday, August 25, 2008

ray tracing in AS3.0

Flash 3D中最强的光影效果-光线追踪(点击展开中文翻译)


Recently I trying ray tracing in action script. Some ray tracer in flash I know is :
1.Strille’s raytracer_f9(nice effect, source not available ):http://www.strille.net/works/as3/raytracer/raytracer_f9.swf

2.Forrest Briggs’ Real Time Ray Tracer in AS3(simple but effective):http://www.laserpirate.com/as3raytracer/
source:http://www.laserpirate.com/as3raytracer/RayTracer.as

3.non real time ray-tracing in flash-mx(flash-6):
Strillehttp://www.strille.net/works/raytracer.swf
(more controls, you can add light source, sphere, set texture)
Ross Richardson
http://www.flashkit.com/movies/3D/Ray_Trac-Ross_Ric-9255/index.php (simple and open source)
Ross Richardson’s source:http://www.flashkit.com/downloads/movies/zip/9255/Ray%20Tracer%20v0.8.zip

I rewrite Forrest Briggs’s source and add some controls(arrow &space&shift key to move the camera)and fake textures.

demo:https://flaswf.googlecode.com/svn/trunk/flaswfblog/old_homepage/raytracersmall.swf

I also write one using the new Vector3D class for flash 10,but speed down to 3~5 fps! By the way, all above is mostly about Ray-tracing spheres so I also write one Ray-tracing triangle using Barycentric coordinate.



ray-tracing triangles
ray-tracing bump mapping
LINKS:
open source ray-tracing engine based on c++ http://www.devmaster.net/articles/raytracing_series/part1.php(C++source+toturial
The Basics of Raytracing
http://www.devmaster.net/articles/raytracing/
Another Raytracing experiment based on Forrest Briggs's work:
http://unitcu.be/?p=1
ASTrace Raytracing Library (Open Source, AS3)
http://experimentalized.com/astrace.html
http://experimentalized.blogspot.com/2010/10/astrace-pre-release.html

Sponsors