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,132 @@
1
+ package org.sunflow.math;
2
+
3
+ /**
4
+ * Vector versions of the standard noise functions. These are provided to
5
+ * emulate standard renderman calls.This code was adapted mainly from the
6
+ * mrclasses package by Gonzalo Garramuno
7
+ * (http://sourceforge.net/projects/mrclasses/).
8
+ */
9
+ public class PerlinVector {
10
+
11
+ private static final float P1x = 0.34f;
12
+ private static final float P1y = 0.66f;
13
+ private static final float P1z = 0.237f;
14
+ private static final float P2x = 0.011f;
15
+ private static final float P2y = 0.845f;
16
+ private static final float P2z = 0.037f;
17
+ private static final float P3x = 0.34f;
18
+ private static final float P3y = 0.12f;
19
+ private static final float P3z = 0.9f;
20
+
21
+ public static final Vector3 snoise(float x) {
22
+ return new Vector3(PerlinScalar.snoise(x + P1x), PerlinScalar.snoise(x + P2x), PerlinScalar.snoise(x + P3x));
23
+ }
24
+
25
+ public static final Vector3 snoise(float x, float y) {
26
+ return new Vector3(PerlinScalar.snoise(x + P1x, y + P1y), PerlinScalar.snoise(x + P2x, y + P2y), PerlinScalar.snoise(x + P3x, y + P3y));
27
+ }
28
+
29
+ public static final Vector3 snoise(float x, float y, float z) {
30
+ return new Vector3(PerlinScalar.snoise(x + P1x, y + P1y, z + P1z), PerlinScalar.snoise(x + P2x, y + P2y, z + P2z), PerlinScalar.snoise(x + P3x, y + P3y, z + P3z));
31
+ }
32
+
33
+ public static final Vector3 snoise(float x, float y, float z, float t) {
34
+ return new Vector3(PerlinScalar.snoise(x + P1x, y + P1y, z + P1z, t), PerlinScalar.snoise(x + P2x, y + P2y, z + P2z, t), PerlinScalar.snoise(x + P3x, y + P3y, z + P3z, t));
35
+ }
36
+
37
+ public static final Vector3 snoise(Point2 p) {
38
+ return snoise(p.x, p.y);
39
+ }
40
+
41
+ public static final Vector3 snoise(Point3 p) {
42
+ return snoise(p.x, p.y, p.z);
43
+ }
44
+
45
+ public static final Vector3 snoise(Point3 p, float t) {
46
+ return snoise(p.x, p.y, p.z, t);
47
+ }
48
+
49
+ public static final Vector3 noise(float x) {
50
+ return new Vector3(PerlinScalar.noise(x + P1x), PerlinScalar.noise(x + P2x), PerlinScalar.noise(x + P3x));
51
+ }
52
+
53
+ public static final Vector3 noise(float x, float y) {
54
+ return new Vector3(PerlinScalar.noise(x + P1x, y + P1y), PerlinScalar.noise(x + P2x, y + P2y), PerlinScalar.noise(x + P3x, y + P3y));
55
+ }
56
+
57
+ public static final Vector3 noise(float x, float y, float z) {
58
+ return new Vector3(PerlinScalar.noise(x + P1x, y + P1y, z + P1z), PerlinScalar.noise(x + P2x, y + P2y, z + P2z), PerlinScalar.noise(x + P3x, y + P3y, z + P3z));
59
+ }
60
+
61
+ public static final Vector3 noise(float x, float y, float z, float t) {
62
+ return new Vector3(PerlinScalar.noise(x + P1x, y + P1y, z + P1z, t), PerlinScalar.noise(x + P2x, y + P2y, z + P2z, t), PerlinScalar.noise(x + P3x, y + P3y, z + P3z, t));
63
+ }
64
+
65
+ public static final Vector3 noise(Point2 p) {
66
+ return noise(p.x, p.y);
67
+ }
68
+
69
+ public static final Vector3 noise(Point3 p) {
70
+ return noise(p.x, p.y, p.z);
71
+ }
72
+
73
+ public static final Vector3 noise(Point3 p, float t) {
74
+ return noise(p.x, p.y, p.z, t);
75
+ }
76
+
77
+ public static final Vector3 pnoise(float x, float period) {
78
+ return new Vector3(PerlinScalar.pnoise(x + P1x, period), PerlinScalar.pnoise(x + P2x, period), PerlinScalar.pnoise(x + P3x, period));
79
+ }
80
+
81
+ public static final Vector3 pnoise(float x, float y, float w, float h) {
82
+ return new Vector3(PerlinScalar.pnoise(x + P1x, y + P1y, w, h), PerlinScalar.pnoise(x + P2x, y + P2y, w, h), PerlinScalar.pnoise(x + P3x, y + P3y, w, h));
83
+ }
84
+
85
+ public static final Vector3 pnoise(float x, float y, float z, float w, float h, float d) {
86
+ return new Vector3(PerlinScalar.pnoise(x + P1x, y + P1y, z + P1z, w, h, d), PerlinScalar.pnoise(x + P2x, y + P2y, z + P2z, w, h, d), PerlinScalar.pnoise(x + P3x, y + P3y, z + P3z, w, h, d));
87
+ }
88
+
89
+ public static final Vector3 pnoise(float x, float y, float z, float t, float w, float h, float d, float p) {
90
+ return new Vector3(PerlinScalar.pnoise(x + P1x, y + P1y, z + P1z, t, w, h, d, p), PerlinScalar.pnoise(x + P2x, y + P2y, z + P2z, t, w, h, d, p), PerlinScalar.pnoise(x + P3x, y + P3y, z + P3z, t, w, h, d, p));
91
+ }
92
+
93
+ public static final Vector3 pnoise(Point2 p, float periodx, float periody) {
94
+ return pnoise(p.x, p.y, periodx, periody);
95
+ }
96
+
97
+ public static final Vector3 pnoise(Point3 p, Vector3 period) {
98
+ return pnoise(p.x, p.y, p.z, period.x, period.y, period.z);
99
+ }
100
+
101
+ public static final Vector3 pnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
102
+ return pnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
103
+ }
104
+
105
+ public static final Vector3 spnoise(float x, float period) {
106
+ return new Vector3(PerlinScalar.spnoise(x + P1x, period), PerlinScalar.spnoise(x + P2x, period), PerlinScalar.spnoise(x + P3x, period));
107
+ }
108
+
109
+ public static final Vector3 spnoise(float x, float y, float w, float h) {
110
+ return new Vector3(PerlinScalar.spnoise(x + P1x, y + P1y, w, h), PerlinScalar.spnoise(x + P2x, y + P2y, w, h), PerlinScalar.spnoise(x + P3x, y + P3y, w, h));
111
+ }
112
+
113
+ public static final Vector3 spnoise(float x, float y, float z, float w, float h, float d) {
114
+ return new Vector3(PerlinScalar.spnoise(x + P1x, y + P1y, z + P1z, w, h, d), PerlinScalar.spnoise(x + P2x, y + P2y, z + P2z, w, h, d), PerlinScalar.spnoise(x + P3x, y + P3y, z + P3z, w, h, d));
115
+ }
116
+
117
+ public static final Vector3 spnoise(float x, float y, float z, float t, float w, float h, float d, float p) {
118
+ return new Vector3(PerlinScalar.spnoise(x + P1x, y + P1y, z + P1z, t, w, h, d, p), PerlinScalar.spnoise(x + P2x, y + P2y, z + P2z, t, w, h, d, p), PerlinScalar.spnoise(x + P3x, y + P3y, z + P3z, t, w, h, d, p));
119
+ }
120
+
121
+ public static final Vector3 spnoise(Point2 p, float periodx, float periody) {
122
+ return spnoise(p.x, p.y, periodx, periody);
123
+ }
124
+
125
+ public static final Vector3 spnoise(Point3 p, Vector3 period) {
126
+ return spnoise(p.x, p.y, p.z, period.x, period.y, period.z);
127
+ }
128
+
129
+ public static final Vector3 spnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
130
+ return spnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
131
+ }
132
+ }
@@ -0,0 +1,36 @@
1
+ package org.sunflow.math;
2
+
3
+ public final class Point2 {
4
+
5
+ public float x, y;
6
+
7
+ public Point2() {
8
+ }
9
+
10
+ public Point2(float x, float y) {
11
+ this.x = x;
12
+ this.y = y;
13
+ }
14
+
15
+ public Point2(Point2 p) {
16
+ x = p.x;
17
+ y = p.y;
18
+ }
19
+
20
+ public final Point2 set(float x, float y) {
21
+ this.x = x;
22
+ this.y = y;
23
+ return this;
24
+ }
25
+
26
+ public final Point2 set(Point2 p) {
27
+ x = p.x;
28
+ y = p.y;
29
+ return this;
30
+ }
31
+
32
+ @Override
33
+ public final String toString() {
34
+ return String.format("(%.2f, %.2f)", x, y);
35
+ }
36
+ }
@@ -0,0 +1,133 @@
1
+ package org.sunflow.math;
2
+
3
+ public final class Point3 {
4
+
5
+ public float x, y, z;
6
+
7
+ public Point3() {
8
+ }
9
+
10
+ public Point3(float x, float y, float z) {
11
+ this.x = x;
12
+ this.y = y;
13
+ this.z = z;
14
+ }
15
+
16
+ public Point3(Point3 p) {
17
+ x = p.x;
18
+ y = p.y;
19
+ z = p.z;
20
+ }
21
+
22
+ public float get(int i) {
23
+ switch (i) {
24
+ case 0:
25
+ return x;
26
+ case 1:
27
+ return y;
28
+ default:
29
+ return z;
30
+ }
31
+ }
32
+
33
+ public final float distanceTo(Point3 p) {
34
+ float dx = x - p.x;
35
+ float dy = y - p.y;
36
+ float dz = z - p.z;
37
+ return (float) Math.sqrt((dx * dx) + (dy * dy) + (dz * dz));
38
+ }
39
+
40
+ public final float distanceTo(float px, float py, float pz) {
41
+ float dx = x - px;
42
+ float dy = y - py;
43
+ float dz = z - pz;
44
+ return (float) Math.sqrt((dx * dx) + (dy * dy) + (dz * dz));
45
+ }
46
+
47
+ public final float distanceToSquared(Point3 p) {
48
+ float dx = x - p.x;
49
+ float dy = y - p.y;
50
+ float dz = z - p.z;
51
+ return (dx * dx) + (dy * dy) + (dz * dz);
52
+ }
53
+
54
+ public final float distanceToSquared(float px, float py, float pz) {
55
+ float dx = x - px;
56
+ float dy = y - py;
57
+ float dz = z - pz;
58
+ return (dx * dx) + (dy * dy) + (dz * dz);
59
+ }
60
+
61
+ public final Point3 set(float x, float y, float z) {
62
+ this.x = x;
63
+ this.y = y;
64
+ this.z = z;
65
+ return this;
66
+ }
67
+
68
+ public final Point3 set(Point3 p) {
69
+ x = p.x;
70
+ y = p.y;
71
+ z = p.z;
72
+ return this;
73
+ }
74
+
75
+ public static final Point3 add(Point3 p, Vector3 v, Point3 dest) {
76
+ dest.x = p.x + v.x;
77
+ dest.y = p.y + v.y;
78
+ dest.z = p.z + v.z;
79
+ return dest;
80
+ }
81
+
82
+ public static final Vector3 sub(Point3 p1, Point3 p2, Vector3 dest) {
83
+ dest.x = p1.x - p2.x;
84
+ dest.y = p1.y - p2.y;
85
+ dest.z = p1.z - p2.z;
86
+ return dest;
87
+ }
88
+
89
+ public static final Point3 mid(Point3 p1, Point3 p2, Point3 dest) {
90
+ dest.x = 0.5f * (p1.x + p2.x);
91
+ dest.y = 0.5f * (p1.y + p2.y);
92
+ dest.z = 0.5f * (p1.z + p2.z);
93
+ return dest;
94
+ }
95
+
96
+ public static final Point3 blend(Point3 p0, Point3 p1, float blend, Point3 dest) {
97
+ dest.x = (1 - blend) * p0.x + blend * p1.x;
98
+ dest.y = (1 - blend) * p0.y + blend * p1.y;
99
+ dest.z = (1 - blend) * p0.z + blend * p1.z;
100
+ return dest;
101
+ }
102
+
103
+ public static final Vector3 normal(Point3 p0, Point3 p1, Point3 p2) {
104
+ float edge1x = p1.x - p0.x;
105
+ float edge1y = p1.y - p0.y;
106
+ float edge1z = p1.z - p0.z;
107
+ float edge2x = p2.x - p0.x;
108
+ float edge2y = p2.y - p0.y;
109
+ float edge2z = p2.z - p0.z;
110
+ float nx = edge1y * edge2z - edge1z * edge2y;
111
+ float ny = edge1z * edge2x - edge1x * edge2z;
112
+ float nz = edge1x * edge2y - edge1y * edge2x;
113
+ return new Vector3(nx, ny, nz);
114
+ }
115
+
116
+ public static final Vector3 normal(Point3 p0, Point3 p1, Point3 p2, Vector3 dest) {
117
+ float edge1x = p1.x - p0.x;
118
+ float edge1y = p1.y - p0.y;
119
+ float edge1z = p1.z - p0.z;
120
+ float edge2x = p2.x - p0.x;
121
+ float edge2y = p2.y - p0.y;
122
+ float edge2z = p2.z - p0.z;
123
+ dest.x = edge1y * edge2z - edge1z * edge2y;
124
+ dest.y = edge1z * edge2x - edge1x * edge2z;
125
+ dest.z = edge1x * edge2y - edge1y * edge2x;
126
+ return dest;
127
+ }
128
+
129
+ @Override
130
+ public final String toString() {
131
+ return String.format("(%.2f, %.2f, %.2f)", x, y, z);
132
+ }
133
+ }
@@ -0,0 +1,209 @@
1
+ package org.sunflow.math;
2
+
3
+ import org.sunflow.system.UI;
4
+ import org.sunflow.system.UI.Module;
5
+
6
+ public final class QMC {
7
+
8
+ public static final int MAX_SIGMA_ORDER = 15;
9
+ private static final int NUM = 128;
10
+ private static final int[][] SIGMA = new int[NUM][];
11
+ private static final int[] PRIMES = new int[NUM];
12
+ private static final int[] FIBONACCI = new int[47];
13
+ private static final double[] FIBONACCI_INV = new double[FIBONACCI.length];
14
+ private static final double[] KOROBOV = new double[NUM];
15
+
16
+ static {
17
+ UI.printInfo(Module.QMC, "Initializing Faure scrambling tables ...");
18
+ // build table of first primes
19
+ PRIMES[0] = 2;
20
+ for (int i = 1; i < PRIMES.length; i++) {
21
+ PRIMES[i] = nextPrime(PRIMES[i - 1]);
22
+ }
23
+ int[][] table = new int[PRIMES[PRIMES.length - 1] + 1][];
24
+ table[2] = new int[2];
25
+ table[2][0] = 0;
26
+ table[2][1] = 1;
27
+ for (int i = 3; i <= PRIMES[PRIMES.length - 1]; i++) {
28
+ table[i] = new int[i];
29
+ if ((i & 1) == 0) {
30
+ int[] prev = table[i >> 1];
31
+ for (int j = 0; j < prev.length; j++) {
32
+ table[i][j] = 2 * prev[j];
33
+ }
34
+ for (int j = 0; j < prev.length; j++) {
35
+ table[i][prev.length + j] = 2 * prev[j] + 1;
36
+ }
37
+ } else {
38
+ int[] prev = table[i - 1];
39
+ int med = (i - 1) >> 1;
40
+ for (int j = 0; j < med; j++) {
41
+ table[i][j] = prev[j] + ((prev[j] >= med) ? 1 : 0);
42
+ }
43
+ table[i][med] = med;
44
+ for (int j = 0; j < med; j++) {
45
+ table[i][med + j + 1] = prev[j + med] + ((prev[j + med] >= med) ? 1 : 0);
46
+ }
47
+ }
48
+ }
49
+ for (int i = 0; i < PRIMES.length; i++) {
50
+ int p = PRIMES[i];
51
+ SIGMA[i] = new int[p];
52
+ System.arraycopy(table[p], 0, SIGMA[i], 0, p);
53
+ }
54
+ UI.printInfo(Module.QMC, "Initializing lattice tables ...");
55
+ FIBONACCI[0] = 0;
56
+ FIBONACCI[1] = 1;
57
+ for (int i = 2; i < FIBONACCI.length; i++) {
58
+ FIBONACCI[i] = FIBONACCI[i - 1] + FIBONACCI[i - 2];
59
+ FIBONACCI_INV[i] = 1.0 / FIBONACCI[i];
60
+ }
61
+ KOROBOV[0] = 1;
62
+ for (int i = 1; i < KOROBOV.length; i++) {
63
+ KOROBOV[i] = 203 * KOROBOV[i - 1];
64
+ }
65
+ }
66
+
67
+ private static final int nextPrime(int p) {
68
+ p = p + (p & 1) + 1;
69
+ while (true) {
70
+ int div = 3;
71
+ boolean isPrime = true;
72
+ while (isPrime && ((div * div) <= p)) {
73
+ isPrime = ((p % div) != 0);
74
+ div += 2;
75
+ }
76
+ if (isPrime) {
77
+ return p;
78
+ }
79
+ p += 2;
80
+ }
81
+ }
82
+
83
+ private QMC() {
84
+ }
85
+
86
+ public static double riVDC(int bits, int r) {
87
+ bits = (bits << 16) | (bits >>> 16);
88
+ bits = ((bits & 0x00ff00ff) << 8) | ((bits & 0xff00ff00) >>> 8);
89
+ bits = ((bits & 0x0f0f0f0f) << 4) | ((bits & 0xf0f0f0f0) >>> 4);
90
+ bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >>> 2);
91
+ bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >>> 1);
92
+ bits ^= r;
93
+ return (double) (bits & 0xFFFFFFFFL) / (double) 0x100000000L;
94
+ }
95
+
96
+ public static double riS(int i, int r) {
97
+ for (int v = 1 << 31; i != 0; i >>>= 1, v ^= v >>> 1) {
98
+ if ((i & 1) != 0) {
99
+ r ^= v;
100
+ }
101
+ }
102
+ return (double) (r & 0xFFFFFFFFL) / (double) 0x100000000L;
103
+ }
104
+
105
+ public static double riLP(int i, int r) {
106
+ for (int v = 1 << 31; i != 0; i >>>= 1, v |= v >>> 1) {
107
+ if ((i & 1) != 0) {
108
+ r ^= v;
109
+ }
110
+ }
111
+ return (double) (r & 0xFFFFFFFFL) / (double) 0x100000000L;
112
+ }
113
+
114
+ public static final double halton(int d, int i) {
115
+ // generalized Halton sequence
116
+ switch (d) {
117
+ case 0: {
118
+ i = (i << 16) | (i >>> 16);
119
+ i = ((i & 0x00ff00ff) << 8) | ((i & 0xff00ff00) >>> 8);
120
+ i = ((i & 0x0f0f0f0f) << 4) | ((i & 0xf0f0f0f0) >>> 4);
121
+ i = ((i & 0x33333333) << 2) | ((i & 0xcccccccc) >>> 2);
122
+ i = ((i & 0x55555555) << 1) | ((i & 0xaaaaaaaa) >>> 1);
123
+ return (double) (i & 0xFFFFFFFFL) / (double) 0x100000000L;
124
+ }
125
+ case 1: {
126
+ double v = 0;
127
+ double inv = 1.0 / 3;
128
+ double p;
129
+ int n;
130
+ for (p = inv, n = i; n != 0; p *= inv, n /= 3) {
131
+ v += (n % 3) * p;
132
+ }
133
+ return v;
134
+ }
135
+ default:
136
+ }
137
+ int base = PRIMES[d];
138
+ int[] perm = SIGMA[d];
139
+ double v = 0;
140
+ double inv = 1.0 / base;
141
+ double p;
142
+ int n;
143
+ for (p = inv, n = i; n != 0; p *= inv, n /= base) {
144
+ v += perm[n % base] * p;
145
+ }
146
+ return v;
147
+ }
148
+
149
+ /**
150
+ * Compute mod(x,1), assuming that x is positive or 0.
151
+ *
152
+ * @param x any number >= 0
153
+ * @return mod(x,1)
154
+ */
155
+ public static final double mod1(double x) {
156
+ // assumes x >= 0
157
+ return x - (int) x;
158
+ }
159
+
160
+ /**
161
+ * Compute sigma function used to seed QMC sequence trees. The sigma table
162
+ * is exactly 2^order elements long, and therefore i should be in the: [0,
163
+ * 2^order) interval. This function is equal to 2^order*halton(0,i)
164
+ *
165
+ * @param i index
166
+ * @param order
167
+ * @return sigma function
168
+ */
169
+ public static final int sigma(int i, int order) {
170
+ assert order > 0 && order < 32;
171
+ assert i >= 0 && i < (1 << order);
172
+ i = (i << 16) | (i >>> 16);
173
+ i = ((i & 0x00ff00ff) << 8) | ((i & 0xff00ff00) >>> 8);
174
+ i = ((i & 0x0f0f0f0f) << 4) | ((i & 0xf0f0f0f0) >>> 4);
175
+ i = ((i & 0x33333333) << 2) | ((i & 0xcccccccc) >>> 2);
176
+ i = ((i & 0x55555555) << 1) | ((i & 0xaaaaaaaa) >>> 1);
177
+ return i >>> (32 - order);
178
+ }
179
+
180
+ public static final int getFibonacciRank(int n) {
181
+ int k = 3;
182
+ while (FIBONACCI[k] <= n) {
183
+ k++;
184
+ }
185
+ return k - 1;
186
+ }
187
+
188
+ public static final int fibonacci(int k) {
189
+ return FIBONACCI[k];
190
+ }
191
+
192
+ public static final double fibonacciLattice(int k, int i, int d) {
193
+ return d == 0 ? i * FIBONACCI_INV[k] : mod1((i * FIBONACCI[k - 1]) * FIBONACCI_INV[k]);
194
+ }
195
+
196
+ public static final double reducedCPRotation(int k, int d, double x0, double x1) {
197
+ int j1 = FIBONACCI[2 * ((k - 1) >> 2) + 1];
198
+ int j2 = FIBONACCI[2 * ((k + 1) >> 2)];
199
+ if (d == 1) {
200
+ j1 = ((j1 * FIBONACCI[k - 1]) % FIBONACCI[k]);
201
+ j2 = ((j2 * FIBONACCI[k - 1]) % FIBONACCI[k]) - FIBONACCI[k];
202
+ }
203
+ return (x0 * j1 + x1 * j2) * FIBONACCI_INV[k];
204
+ }
205
+
206
+ public static final double korobovLattice(int m, int i, int d) {
207
+ return mod1(i * KOROBOV[d] / (1 << m));
208
+ }
209
+ }