Described idea behind hidden polygon removal.
[sixth-3d.git] / doc / index.org
1 #+TITLE: Sixth 3D - 3D engine
2
3 -----
4 - This is a subproject of [[http://www2.svjatoslav.eu/gitbrowse/sixth/doc/index.html][Sixth]]
5
6 - [[http://www2.svjatoslav.eu/gitweb/?p=sixth-3d.git;a=snapshot;h=HEAD;sf=tgz][download latest snapshot]]
7
8 - This program is free software; you can redistribute it and/or modify it under
9   the terms of version 3 of the [[https://www.gnu.org/licenses/lgpl.html][GNU Lesser General Public License]] or later as
10   published by the Free Software Foundation.
11
12 - Program author:
13   - Svjatoslav Agejenko
14   - Homepage: http://svjatoslav.eu
15   - Email: mailto://svjatoslav@svjatoslav.eu
16
17 - [[http://svjatoslav.eu/programs.jsp][other applications hosted at svjatoslav.eu]]
18
19 * (document settings) :noexport:
20 ** use dark style for TWBS-HTML exporter
21 #+HTML_HEAD: <link href="https://bootswatch.com/darkly/bootstrap.min.css" rel="stylesheet">
22 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
23 #+HTML_HEAD: <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script>"
24 #+HTML_HEAD: <style type="text/css">
25 #+HTML_HEAD:   footer {background-color: #111 !important;}
26 #+HTML_HEAD:   pre {background-color: #111; color: #ccc;}
27 #+HTML_HEAD: </style>
28
29 * Project description
30 In-software, pure Java realtime 3D rendering engine. With the final
31 goal of becoming a platform for buildng 3D user interfaces and
32 interactive data visualization.
33
34 + See: [[http://www2.svjatoslav.eu/gitbrowse/sixth-3d-demos/doc/index.html][demos of current 3D engine capabilities]]
35
36
37 System is implemented in Java because:
38 - It is easy to refactor and experiment with.
39
40 - It scales well to handle great complexity.
41   - Allows to implement clever performance optimizations (instead of
42     going for GPU offered brute-force rendering approach).
43
44 - No limitations imposed by:
45   - requirement for decent GPU
46   - GPU missing features
47   - GPU missing/incomplete/buggy drivers
48   - OpenGL specification
49
50 - It is fast enough thanks to:
51   - Java virtual machine just-in-time compiler.
52   - Growing CPU cores count.
53
54 - As a result it is easy to run on various hardware platforms and
55   operating systems.
56
57 3D rendering is done in software, 100% pure Java on CPU. At least for
58 now. Modern CPU cores count keeps growing and therefore rendering by
59 CPU is not as expensive as it used to be for the old single core
60 systems.
61
62 CPU rendering performance is already good enough to implement usable
63 3D UI at sufficient detail level, resolution and frame rate.
64
65 Pure Java also means easy portability and installation. No need to
66 deal with platform specific dependencies.
67
68 Also CPU rendering allows to easily test different rendering
69 algorithms and retains complete control of every rendered pixel.
70
71
72 * Instructions to embed Sixth-3D in your project
73 Maven *pom.xml* file snippet:
74 #+BEGIN_SRC xml
75 <dependencies>
76     ...
77     <dependency>
78         <groupId>eu.svjatoslav</groupId>
79         <artifactId>sixth-3d</artifactId>
80         <version>1.0</version>
81     </dependency>
82     ...
83 </dependencies>
84
85 <repositories>
86     ...
87     <repository>
88         <id>svjatoslav.eu</id>
89         <name>Svjatoslav repository</name>
90         <url>http://www2.svjatoslav.eu/maven/</url>
91     </repository>
92     ...
93 </repositories>
94 #+END_SRC
95
96 See [[file:codeGraph/index.html][generated code graph]] using [[http://www2.svjatoslav.eu/gitbrowse/javainspect/doc/index.html][this tool]].
97 * TODO features to add
98 + Partial region/frame repaint: when only one small object changed on
99   the scene, it would be faster to re-render that specific area.
100
101 + Once partial rendering works, in would be easy to add multi-core
102   rendering support. So that each core renders it's own region of the
103   screen.
104
105 + Antialiazing. Would improve text readability. If antialiazing is too
106   expensive for every frame, it could be used only for last frame
107   before animations become still and waiting for user input starts.
108
109 + Render only visible polygons.
110   + This would significantly reduce RAM <-> CPU traffic.
111
112   + General algorithm description:
113     + For each horizontal scanline:
114       + sort polygon edges from left to right
115       + while iterating and drawing pixels over screen X axis (left to
116         right) track next appearing/disappearing polygons.
117         + For each polygon edge update Z sorted active polygons list.
118         + Only draw pixel from the top-most polygon.
119           + Only if polygon area is transparent/half-transparent add
120             colors from the polygons below.
121
122   + As a bonus, this would allow to track which polygons are really
123     visible in the final scene for each frame.
124
125     + Such information allows further optimizations:
126
127       + Dynamic geometry simplification:
128         + Dynamically detect and replace invisible objects from the
129           scene with simplified bounding box.
130
131         + Dynamically replace boudnig box with actual object once it
132           becomes visible.
133
134       + Dynamically unload unused textures from RAM.