Line3D is the most efficient CPU-based 3D graphics engine ever written in Java. It is very lightweight and supports stereoscopic 3D rendering. Line3D is a part of PhysX3D, Nuclide3D, DroneEngine as well as KineticGas. Since there was no 3D graphics module in Java which could fill my needs of a very efficient graphics engine running on just one CPU core, I had to develop my own. I started with the very basic and very efficient Java libraries javax.swing.JFrame and java.awt.Graphics2D which provided basic shapes such as lines, circles, polygons as well as single pixels on the 2D screen area.
Then I implemented a coordinate transformation method which at first could only rotate, scale and transform 3D coordinates based on mouse interaction in order to project those on the 2D screen. Later the formulas for variable field of view were added. For better visualising plains and spheres I implemented simple polygon graphics with dynamic lighting by multiple light sources. Finally I implemented stereoscopic side-by-side image rendering for 3D monitors and head-mounted displays. Also a very efficient image post-processing algorithm was added to enable bloom.
Running sequential on just one CPU thread, the algorithms had to be as minimalistic and fast as possible. The framerate is depending only on how many lines or polygons are drawn on the display. At few objects, about 30000fps and for 50k objects 30fps can be achieved. Currently the amount of code is about 1k lines including mouse and keyboard interaction.
Problem | My Solution |
Alternative |
---|---|---|
Wireframe Rendering | Stereoscopic Perspective Projection with adjustable field of view | Orthographic Projection |
Occlusion | Painter's Algorithm | z-Buffering |
Shading | Flat Shading with multiple light sources | Phong Shading |
Typical workload in PhysX3D: Shapes to be drawn (Lines, Circles, Polygons, Text): 46337
1. collect output data | 0.00039ms |
---|---|
2. calculate shapes from 3D to 2D and save shapes in 2D | 8.32303ms |
3. sort shapes by z-coordinate | 5.05169ms |
4. draw shapes on frame buffer | 14.37938ms |
5. draw on screen display on frame buffer | 0.06237ms |
6. draw frame buffer on screen | 1.02400ms |
Total 34.52323fps | 28.96482ms |