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,29 @@
1
+ package org.sunflow.core;
2
+
3
+ /**
4
+ * Represents a mapping from the 3D scene onto the final image. A camera lens is
5
+ * responsible for determining what ray to cast through each pixel.
6
+ */
7
+ public interface CameraLens extends RenderObject {
8
+
9
+ /**
10
+ * Create a new {@link Ray ray}to be cast through pixel (x,y) on the image
11
+ * plane. Two sampling parameters are provided for lens sampling. They are
12
+ * guarenteed to be in the interval [0,1). They can be used to perturb the
13
+ * position of the source of the ray on the lens of the camera for DOF
14
+ * effects. A third sampling parameter is provided for motion blur effects.
15
+ * Note that the {@link Camera} class already handles camera movement motion
16
+ * blur. Rays should be generated in camera space - that is, with the eye at
17
+ * the origin, looking down the -Z axis, with +Y pointing up.
18
+ *
19
+ * @param x x coordinate of the (sub)pixel
20
+ * @param y y coordinate of the (sub)pixel
21
+ * @param imageWidth image width in pixels
22
+ * @param imageHeight image height in pixels
23
+ * @param lensX x lens sampling parameter
24
+ * @param lensY y lens sampling parameter
25
+ * @param time time sampling parameter
26
+ * @return a new ray passing through the given pixel
27
+ */
28
+ public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time);
29
+ }
@@ -0,0 +1,15 @@
1
+ package org.sunflow.core;
2
+
3
+ /**
4
+ * This class is a generic interface to caustic photon mapping capabilities.
5
+ */
6
+ public interface CausticPhotonMapInterface extends PhotonStore {
7
+
8
+ /**
9
+ * Retrieve caustic photons at the specified shading location and add them
10
+ * as diffuse light samples.
11
+ *
12
+ * @param state
13
+ */
14
+ void getSamples(ShadingState state);
15
+ }
@@ -0,0 +1,78 @@
1
+ package org.sunflow.core;
2
+
3
+ import org.sunflow.image.Color;
4
+
5
+ /**
6
+ * Represents an image output device.
7
+ */
8
+ public interface Display {
9
+
10
+ /**
11
+ * This is called before an image is rendered to indicate how large the
12
+ * rendered image will be. This allows the display driver to write out image
13
+ * headers or allocate surfaces. Bucket size will be 0 when called from a
14
+ * non-bucket based source.
15
+ *
16
+ * @param w width of the rendered image in pixels
17
+ * @param h height of the rendered image in pixels
18
+ * @param bucketSize size of the buckets in pixels
19
+ */
20
+ void imageBegin(int w, int h, int bucketSize);
21
+
22
+ /**
23
+ * Prepare the specified area to be rendered. This may be used to highlight
24
+ * the work in progress area or simply to setup the display driver to
25
+ * receive the specified portion of the image
26
+ *
27
+ * @param x x coordinate of the bucket within the image
28
+ * @param y y coordinate of the bucket within the image
29
+ * @param w width of the bucket in pixels
30
+ * @param h height of the bucket in pixels
31
+ * @param id unique identifier corresponding to the thread which invoked
32
+ * this call
33
+ */
34
+ void imagePrepare(int x, int y, int w, int h, int id);
35
+
36
+ /**
37
+ * Update the current image with a bucket of data. The region is guarenteed
38
+ * to be within the bounds created by the call to imageBegin. No clipping is
39
+ * necessary. Colors are passed in unprocessed. It is up the display driver
40
+ * to do any type of quantization, gamma compensation or tone-mapping
41
+ * needed. The array of colors will be exactly
42
+ * <code>w * h</code> long and in row major order.
43
+ *
44
+ * @param x x coordinate of the bucket within the image
45
+ * @param y y coordinate of the bucket within the image
46
+ * @param w width of the bucket in pixels
47
+ * @param h height of the bucket in pixels
48
+ * @param data bucket data, this array will be exactly <code>w * h</code>
49
+ * long
50
+ * @param alpha pixel coverage data, this array will be exactly
51
+ * <code>w * h</code> long
52
+ */
53
+ void imageUpdate(int x, int y, int w, int h, Color[] data, float[] alpha);
54
+
55
+ /**
56
+ * Update the current image with a region of flat color. This is used by
57
+ * progressive rendering to render progressively smaller regions of the
58
+ * screen which will overlap. The region is guarenteed to be within the
59
+ * bounds created by the call to imageBegin. No clipping is necessary.
60
+ * Colors are passed in unprocessed. It is up the display driver to do any
61
+ * type of quantization , gamma compensation or tone-mapping needed.
62
+ *
63
+ * @param x x coordinate of the region within the image
64
+ * @param y y coordinate of the region within the image
65
+ * @param w with of the region in pixels
66
+ * @param h height of the region in pixels
67
+ * @param c color to fill the region with
68
+ * @param alpha pixel coverage
69
+ */
70
+ void imageFill(int x, int y, int w, int h, Color c, float alpha);
71
+
72
+ /**
73
+ * This call is made after the image has been rendered. This allows the
74
+ * display driver to close any open files, write the image to disk or flush
75
+ * any other type of buffers.
76
+ */
77
+ void imageEnd();
78
+ }
@@ -0,0 +1,27 @@
1
+ package org.sunflow.core;
2
+
3
+ /**
4
+ * Represents a multi-pixel image filter kernel.
5
+ */
6
+ public interface Filter {
7
+
8
+ /**
9
+ * Width in pixels of the filter extents. The filter will be applied to the
10
+ * range of pixels within a box of
11
+ * <code>+/- getSize() / 2</code> around the center of the pixel.
12
+ *
13
+ * @return width in pixels
14
+ */
15
+ public float getSize();
16
+
17
+ /**
18
+ * Get value of the filter at offset (x, y). The filter should never be
19
+ * called with values beyond its extents but should return 0 in those cases
20
+ * anyway.
21
+ *
22
+ * @param x x offset in pixels
23
+ * @param y y offset in pixels
24
+ * @return value of the filter at the specified location
25
+ */
26
+ public float get(float x, float y);
27
+ }
@@ -0,0 +1,42 @@
1
+ package org.sunflow.core;
2
+
3
+ import org.sunflow.image.Color;
4
+
5
+ /**
6
+ * This represents a global illumination algorithm. It provides an interface to
7
+ * compute indirect diffuse bounces of light and make those results available to
8
+ * shaders.
9
+ */
10
+ public interface GIEngine {
11
+
12
+ /**
13
+ * This is an optional method for engines that contain a secondary
14
+ * illumination engine which can return an approximation of the global
15
+ * radiance in the scene (like a photon map). Engines can safely return
16
+ * <code>Color.BLACK</code> if they can't or don't wish to support this.
17
+ *
18
+ * @param state shading state
19
+ * @return color approximating global radiance
20
+ */
21
+ public Color getGlobalRadiance(ShadingState state);
22
+
23
+ /**
24
+ * Initialize the engine. This is called before rendering begins.
25
+ *
26
+ * @return <code>true</code> if the init phase succeeded, <code>false</code>
27
+ * otherwise
28
+ */
29
+ public boolean init(Options options, Scene scene);
30
+
31
+ /**
32
+ * Return the incomming irradiance due to indirect diffuse illumination at
33
+ * the specified surface point.
34
+ *
35
+ * @param state current render state describing the point to be computed
36
+ * @param diffuseReflectance diffuse albedo of the point being shaded, this
37
+ * can be used for importance tracking
38
+ * @return irradiance from indirect diffuse illumination at the specified
39
+ * point
40
+ */
41
+ public Color getIrradiance(ShadingState state, Color diffuseReflectance);
42
+ }
@@ -0,0 +1,157 @@
1
+ package org.sunflow.core;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.accel.NullAccelerator;
5
+ import org.sunflow.math.BoundingBox;
6
+ import org.sunflow.math.Matrix4;
7
+ import org.sunflow.system.UI;
8
+ import org.sunflow.system.UI.Module;
9
+
10
+ /**
11
+ * This class represent a geometric object in its native object space. These
12
+ * object are not rendered directly, they must be instanced via
13
+ * {@link Instance}. This class performs all the bookkeeping needed for
14
+ * on-demand tesselation and acceleration structure building.
15
+ */
16
+ public class Geometry implements RenderObject {
17
+
18
+ private Tesselatable tesselatable;
19
+ private PrimitiveList primitives;
20
+ private AccelerationStructure accel;
21
+ private int builtAccel;
22
+ private int builtTess;
23
+ private String acceltype;
24
+
25
+ /**
26
+ * Create a geometry from the specified tesselatable object. The actual
27
+ * renderable primitives will be generated on demand.
28
+ *
29
+ * @param tesselatable tesselation object
30
+ */
31
+ public Geometry(Tesselatable tesselatable) {
32
+ this.tesselatable = tesselatable;
33
+ primitives = null;
34
+ accel = null;
35
+ builtAccel = 0;
36
+ builtTess = 0;
37
+ acceltype = null;
38
+ }
39
+
40
+ /**
41
+ * Create a geometry from the specified primitive aggregate. The
42
+ * acceleration structure for this object will be built on demand.
43
+ *
44
+ * @param primitives primitive list object
45
+ */
46
+ public Geometry(PrimitiveList primitives) {
47
+ tesselatable = null;
48
+ this.primitives = primitives;
49
+ accel = null;
50
+ builtAccel = 0;
51
+ builtTess = 1; // already tesselated
52
+ }
53
+
54
+ @Override
55
+ public boolean update(ParameterList pl, SunflowAPI api) {
56
+ acceltype = pl.getString("accel", acceltype);
57
+ // clear up old tesselation if it exists
58
+ if (tesselatable != null) {
59
+ primitives = null;
60
+ builtTess = 0;
61
+ }
62
+ // clear acceleration structure so it will be rebuilt
63
+ accel = null;
64
+ builtAccel = 0;
65
+ if (tesselatable != null) {
66
+ return tesselatable.update(pl, api);
67
+ }
68
+ // update primitives
69
+ return primitives.update(pl, api);
70
+ }
71
+
72
+ int getNumPrimitives() {
73
+ return primitives == null ? 0 : primitives.getNumPrimitives();
74
+ }
75
+
76
+ BoundingBox getWorldBounds(Matrix4 o2w) {
77
+ if (primitives == null) {
78
+
79
+ BoundingBox b = tesselatable.getWorldBounds(o2w);
80
+ if (b != null) {
81
+ return b;
82
+ }
83
+ if (builtTess == 0) {
84
+ tesselate();
85
+ }
86
+ if (primitives == null) {
87
+ return null; // failed tesselation, return infinite bounding
88
+ } // box
89
+ }
90
+ return primitives.getWorldBounds(o2w);
91
+ }
92
+
93
+ void intersect(Ray r, IntersectionState state) {
94
+ if (builtTess == 0) {
95
+ tesselate();
96
+ }
97
+ if (builtAccel == 0) {
98
+ build();
99
+ }
100
+ accel.intersect(r, state);
101
+ }
102
+
103
+ private synchronized void tesselate() {
104
+ // double check flag
105
+ if (builtTess != 0) {
106
+ return;
107
+ }
108
+ if (tesselatable != null && primitives == null) {
109
+ UI.printInfo(Module.GEOM, "Tesselating geometry ...");
110
+ primitives = tesselatable.tesselate();
111
+ if (primitives == null) {
112
+ UI.printError(Module.GEOM, "Tesselation failed - geometry will be discarded");
113
+ } else {
114
+ UI.printDetailed(Module.GEOM, "Tesselation produced %d primitives", primitives.getNumPrimitives());
115
+ }
116
+ }
117
+ builtTess = 1;
118
+ }
119
+
120
+ private synchronized void build() {
121
+ // double check flag
122
+ if (builtAccel != 0) {
123
+ return;
124
+ }
125
+ if (primitives != null) {
126
+ int n = primitives.getNumPrimitives();
127
+ if (n >= 1000) {
128
+ UI.printInfo(Module.GEOM, "Building acceleration structure for %d primitives ...", n);
129
+ }
130
+ accel = AccelerationStructureFactory.create(acceltype, n, true);
131
+ accel.build(primitives);
132
+ } else {
133
+ // create an empty accelerator to avoid having to check for null
134
+ // pointers in the intersect method
135
+ accel = new NullAccelerator();
136
+ }
137
+ builtAccel = 1;
138
+ }
139
+
140
+ void prepareShadingState(ShadingState state) {
141
+ primitives.prepareShadingState(state);
142
+ }
143
+
144
+ PrimitiveList getBakingPrimitives() {
145
+ if (builtTess == 0) {
146
+ tesselate();
147
+ }
148
+ if (primitives == null) {
149
+ return null;
150
+ }
151
+ return primitives.getBakingPrimitives();
152
+ }
153
+
154
+ PrimitiveList getPrimitiveList() {
155
+ return primitives;
156
+ }
157
+ }
@@ -0,0 +1,21 @@
1
+ package org.sunflow.core;
2
+
3
+ import org.sunflow.image.Color;
4
+ import org.sunflow.math.Point3;
5
+ import org.sunflow.math.Vector3;
6
+
7
+ /**
8
+ * Represents a global photon map. This is a structure which can return a rough
9
+ * approximation of the diffuse radiance at a given surface point.
10
+ */
11
+ public interface GlobalPhotonMapInterface extends PhotonStore {
12
+
13
+ /**
14
+ * Lookup the global diffuse radiance at the specified surface point.
15
+ *
16
+ * @param p surface position
17
+ * @param n surface normal
18
+ * @return an approximation of global diffuse radiance at this point
19
+ */
20
+ public Color getRadiance(Point3 p, Vector3 n);
21
+ }
@@ -0,0 +1,26 @@
1
+ package org.sunflow.core;
2
+
3
+ /**
4
+ * This interface represents an image sampling algorithm capable of rendering
5
+ * the entire image. Implementations are responsible for anti-aliasing and
6
+ * filtering.
7
+ */
8
+ public interface ImageSampler {
9
+
10
+ /**
11
+ * Prepare the sampler for rendering an image of w x h pixels
12
+ *
13
+ * @param w width of the image
14
+ * @param h height of the image
15
+ */
16
+ public boolean prepare(Options options, Scene scene, int w, int h);
17
+
18
+ /**
19
+ * Render the image to the specified display. The sampler can assume the
20
+ * display has been opened and that it will be closed after the method
21
+ * returns.
22
+ *
23
+ * @param display Display driver to send image data to
24
+ */
25
+ public void render(Display display);
26
+ }
@@ -0,0 +1,224 @@
1
+ package org.sunflow.core;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.math.BoundingBox;
5
+ import org.sunflow.math.Matrix4;
6
+ import org.sunflow.math.MovingMatrix4;
7
+ import org.sunflow.system.UI;
8
+ import org.sunflow.system.UI.Module;
9
+
10
+ /**
11
+ * This represents an instance of a {@link Geometry} into the scene. This class
12
+ * maps object space to world space and maintains a list of shaders and
13
+ * modifiers attached to the surface.
14
+ */
15
+ public class Instance implements RenderObject {
16
+
17
+ private MovingMatrix4 o2w;
18
+ private MovingMatrix4 w2o;
19
+ private BoundingBox bounds;
20
+ private Geometry geometry;
21
+ private Shader[] shaders;
22
+ private Modifier[] modifiers;
23
+
24
+ public Instance() {
25
+ o2w = new MovingMatrix4(null);
26
+ w2o = new MovingMatrix4(null);
27
+ bounds = null;
28
+ geometry = null;
29
+ shaders = null;
30
+ modifiers = null;
31
+ }
32
+
33
+ public static Instance createTemporary(PrimitiveList primitives, Matrix4 transform, Shader shader) {
34
+ Instance i = new Instance();
35
+ i.o2w = new MovingMatrix4(transform);
36
+ i.w2o = i.o2w.inverse();
37
+ if (i.w2o == null) {
38
+ UI.printError(Module.GEOM, "Unable to compute transform inverse");
39
+ return null;
40
+ }
41
+ i.geometry = new Geometry(primitives);
42
+ i.shaders = new Shader[]{shader};
43
+ i.updateBounds();
44
+ return i;
45
+ }
46
+
47
+ public boolean update(ParameterList pl, SunflowAPI api) {
48
+ String geometryName = pl.getString("geometry", null);
49
+ if (geometry == null || geometryName != null) {
50
+ if (geometryName == null) {
51
+ UI.printError(Module.GEOM, "geometry parameter missing - unable to create instance");
52
+ return false;
53
+ }
54
+ geometry = api.lookupGeometry(geometryName);
55
+ if (geometry == null) {
56
+ UI.printError(Module.GEOM, "Geometry \"%s\" was not declared yet - instance is invalid", geometryName);
57
+ return false;
58
+ }
59
+ }
60
+ String[] shaderNames = pl.getStringArray("shaders", null);
61
+ if (shaderNames != null) {
62
+ // new shader names have been provided
63
+ shaders = new Shader[shaderNames.length];
64
+ for (int i = 0; i < shaders.length; i++) {
65
+ shaders[i] = api.lookupShader(shaderNames[i]);
66
+ if (shaders[i] == null) {
67
+ UI.printWarning(Module.GEOM, "Shader \"%s\" was not declared yet - ignoring", shaderNames[i]);
68
+ }
69
+ }
70
+ } else {
71
+ // re-use existing shader array
72
+ }
73
+ String[] modifierNames = pl.getStringArray("modifiers", null);
74
+ if (modifierNames != null) {
75
+ // new modifier names have been provided
76
+ modifiers = new Modifier[modifierNames.length];
77
+ for (int i = 0; i < modifiers.length; i++) {
78
+ modifiers[i] = api.lookupModifier(modifierNames[i]);
79
+ if (modifiers[i] == null) {
80
+ UI.printWarning(Module.GEOM, "Modifier \"%s\" was not declared yet - ignoring", modifierNames[i]);
81
+ }
82
+ }
83
+ }
84
+ o2w = pl.getMovingMatrix("transform", o2w);
85
+ w2o = o2w.inverse();
86
+ if (w2o == null) {
87
+ UI.printError(Module.GEOM, "Unable to compute transform inverse");
88
+ return false;
89
+ }
90
+ return true;
91
+ }
92
+
93
+ /**
94
+ * Recompute world space bounding box of this instance.
95
+ */
96
+ public void updateBounds() {
97
+ bounds = geometry.getWorldBounds(o2w.getData(0));
98
+ for (int i = 1; i < o2w.numSegments(); i++) {
99
+ bounds.include(geometry.getWorldBounds(o2w.getData(i)));
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Checks to see if this instance is relative to the specified geometry.
105
+ *
106
+ * @param g geometry to check against
107
+ * @return <code>true</code> if the instanced geometry is equals to g,
108
+ * <code>false</code> otherwise
109
+ */
110
+ public boolean hasGeometry(Geometry g) {
111
+ return geometry == g;
112
+ }
113
+
114
+ /**
115
+ * Remove the specified shader from the instance's list if it is being used.
116
+ *
117
+ * @param s shader to remove
118
+ */
119
+ public void removeShader(Shader s) {
120
+ if (shaders != null) {
121
+ for (int i = 0; i < shaders.length; i++) {
122
+ if (shaders[i] == s) {
123
+ shaders[i] = null;
124
+ }
125
+ }
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Remove the specified modifier from the instance's list if it is being
131
+ * used.
132
+ *
133
+ * @param m modifier to remove
134
+ */
135
+ public void removeModifier(Modifier m) {
136
+ if (modifiers != null) {
137
+ for (int i = 0; i < modifiers.length; i++) {
138
+ if (modifiers[i] == m) {
139
+ modifiers[i] = null;
140
+ }
141
+ }
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Get the world space bounding box for this instance.
147
+ *
148
+ * @return bounding box in world space
149
+ */
150
+ public BoundingBox getBounds() {
151
+ return bounds;
152
+ }
153
+
154
+ int getNumPrimitives() {
155
+ return geometry.getNumPrimitives();
156
+ }
157
+
158
+ void intersect(Ray r, IntersectionState state) {
159
+ Ray localRay = r.transform(w2o.sample(state.time));
160
+ state.current = this;
161
+ geometry.intersect(localRay, state);
162
+ // FIXME: transfer max distance to current ray
163
+ r.setMax(localRay.getMax());
164
+ }
165
+
166
+ /**
167
+ * Prepare the shading state for shader invocation. This also runs the
168
+ * currently attached surface modifier.
169
+ *
170
+ * @param state shading state to be prepared
171
+ */
172
+ public void prepareShadingState(ShadingState state) {
173
+ geometry.prepareShadingState(state);
174
+ if (state.getNormal() != null && state.getGeoNormal() != null) {
175
+ state.correctShadingNormal();
176
+ }
177
+ // run modifier if it was provided
178
+ if (state.getModifier() != null) {
179
+ state.getModifier().modify(state);
180
+ }
181
+ }
182
+
183
+ /**
184
+ * Get a shader for the instance's list.
185
+ *
186
+ * @param i index into the shader list
187
+ * @return requested shader, or <code>null</code> if the input is invalid
188
+ */
189
+ public Shader getShader(int i) {
190
+ if (shaders == null || i < 0 || i >= shaders.length) {
191
+ return null;
192
+ }
193
+ return shaders[i];
194
+ }
195
+
196
+ /**
197
+ * Get a modifier for the instance's list.
198
+ *
199
+ * @param i index into the modifier list
200
+ * @return requested modifier, or <code>null</code> if the input is invalid
201
+ */
202
+ public Modifier getModifier(int i) {
203
+ if (modifiers == null || i < 0 || i >= modifiers.length) {
204
+ return null;
205
+ }
206
+ return modifiers[i];
207
+ }
208
+
209
+ Matrix4 getObjectToWorld(float time) {
210
+ return o2w.sample(time);
211
+ }
212
+
213
+ Matrix4 getWorldToObject(float time) {
214
+ return w2o.sample(time);
215
+ }
216
+
217
+ PrimitiveList getBakingPrimitives() {
218
+ return geometry.getBakingPrimitives();
219
+ }
220
+
221
+ Geometry getGeometry() {
222
+ return geometry;
223
+ }
224
+ }