joonsrenderer 1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/CHANGELOG.md +2 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +674 -0
  7. data/README.md +2 -0
  8. data/Rakefile +43 -0
  9. data/docs/.gitignore +6 -0
  10. data/docs/_config.yml +20 -0
  11. data/docs/_includes/footer.html +38 -0
  12. data/docs/_includes/head.html +15 -0
  13. data/docs/_includes/header.html +27 -0
  14. data/docs/_includes/icon-github.html +1 -0
  15. data/docs/_includes/icon-github.svg +1 -0
  16. data/docs/_includes/icon-twitter.html +1 -0
  17. data/docs/_includes/icon-twitter.svg +1 -0
  18. data/docs/_layouts/default.html +20 -0
  19. data/docs/_layouts/page.html +14 -0
  20. data/docs/_layouts/post.html +15 -0
  21. data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
  22. data/docs/_posts/2017-01-08-welcome.md +78 -0
  23. data/docs/_sass/_base.scss +206 -0
  24. data/docs/_sass/_layout.scss +242 -0
  25. data/docs/_sass/_syntax-highlighting.scss +71 -0
  26. data/docs/about.md +12 -0
  27. data/docs/assets/Animation.ogv +0 -0
  28. data/docs/assets/Animation.png +0 -0
  29. data/docs/assets/basic.png +0 -0
  30. data/docs/assets/basic_traced.png +0 -0
  31. data/docs/css/main.scss +38 -0
  32. data/docs/favicon.ico +0 -0
  33. data/docs/feed.xml +30 -0
  34. data/docs/index.html +38 -0
  35. data/joonsrenderer.gemspec +23 -0
  36. data/lib/joonsrenderer.rb +12 -0
  37. data/lib/joonsrenderer/version.rb +3 -0
  38. data/pom.rb +75 -0
  39. data/pom.xml +163 -0
  40. data/src/main/java/SunflowGUI.java +1354 -0
  41. data/src/main/java/joons/JRFiller.java +79 -0
  42. data/src/main/java/joons/JRImagePanel.java +141 -0
  43. data/src/main/java/joons/JRRecorder.java +183 -0
  44. data/src/main/java/joons/JRStatics.java +199 -0
  45. data/src/main/java/joons/JoonsRenderer.java +837 -0
  46. data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
  47. data/src/main/java/org/sunflow/Benchmark.java +313 -0
  48. data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
  49. data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
  50. data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
  51. data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
  52. data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
  53. data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
  54. data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
  55. data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
  56. data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
  57. data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
  58. data/src/main/java/org/sunflow/core/Camera.java +125 -0
  59. data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
  60. data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
  61. data/src/main/java/org/sunflow/core/Display.java +78 -0
  62. data/src/main/java/org/sunflow/core/Filter.java +27 -0
  63. data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
  64. data/src/main/java/org/sunflow/core/Geometry.java +157 -0
  65. data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
  66. data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
  67. data/src/main/java/org/sunflow/core/Instance.java +224 -0
  68. data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
  69. data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
  70. data/src/main/java/org/sunflow/core/LightSample.java +104 -0
  71. data/src/main/java/org/sunflow/core/LightServer.java +382 -0
  72. data/src/main/java/org/sunflow/core/LightSource.java +67 -0
  73. data/src/main/java/org/sunflow/core/Modifier.java +16 -0
  74. data/src/main/java/org/sunflow/core/Options.java +20 -0
  75. data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
  76. data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
  77. data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
  78. data/src/main/java/org/sunflow/core/Ray.java +219 -0
  79. data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
  80. data/src/main/java/org/sunflow/core/Scene.java +377 -0
  81. data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
  82. data/src/main/java/org/sunflow/core/Shader.java +30 -0
  83. data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
  84. data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
  85. data/src/main/java/org/sunflow/core/Statistics.java +85 -0
  86. data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
  87. data/src/main/java/org/sunflow/core/Texture.java +128 -0
  88. data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
  89. data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
  90. data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
  91. data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
  92. data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
  93. data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
  94. data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
  95. data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
  96. data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
  97. data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
  98. data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
  99. data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
  100. data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
  101. data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
  102. data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
  103. data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
  104. data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
  105. data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
  106. data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
  107. data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
  108. data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
  109. data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
  110. data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
  111. data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
  112. data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
  113. data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
  114. data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
  115. data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
  116. data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
  117. data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
  118. data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
  119. data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
  120. data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
  121. data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
  122. data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
  123. data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
  124. data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
  125. data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
  126. data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
  127. data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
  128. data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
  129. data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
  130. data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
  131. data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
  132. data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
  133. data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
  134. data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
  135. data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
  136. data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
  137. data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
  138. data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
  139. data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
  140. data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
  141. data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
  142. data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
  143. data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
  144. data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
  145. data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
  146. data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
  147. data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
  148. data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
  149. data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
  150. data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
  151. data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
  152. data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
  153. data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
  154. data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
  155. data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
  156. data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
  157. data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
  158. data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
  159. data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
  160. data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
  161. data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
  162. data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
  163. data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
  164. data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
  165. data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
  166. data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
  167. data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
  168. data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
  169. data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
  170. data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
  171. data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
  172. data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
  173. data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
  174. data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
  175. data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
  176. data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
  177. data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
  178. data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
  179. data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
  180. data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
  181. data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
  182. data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
  183. data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
  184. data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
  185. data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
  186. data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
  187. data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
  188. data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
  189. data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
  190. data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
  191. data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
  192. data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
  193. data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
  194. data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
  195. data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
  196. data/src/main/java/org/sunflow/image/Color.java +374 -0
  197. data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
  198. data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
  199. data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
  200. data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
  201. data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
  202. data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
  203. data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
  204. data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
  205. data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
  206. data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
  207. data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
  208. data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
  209. data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
  210. data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
  211. data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
  212. data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
  213. data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
  214. data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
  215. data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
  216. data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
  217. data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
  218. data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
  219. data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
  220. data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
  221. data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
  222. data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
  223. data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
  224. data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
  225. data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
  226. data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
  227. data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
  228. data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
  229. data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
  230. data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
  231. data/src/main/java/org/sunflow/math/Point2.java +36 -0
  232. data/src/main/java/org/sunflow/math/Point3.java +133 -0
  233. data/src/main/java/org/sunflow/math/QMC.java +209 -0
  234. data/src/main/java/org/sunflow/math/Solvers.java +142 -0
  235. data/src/main/java/org/sunflow/math/Vector3.java +197 -0
  236. data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
  237. data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
  238. data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
  239. data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
  240. data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
  241. data/src/main/java/org/sunflow/system/Memory.java +18 -0
  242. data/src/main/java/org/sunflow/system/Parser.java +162 -0
  243. data/src/main/java/org/sunflow/system/Plugins.java +142 -0
  244. data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
  245. data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
  246. data/src/main/java/org/sunflow/system/Timer.java +53 -0
  247. data/src/main/java/org/sunflow/system/UI.java +112 -0
  248. data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
  249. data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
  250. data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
  251. data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
  252. data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
  253. data/src/main/java/org/sunflow/util/IntArray.java +77 -0
  254. data/src/test/java/a_maintest.java +129 -0
  255. metadata +300 -0
@@ -0,0 +1,125 @@
1
+ package org.sunflow;
2
+
3
+ import org.sunflow.core.Display;
4
+ import org.sunflow.core.display.FastDisplay;
5
+ import org.sunflow.core.display.FileDisplay;
6
+ import org.sunflow.math.Matrix4;
7
+ import org.sunflow.math.Point3;
8
+ import org.sunflow.math.Vector3;
9
+ import org.sunflow.system.Timer;
10
+ import org.sunflow.system.UI;
11
+ import org.sunflow.system.UI.Module;
12
+ import org.sunflow.system.ui.ConsoleInterface;
13
+
14
+ public class RealtimeBenchmark extends SunflowAPI {
15
+ final String CAMERA = "camera";
16
+ final String TRANSFORM = "transform";
17
+ public RealtimeBenchmark(boolean showGUI, int threads) {
18
+ Display display = showGUI ? new FastDisplay() : new FileDisplay(false);
19
+ UI.printInfo(Module.BENCH, "Preparing benchmarking scene ...");
20
+ // settings
21
+ parameter("threads", threads);
22
+ // spawn regular priority threads
23
+ parameter("threads.lowPriority", false);
24
+ parameter("resolutionX", 512);
25
+ parameter("resolutionY", 512);
26
+ parameter("aa.min", -3);
27
+ parameter("aa.max", 0);
28
+ parameter("depths.diffuse", 1);
29
+ parameter("depths.reflection", 1);
30
+ parameter("depths.refraction", 0);
31
+ parameter("bucket.order", "hilbert");
32
+ parameter("bucket.size", 32);
33
+ options(SunflowAPI.DEFAULT_OPTIONS);
34
+ // camera
35
+ Point3 eye = new Point3(30, 0, 10.967f);
36
+ Point3 target = new Point3(0, 0, 5.4f);
37
+ Vector3 up = new Vector3(0, 0, 1);
38
+ parameter(TRANSFORM, Matrix4.lookAt(eye, target, up));
39
+ parameter("fov", 45.0f);
40
+ camera(CAMERA, "pinhole");
41
+ parameter(CAMERA, CAMERA);
42
+ options(SunflowAPI.DEFAULT_OPTIONS);
43
+ // geometry
44
+ createGeometry();
45
+ // this first render is not timed, it caches the acceleration data
46
+ // structures and tesselations so they won't be
47
+ // included in the main timing
48
+ UI.printInfo(Module.BENCH, "Rendering warmup frame ...");
49
+ render(SunflowAPI.DEFAULT_OPTIONS, display);
50
+ // now disable all output - and run the benchmark
51
+ UI.set(null);
52
+ Timer t = new Timer();
53
+ t.start();
54
+ float phi = 0;
55
+ int frames = 0;
56
+ while (phi < 4 * Math.PI) {
57
+ eye.x = 30 * (float) Math.cos(phi);
58
+ eye.y = 30 * (float) Math.sin(phi);
59
+ phi += Math.PI / 30;
60
+ frames++;
61
+ // update camera
62
+ parameter(TRANSFORM, Matrix4.lookAt(eye, target, up));
63
+ camera(CAMERA, null);
64
+ render(SunflowAPI.DEFAULT_OPTIONS, display);
65
+ }
66
+ t.end();
67
+ UI.set(new ConsoleInterface());
68
+ UI.printInfo(Module.BENCH, "Benchmark results:");
69
+ UI.printInfo(Module.BENCH, " * Average FPS: %.2f", frames / t.seconds());
70
+ UI.printInfo(Module.BENCH, " * Total time: %s", t);
71
+ }
72
+
73
+ private void createGeometry() {
74
+ // light source
75
+ parameter("source", new Point3(-15.5945f, -30.0581f, 45.967f));
76
+ parameter("dir", new Vector3(15.5945f, 30.0581f, -45.967f));
77
+ parameter("radius", 60.0f);
78
+ parameter("radiance", null, 3, 3, 3);
79
+ light("light", "directional");
80
+
81
+ // gi-engine
82
+ parameter("gi.engine", "fake");
83
+ parameter("gi.fake.sky", null, 0.25f, 0.25f, 0.25f);
84
+ parameter("gi.fake.ground", null, 0.01f, 0.01f, 0.5f);
85
+ parameter("gi.fake.up", new Vector3(0, 0, 1));
86
+ options(DEFAULT_OPTIONS);
87
+
88
+ // shaders
89
+ parameter("diffuse", null, 0.5f, 0.5f, 0.5f);
90
+ shader("default", "diffuse");
91
+ parameter("diffuse", null, 0.5f, 0.5f, 0.5f);
92
+ parameter("shiny", 0.2f);
93
+ shader("refl", "shiny_diffuse");
94
+ // objects
95
+
96
+ // teapot
97
+ parameter("subdivs", 10);
98
+ geometry("teapot", "teapot");
99
+ parameter("shaders", "default");
100
+ Matrix4 m = Matrix4.IDENTITY;
101
+ m = Matrix4.scale(0.075f).multiply(m);
102
+ m = Matrix4.rotateZ((float) Math.toRadians(-45f)).multiply(m);
103
+ m = Matrix4.translation(-7, 0, 0).multiply(m);
104
+ parameter(TRANSFORM, m);
105
+ instance("teapot.instance", "teapot");
106
+
107
+ // gumbo
108
+ parameter("subdivs", 10);
109
+ geometry("gumbo", "gumbo");
110
+ m = Matrix4.IDENTITY;
111
+ m = Matrix4.scale(0.5f).multiply(m);
112
+ m = Matrix4.rotateZ((float) Math.toRadians(25f)).multiply(m);
113
+ m = Matrix4.translation(3, -7, 0).multiply(m);
114
+ parameter("shaders", "default");
115
+ parameter(TRANSFORM, m);
116
+ instance("gumbo.instance", "gumbo");
117
+
118
+ // ground plane
119
+ parameter("center", new Point3(0, 0, 0));
120
+ parameter("normal", new Vector3(0, 0, 1));
121
+ geometry("ground", "plane");
122
+ parameter("shaders", "refl");
123
+ instance("ground.instance", "ground");
124
+ }
125
+ }
@@ -0,0 +1,344 @@
1
+ package org.sunflow;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.Locale;
5
+
6
+ import org.sunflow.core.Camera;
7
+ import org.sunflow.core.Geometry;
8
+ import org.sunflow.core.Instance;
9
+ import org.sunflow.core.LightSource;
10
+ import org.sunflow.core.Modifier;
11
+ import org.sunflow.core.Options;
12
+ import org.sunflow.core.ParameterList;
13
+ import org.sunflow.core.PrimitiveList;
14
+ import org.sunflow.core.RenderObject;
15
+ import org.sunflow.core.Scene;
16
+ import org.sunflow.core.Shader;
17
+ import org.sunflow.core.Tesselatable;
18
+ import org.sunflow.system.UI;
19
+ import org.sunflow.system.UI.Module;
20
+ import org.sunflow.util.FastHashMap;
21
+
22
+ final class RenderObjectMap {
23
+
24
+ private FastHashMap<String, RenderObjectHandle> renderObjects;
25
+ private boolean rebuildInstanceList;
26
+ private boolean rebuildLightList;
27
+
28
+ private enum RenderObjectType {
29
+
30
+ UNKNOWN, SHADER, MODIFIER, GEOMETRY, INSTANCE, LIGHT, CAMERA, OPTIONS
31
+ }
32
+
33
+ RenderObjectMap() {
34
+ renderObjects = new FastHashMap<>();
35
+ rebuildInstanceList = rebuildLightList = false;
36
+ }
37
+
38
+ final boolean has(String name) {
39
+ return renderObjects.containsKey(name);
40
+ }
41
+
42
+ final void remove(String name) {
43
+ RenderObjectHandle obj = renderObjects.get(name);
44
+ if (obj == null) {
45
+ UI.printWarning(Module.API, "Unable to remove \"%s\" - object was not defined yet");
46
+ return;
47
+ }
48
+ UI.printDetailed(Module.API, "Removing object \"%s\"", name);
49
+ renderObjects.remove(name);
50
+ // scan through all objects to make sure we don't have any
51
+ // references to the old object still around
52
+ switch (obj.type) {
53
+ case SHADER:
54
+ Shader s = obj.getShader();
55
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
56
+ Instance i = e.getValue().getInstance();
57
+ if (i != null) {
58
+ UI.printWarning(Module.API, "Removing shader \"%s\" from instance \"%s\"", name, e.getKey());
59
+ i.removeShader(s);
60
+ }
61
+ }
62
+ break;
63
+ case MODIFIER:
64
+ Modifier m = obj.getModifier();
65
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
66
+ Instance i = e.getValue().getInstance();
67
+ if (i != null) {
68
+ UI.printWarning(Module.API, "Removing modifier \"%s\" from instance \"%s\"", name, e.getKey());
69
+ i.removeModifier(m);
70
+ }
71
+ }
72
+ break;
73
+ case GEOMETRY: {
74
+ Geometry g = obj.getGeometry();
75
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
76
+ Instance i = e.getValue().getInstance();
77
+ if (i != null && i.hasGeometry(g)) {
78
+ UI.printWarning(Module.API, "Removing instance \"%s\" because it referenced geometry \"%s\"", e.getKey(), name);
79
+ remove(e.getKey());
80
+ }
81
+ }
82
+ break;
83
+ }
84
+ case INSTANCE:
85
+ rebuildInstanceList = true;
86
+ break;
87
+ case LIGHT:
88
+ rebuildLightList = true;
89
+ break;
90
+ default:
91
+ // no dependencies
92
+ break;
93
+ }
94
+ }
95
+
96
+ final boolean update(String name, ParameterList pl, SunflowAPI api) {
97
+ RenderObjectHandle obj = renderObjects.get(name);
98
+ boolean success;
99
+ if (obj == null) {
100
+ UI.printError(Module.API, "Unable to update \"%s\" - object was not defined yet", name);
101
+ success = false;
102
+ } else {
103
+ UI.printDetailed(Module.API, "Updating %s object \"%s\"", obj.typeName(), name);
104
+ success = obj.update(pl, api);
105
+ if (!success) {
106
+ UI.printError(Module.API, "Unable to update \"%s\" - removing", name);
107
+ remove(name);
108
+ } else {
109
+ switch (obj.type) {
110
+ case GEOMETRY:
111
+ case INSTANCE:
112
+ rebuildInstanceList = true;
113
+ break;
114
+ case LIGHT:
115
+ rebuildLightList = true;
116
+ break;
117
+ default:
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ return success;
123
+ }
124
+
125
+ final void updateScene(Scene scene) {
126
+ if (rebuildInstanceList) {
127
+ UI.printInfo(Module.API, "Building scene instance list for rendering ...");
128
+ int numInfinite = 0, numInstance = 0;
129
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
130
+ Instance i = e.getValue().getInstance();
131
+ if (i != null) {
132
+ i.updateBounds();
133
+ if (i.getBounds() == null) {
134
+ numInfinite++;
135
+ } else if (!i.getBounds().isEmpty()) {
136
+ numInstance++;
137
+ } else {
138
+ UI.printWarning(Module.API, "Ignoring empty instance: \"%s\"", e.getKey());
139
+ }
140
+ }
141
+ }
142
+ Instance[] infinite = new Instance[numInfinite];
143
+ Instance[] instance = new Instance[numInstance];
144
+ numInfinite = numInstance = 0;
145
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
146
+ Instance i = e.getValue().getInstance();
147
+ if (i != null) {
148
+ if (i.getBounds() == null) {
149
+ infinite[numInfinite] = i;
150
+ numInfinite++;
151
+ } else if (!i.getBounds().isEmpty()) {
152
+ instance[numInstance] = i;
153
+ numInstance++;
154
+ }
155
+ }
156
+ }
157
+ scene.setInstanceLists(instance, infinite);
158
+ rebuildInstanceList = false;
159
+ }
160
+ if (rebuildLightList) {
161
+ UI.printInfo(Module.API, "Building scene light list for rendering ...");
162
+ ArrayList<LightSource> lightList = new ArrayList<>();
163
+ for (FastHashMap.Entry<String, RenderObjectHandle> e : renderObjects) {
164
+ LightSource light = e.getValue().getLight();
165
+ if (light != null) {
166
+ lightList.add(light);
167
+ }
168
+
169
+ }
170
+ scene.setLightList(lightList.toArray(new LightSource[lightList.size()]));
171
+ rebuildLightList = false;
172
+ }
173
+ }
174
+
175
+ final void put(String name, Shader shader) {
176
+ renderObjects.put(name, new RenderObjectHandle(shader));
177
+ }
178
+
179
+ final void put(String name, Modifier modifier) {
180
+ renderObjects.put(name, new RenderObjectHandle(modifier));
181
+ }
182
+
183
+ final void put(String name, PrimitiveList primitives) {
184
+ renderObjects.put(name, new RenderObjectHandle(primitives));
185
+ }
186
+
187
+ final void put(String name, Tesselatable tesselatable) {
188
+ renderObjects.put(name, new RenderObjectHandle(tesselatable));
189
+ }
190
+
191
+ final void put(String name, Instance instance) {
192
+ renderObjects.put(name, new RenderObjectHandle(instance));
193
+ }
194
+
195
+ final void put(String name, LightSource light) {
196
+ renderObjects.put(name, new RenderObjectHandle(light));
197
+ }
198
+
199
+ final void put(String name, Camera camera) {
200
+ renderObjects.put(name, new RenderObjectHandle(camera));
201
+ }
202
+
203
+ final void put(String name, Options options) {
204
+ renderObjects.put(name, new RenderObjectHandle(options));
205
+ }
206
+
207
+ final Geometry lookupGeometry(String name) {
208
+ if (name == null) {
209
+ return null;
210
+ }
211
+ RenderObjectHandle handle = renderObjects.get(name);
212
+ return (handle == null) ? null : handle.getGeometry();
213
+ }
214
+
215
+ final Instance lookupInstance(String name) {
216
+ if (name == null) {
217
+ return null;
218
+ }
219
+ RenderObjectHandle handle = renderObjects.get(name);
220
+ return (handle == null) ? null : handle.getInstance();
221
+ }
222
+
223
+ final Camera lookupCamera(String name) {
224
+ if (name == null) {
225
+ return null;
226
+ }
227
+ RenderObjectHandle handle = renderObjects.get(name);
228
+ return (handle == null) ? null : handle.getCamera();
229
+ }
230
+
231
+ final Options lookupOptions(String name) {
232
+ if (name == null) {
233
+ return null;
234
+ }
235
+ RenderObjectHandle handle = renderObjects.get(name);
236
+ return (handle == null) ? null : handle.getOptions();
237
+ }
238
+
239
+ final Shader lookupShader(String name) {
240
+ if (name == null) {
241
+ return null;
242
+ }
243
+ RenderObjectHandle handle = renderObjects.get(name);
244
+ return (handle == null) ? null : handle.getShader();
245
+ }
246
+
247
+ final Modifier lookupModifier(String name) {
248
+ if (name == null) {
249
+ return null;
250
+ }
251
+ RenderObjectHandle handle = renderObjects.get(name);
252
+ return (handle == null) ? null : handle.getModifier();
253
+ }
254
+
255
+ final LightSource lookupLight(String name) {
256
+ if (name == null) {
257
+ return null;
258
+ }
259
+ RenderObjectHandle handle = renderObjects.get(name);
260
+ return (handle == null) ? null : handle.getLight();
261
+ }
262
+
263
+ private static final class RenderObjectHandle {
264
+
265
+ private final RenderObject obj;
266
+ private final RenderObjectType type;
267
+
268
+ private RenderObjectHandle(Shader shader) {
269
+ obj = shader;
270
+ type = RenderObjectType.SHADER;
271
+ }
272
+
273
+ private RenderObjectHandle(Modifier modifier) {
274
+ obj = modifier;
275
+ type = RenderObjectType.MODIFIER;
276
+ }
277
+
278
+ private RenderObjectHandle(Tesselatable tesselatable) {
279
+ obj = new Geometry(tesselatable);
280
+ type = RenderObjectType.GEOMETRY;
281
+ }
282
+
283
+ private RenderObjectHandle(PrimitiveList prims) {
284
+ obj = new Geometry(prims);
285
+ type = RenderObjectType.GEOMETRY;
286
+ }
287
+
288
+ private RenderObjectHandle(Instance instance) {
289
+ obj = instance;
290
+ type = RenderObjectType.INSTANCE;
291
+ }
292
+
293
+ private RenderObjectHandle(LightSource light) {
294
+ obj = light;
295
+ type = RenderObjectType.LIGHT;
296
+ }
297
+
298
+ private RenderObjectHandle(Camera camera) {
299
+ obj = camera;
300
+ type = RenderObjectType.CAMERA;
301
+ }
302
+
303
+ private RenderObjectHandle(Options options) {
304
+ obj = options;
305
+ type = RenderObjectType.OPTIONS;
306
+ }
307
+
308
+ private boolean update(ParameterList pl, SunflowAPI api) {
309
+ return obj.update(pl, api);
310
+ }
311
+
312
+ private String typeName() {
313
+ return type.name().toLowerCase(Locale.ENGLISH);
314
+ }
315
+
316
+ private Shader getShader() {
317
+ return (type == RenderObjectType.SHADER) ? (Shader) obj : null;
318
+ }
319
+
320
+ private Modifier getModifier() {
321
+ return (type == RenderObjectType.MODIFIER) ? (Modifier) obj : null;
322
+ }
323
+
324
+ private Geometry getGeometry() {
325
+ return (type == RenderObjectType.GEOMETRY) ? (Geometry) obj : null;
326
+ }
327
+
328
+ private Instance getInstance() {
329
+ return (type == RenderObjectType.INSTANCE) ? (Instance) obj : null;
330
+ }
331
+
332
+ private LightSource getLight() {
333
+ return (type == RenderObjectType.LIGHT) ? (LightSource) obj : null;
334
+ }
335
+
336
+ private Camera getCamera() {
337
+ return (type == RenderObjectType.CAMERA) ? (Camera) obj : null;
338
+ }
339
+
340
+ private Options getOptions() {
341
+ return (type == RenderObjectType.OPTIONS) ? (Options) obj : null;
342
+ }
343
+ }
344
+ }