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,79 @@
1
+ package joons;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.List;
5
+
6
+ public class JRFiller {
7
+
8
+ private final List<Float> vertices;
9
+ private final List<Integer> triangleIndices;
10
+ private final List<Float> spheres;
11
+ private final List<Float> points;
12
+
13
+ private final String fillType;
14
+ public float[] p; //array of parameters
15
+ public int np = 0; //number of parameters
16
+
17
+ public JRFiller(String fillType, float... params) {
18
+ vertices = new ArrayList<>();
19
+ triangleIndices = new ArrayList<>();
20
+ spheres = new ArrayList<>();
21
+ points = new ArrayList<>();
22
+
23
+ this.fillType = fillType;
24
+ p = params;
25
+ np = p.length;
26
+ }
27
+
28
+ public String getType() {
29
+ return fillType;
30
+ }
31
+
32
+ public List<Float> getVertices() {
33
+ return vertices;
34
+ }
35
+
36
+ private void writeTriangleIndices() {
37
+ for (int i = 0; i < (vertices.size() / 9); i++) {
38
+ //vertices/3 = number of 3d points
39
+ //vertices/9 = number of triangles
40
+ triangleIndices.add(i * 3);
41
+ triangleIndices.add(i * 3 + 1);
42
+ triangleIndices.add(i * 3 + 2);
43
+ }
44
+ }
45
+
46
+ public float[] verticesToArray() {
47
+ float[] v = new float[vertices.size()];
48
+ for (int i = 0; i < vertices.size(); i++) {
49
+ v[i] = vertices.get(i);
50
+ }
51
+ return v;
52
+ }
53
+
54
+ public int[] triangleIndicesToArray() {
55
+ writeTriangleIndices();
56
+ int[] t = new int[triangleIndices.size()];
57
+ for (int i = 0; i < triangleIndices.size(); i++) {
58
+ t[i] = triangleIndices.get(i);
59
+ }
60
+ return t;
61
+ }
62
+
63
+ public void addSphere(float x, float y, float z, float r) {
64
+ spheres.add(x);
65
+ spheres.add(y);
66
+ spheres.add(z);
67
+ spheres.add(r);
68
+ }
69
+
70
+ public List<Float> getSpheres() {
71
+ return spheres;
72
+ }
73
+
74
+ public void addPoint(float x, float y, float z) {
75
+ points.add(x);
76
+ points.add(y);
77
+ points.add(z);
78
+ }
79
+ }
@@ -0,0 +1,141 @@
1
+ package joons;
2
+
3
+ import java.awt.Dimension;
4
+ import java.awt.Graphics;
5
+ import java.awt.image.BufferedImage;
6
+ import javax.swing.JPanel;
7
+
8
+ import org.sunflow.core.Display;
9
+ import org.sunflow.image.Color;
10
+
11
+ import processing.core.PImage;
12
+
13
+ @SuppressWarnings("serial")
14
+ public class JRImagePanel extends JPanel implements Display {
15
+
16
+ private static final int[] BORDERS = {Color.RED.toRGB(),
17
+ Color.GREEN.toRGB(), Color.BLUE.toRGB(), Color.YELLOW.toRGB(),
18
+ Color.CYAN.toRGB(), Color.MAGENTA.toRGB()};
19
+ private BufferedImage image;
20
+ private float xo, yo;
21
+ private float w, h;
22
+ private long repaintCounter;
23
+
24
+ public JRImagePanel() {
25
+ setPreferredSize(new Dimension(640, 480));
26
+ image = null;
27
+ xo = yo = 0;
28
+ w = h = 0;
29
+ }
30
+
31
+ @Override
32
+ public synchronized void imageBegin(int w, int h, int bucketSize) {
33
+ if (image != null && w == image.getWidth() && h == image.getHeight()) {
34
+ // dull image if it has same resolution (75%)
35
+ for (int y = 0; y < h; y++) {
36
+ for (int x = 0; x < w; x++) {
37
+ int rgba = image.getRGB(x, y);
38
+ image.setRGB(x, y, ((rgba & 0xFEFEFEFE) >>> 1) + ((rgba & 0xFCFCFCFC) >>> 2));
39
+ }
40
+ }
41
+ } else {
42
+ // allocate new framebuffer
43
+ image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
44
+ // center
45
+ this.w = w;
46
+ this.h = h;
47
+ xo = yo = 0;
48
+ }
49
+ repaintCounter = System.nanoTime();
50
+ repaint();
51
+ }
52
+
53
+ @Override
54
+ public synchronized void imagePrepare(int x, int y, int w, int h, int id) {
55
+ int border = BORDERS[id % BORDERS.length] | 0xFF000000;
56
+ for (int by = 0; by < h; by++) {
57
+ for (int bx = 0; bx < w; bx++) {
58
+ if (bx == 0 || bx == w - 1) {
59
+ if (5 * by < h || 5 * (h - by - 1) < h) {
60
+ image.setRGB(x + bx, y + by, border);
61
+ }
62
+ } else if (by == 0 || by == h - 1) {
63
+ if (5 * bx < w || 5 * (w - bx - 1) < w) {
64
+ image.setRGB(x + bx, y + by, border);
65
+ }
66
+ }
67
+ }
68
+ }
69
+ repaint();
70
+ }
71
+
72
+ @Override
73
+ public synchronized void imageUpdate(int x, int y, int w, int h, Color[] data, float[] alpha) {
74
+ for (int j = 0, index = 0; j < h; j++) {
75
+ for (int i = 0; i < w; i++, index++) {
76
+ image.setRGB(x + i, y + j, data[index].copy().mul(1.0f / alpha[index]).toNonLinear().toRGBA(alpha[index]));
77
+ }
78
+ }
79
+ repaint();
80
+ }
81
+
82
+ @Override
83
+ public synchronized void imageFill(int x, int y, int w, int h, Color c, float alpha) {
84
+ int rgba = c.copy().mul(1.0f / alpha).toNonLinear().toRGBA(alpha);
85
+ for (int j = 0; j < h; j++) {
86
+ for (int i = 0; i < w; i++) {
87
+ image.setRGB(x + i, y + j, rgba);
88
+ }
89
+ }
90
+ fastRepaint();
91
+ }
92
+
93
+ @Override
94
+ public void imageEnd() {
95
+ repaint();
96
+ }
97
+
98
+ private void fastRepaint() {
99
+ long t = System.nanoTime();
100
+ if (repaintCounter + 125000000 < t) {
101
+ repaintCounter = t;
102
+ repaint();
103
+ }
104
+ }
105
+
106
+ @Override
107
+ public synchronized void paintComponent(Graphics g) {
108
+ super.paintComponent(g);
109
+ if (image == null) {
110
+ return;
111
+ }
112
+ int x = Math.round(xo + (getWidth() - w) * 0.5f);
113
+ int y = Math.round(yo + (getHeight() - h) * 0.5f);
114
+ int iw = Math.round(w);
115
+ int ih = Math.round(h);
116
+ int x0 = x - 1;
117
+ int y0 = y - 1;
118
+ int x1 = x + iw + 1;
119
+ int y1 = y + ih + 1;
120
+ g.setColor(java.awt.Color.WHITE);
121
+ g.drawLine(x0, y0, x1, y0);
122
+ g.drawLine(x1, y0, x1, y1);
123
+ g.drawLine(x1, y1, x0, y1);
124
+ g.drawLine(x0, y1, x0, y0);
125
+ g.drawImage(image, x, y, iw, ih, java.awt.Color.BLACK, this);
126
+ }
127
+
128
+ public PImage getInversedImage() {
129
+ int iw = Math.round(w);
130
+ int ih = Math.round(h);
131
+ PImage inversed = new PImage(iw, ih);
132
+ for (int i = 0; i < ih; i++) {
133
+ for (int j = 0; j < iw; j++) {
134
+ //PApplet.println(i);
135
+ //PApplet.println(j);
136
+ inversed.pixels[(ih - i - 1) * iw + j] = image.getRGB(j, i);
137
+ }
138
+ }
139
+ return inversed;
140
+ }
141
+ }
@@ -0,0 +1,183 @@
1
+ package joons;
2
+
3
+ import java.util.ArrayList;
4
+
5
+ import static joons.JRStatics.*;
6
+ import processing.core.*;
7
+ import processing.opengl.PGraphics3D;
8
+
9
+ /*
10
+ * The purpose of JRRecorder is to geometry used in P5 sketch, and reproduce them in sunflow.
11
+ * Remember, JRRecorder is a secondary PGraphics3D object, and methods are echoed to it by PApplet.
12
+ * Say, when you call PApplet.method(), PApplet will do something like:
13
+ * public void method() { primaryPG3D.method(); secondaryPG3D.method(); }
14
+ */
15
+ public class JRRecorder extends PGraphics3D {
16
+
17
+ private boolean writingVertices = false;
18
+ private ArrayList<Float> tempVertices;
19
+ private final PApplet app;
20
+ int kind, vertCount;
21
+
22
+ /**
23
+ *
24
+ * @param parent
25
+ */
26
+ public JRRecorder(final PApplet parent) {
27
+ //standard construction for a PGraphics object
28
+ app = parent;
29
+ setParent(app);
30
+ setPrimary(false);
31
+ setSize(app.width, app.height);
32
+ init();
33
+
34
+ }
35
+
36
+ private void init() {
37
+ initializeFillers(); //emptying out fillers
38
+ FILLERS_ARE_VALID = true; //true unless proven false
39
+ tempVertices = new ArrayList<>(); //emptying out vertices
40
+ writingVertices = false; //init beginShape()
41
+ }
42
+
43
+ @Override
44
+ public void beginDraw() {
45
+ //this method is echoed before every draw() loop.
46
+ init();
47
+ }
48
+
49
+ @Override
50
+ public void endDraw() {
51
+ //We need this empty override.
52
+ }
53
+
54
+ @Override
55
+ public void perspective(float fov, float aspect, float zNear, float zFar) {
56
+ //zNear and zFar are unused in sunflow.
57
+ FOV = fov;
58
+ ASPECT = aspect;
59
+ }
60
+
61
+ @Override
62
+ public void beginShape() {
63
+ PApplet.println("Joons-Renderer: Please use beginShape(TRIANGLES) or beginShape(QUADS).");
64
+ PApplet.println("Joons-Renderer: Your vertices will be rendered using beginShape(TRIANGLES).");
65
+ beginShape(PConstants.TRIANGLES);
66
+ }
67
+
68
+ @Override
69
+ public void beginShape(int kind) {
70
+ this.kind = kind;
71
+ writingVertices = true;
72
+ vertCount = 0;
73
+ }
74
+
75
+ @Override
76
+ public void vertex(float x, float y, float z) {
77
+ if (writingVertices) {
78
+ vertCount++;
79
+ tempVertices.add(x);
80
+ tempVertices.add(y);
81
+ tempVertices.add(z);
82
+
83
+ if (kind == PConstants.QUADS && vertCount == 4) {
84
+ //if more than 1 quad, simply start a new one.
85
+ endShape();
86
+ beginShape(PConstants.QUADS);
87
+ }
88
+ }
89
+ }
90
+
91
+ @Override
92
+ public void endShape() {
93
+ if (kind == PConstants.QUADS && vertCount == 4) {
94
+ //adding vertices to make two triangles from four points
95
+ //abcd -> abc dac
96
+ tempVertices.add(tempVertices.get(0));//ax
97
+ tempVertices.add(tempVertices.get(1));//ay
98
+ tempVertices.add(tempVertices.get(2));//az
99
+ tempVertices.add(tempVertices.get(6));//cx
100
+ tempVertices.add(tempVertices.get(7));//cy
101
+ tempVertices.add(tempVertices.get(8));//cz
102
+ }
103
+ //divide by 3, because 3 numbers make 1 point.
104
+ for (int i = 0; i < tempVertices.size() / 3; i++) {
105
+ float[] tCoord = applyTransform(
106
+ app,
107
+ tempVertices.get(i * 3),
108
+ tempVertices.get(i * 3 + 1),
109
+ tempVertices.get(i * 3 + 2)
110
+ );
111
+ getCurrentFiller().getVertices().add(tCoord[0]);
112
+ getCurrentFiller().getVertices().add(tCoord[1]);
113
+ getCurrentFiller().getVertices().add(tCoord[2]);
114
+ }
115
+ writingVertices = false;
116
+ vertCount = 0;
117
+ tempVertices = new ArrayList<>(); //emptying out vertices
118
+ }
119
+
120
+ //implementations of 3D primitives
121
+ @Override
122
+ public void box(float d) {
123
+ box(d, d, d);
124
+ }
125
+
126
+ @Override
127
+ public void box(float width, float height, float depth) {
128
+ float w = width / 2;
129
+ float h = height / 2;
130
+ float d = depth / 2;
131
+
132
+ beginShape(PConstants.QUADS);// top
133
+ vertex(w, h, d);
134
+ vertex(-w, h, d);
135
+ vertex(-w, -h, d);
136
+ vertex(w, -h, d);
137
+ endShape();
138
+
139
+ beginShape(PConstants.QUADS);// +x side
140
+ vertex(w, h, d);
141
+ vertex(w, -h, d);
142
+ vertex(w, -h, -d);
143
+ vertex(w, h, -d);
144
+ endShape();
145
+
146
+ beginShape(PConstants.QUADS);// -x side
147
+ vertex(-w, h, -d);
148
+ vertex(-w, -h, -d);
149
+ vertex(-w, -h, d);
150
+ vertex(-w, h, d);
151
+ endShape();
152
+
153
+ beginShape(PConstants.QUADS);// +y side
154
+ vertex(w, h, d);
155
+ vertex(w, h, -d);
156
+ vertex(-w, h, -d);
157
+ vertex(-w, h, d);
158
+ endShape();
159
+
160
+ beginShape(PConstants.QUADS);// -y side
161
+ vertex(-w, -h, d);
162
+ vertex(-w, -h, -d);
163
+ vertex(w, -h, -d);
164
+ vertex(w, -h, d);
165
+ endShape();
166
+
167
+ beginShape(PConstants.QUADS);// bottom
168
+ vertex(-w, h, -d);
169
+ vertex(w, h, -d);
170
+ vertex(w, -h, -d);
171
+ vertex(-w, -h, -d);
172
+ endShape();
173
+ }
174
+
175
+ @Override
176
+ public void sphere(float r) {
177
+ //Sunflow seems to offer an optimized render for a perfect sphere,
178
+ //meaning no triangle polygonal mess from Processing
179
+ float[] sph = applyTransform(app, 0, 0, 0);
180
+ getCurrentFiller().addSphere(sph[0], sph[1], sph[2], r);
181
+ }
182
+
183
+ }
@@ -0,0 +1,199 @@
1
+ package joons;
2
+
3
+ import java.util.ArrayList;
4
+ import java.util.List;
5
+ import processing.core.PApplet;
6
+ import processing.core.PImage;
7
+ import processing.core.PMatrix3D;
8
+
9
+ public final class JRStatics {
10
+ //This class contains all the shared variables and constants,
11
+ //and also the default values for them.
12
+
13
+ //sys constants
14
+ public static final String JR_VERSION = "v1.02";
15
+ public static final String UNRENDERED_FILE_NAME = "captured.png";
16
+ public static final String RENDERED_INV_FILE_NAME = "rendered.png";
17
+
18
+ //sys variables, default unless modified
19
+ // public static PApplet app;
20
+ public static float FOV, ASPECT;
21
+ public static PImage IMG_RENDERED;
22
+ public static List<JRFiller> fillers;
23
+ public static boolean FILLERS_ARE_VALID;
24
+ public static boolean CORNELL_BOX_IS_CALLED = false;
25
+ public static boolean GI_IS_CALLED = false;
26
+ public static boolean GI_AMB_OCC_IS_CALLED = false;
27
+
28
+ //user interface keys
29
+ public static final String IPR = "ipr";
30
+ public static final String BUCKET = "bucket";
31
+ public static final String SRGB_NONLINEAR = "sRGB nonlinear";
32
+ public static final String GI_AMB_OCC = "gi_ambient_occlusion"; // "ambocc" is the proper sunflow parameter.
33
+ public static final String GI_INSTANT = "gi_instant"; //"igi" is the proper sunflow parameter.
34
+ public static final String CORNELL_BOX = "cornell_box";
35
+ public static final String CONSTANT = "constant";
36
+ public static final String DIFFUSE = "diffuse";
37
+ public static final String SHINY = "shiny"; //"shiny_diffuse" is the proper sunflow parameter.
38
+ public static final String MIRROR = "mirror";
39
+ public static final String GLASS = "glass";
40
+ public static final String PHONG = "phong";
41
+ public static final String AMBIENT_OCCLUSION = "ambient_occlusion";
42
+ public static final String LIGHT = "light";
43
+ public static final String SUNSKY = "sunsky"; // Sunsky lighting
44
+
45
+ //sunflow image settings variables, default unless modified
46
+ public static double SIZE_MULTIPLIER = 1;
47
+ public static String SAMPLER = BUCKET;
48
+ public static int AA_MIN = -2;
49
+ public static int AA_MAX = 0;
50
+ public static int AA_SAMPLES = 1;
51
+ public static int CAUSTICS_EMIT = 1000000;
52
+ public static int CAUSTICS_GATHER = 100;
53
+ public static float CAUSTICS_RADIUS = 0.5f;
54
+ public static int TRACE_DEPTH_DIFF = 2;
55
+ public static int TRACE_DEPTH_REFL = 4;
56
+ public static int TRACE_DEPTH_REFR = 4;
57
+ public static float FOCAL_DISTANCE = -1; //uninitialized -1
58
+ public static float LENS_RADIUS = 1f;
59
+
60
+ //sunflow GI instant variables
61
+ public static int GI_INSTANT_SAMPLES = 16;
62
+ public static int GI_INSTANT_SETS = 1;
63
+ public static float GI_INSTANT_C = 0.00003f;
64
+ public static int GI_INSTANT_BIAS_SAMPLES = 0;
65
+
66
+ //sunflow GI ambient occlusion variables
67
+ public static float GI_AMB_OCC_BRIGHT_R = 0.5f;
68
+ public static float GI_AMB_OCC_BRIGHT_G = 0.5f;
69
+ public static float GI_AMB_OCC_BRIGHT_B = 0.5f;
70
+ public static float GI_AMB_OCC_DARK_R = 0;
71
+ public static float GI_AMB_OCC_DARK_G = 0;
72
+ public static float GI_AMB_OCC_DARK_B = 0;
73
+ public static float GI_AMB_OCC_MAX_DIST = 100;
74
+ public static int GI_AMB_OCC_SAMPLES = 32;
75
+
76
+ //background primitive variables
77
+ public static float BG_R = 0.7f;
78
+ public static float BG_G = 0.7f;
79
+ public static float BG_B = 0.7f;
80
+
81
+ //final default values
82
+ public static final float DEF_RADIANCE = 5;
83
+ public static final float DEF_RGB = 255;
84
+ public static final float DEF_GLASS_ALPHA = 150;
85
+ public static final int DEF_SAMPLES = 16;
86
+ public static final float DEF_CORB_RADIANCE = 20;
87
+ public static final float DEF_CORB_COLOR_1 = 220;
88
+ public static final float DEF_CORB_COLOR_2 = 130;
89
+ public static final float DEF_AMB_OCC_MAX_DIST = 50;
90
+
91
+ // Default values for Sunsky lighting.
92
+ public static final float[] DEF_SUNSKY_UP = {0, -1, 0};
93
+ public static final float[] DEF_SUNSKY_EAST = {1, 0, 0};
94
+ public static final float[] DEF_SUNSKY_DIR = {-0.5f, -0.6f, 0.5f};
95
+ public static final int DEF_SUNSKY_SAMPLES = 128;
96
+ public static final float DEF_SUNSKY_TURBIDITY = 6.0f;
97
+
98
+ //static methods
99
+ public static JRFiller getCurrentFiller(){
100
+ return fillers.get(fillers.size() - 1);
101
+ }
102
+
103
+ public static void initializeFillers(){
104
+ fillers = new ArrayList<>();
105
+ //Default shader that kicks in when no shader has been declared.
106
+ fillers.add(new JRFiller(DIFFUSE, DEF_RGB, DEF_RGB, DEF_RGB));
107
+ }
108
+
109
+ public static float[] applyTransform(PApplet app, float x, float y, float z){
110
+ PMatrix3D tr = (PMatrix3D)app.getMatrix();
111
+ float tx = x * tr.m00 + y * tr.m01 + z * tr.m02 + tr.m03;
112
+ float ty = x * tr.m10 + y * tr.m11 + z * tr.m12 + tr.m13;
113
+ float tz = x * tr.m20 + y * tr.m21 + z * tr.m22 + tr.m23;
114
+ return new float[]{tx, ty, tz};
115
+ }
116
+
117
+ //error message strings
118
+ public static final String JR_VERSION_PRINT
119
+ = "Joons-Renderer : " + JR_VERSION + ".";
120
+
121
+ public static final String IMAGE_SAMPLER_ERROR
122
+ = "Joons-Renderer : ERROR, Unknown sampler type. Use either \"ipr\" or \"bucket\" with setSampler() in setup().";
123
+
124
+ public static final String IMAGE_AA_ERROR = String.join("\n"
125
+ , "Joons-Renderer : ERROR, aaMax must be equal to or greater than aaMin."
126
+ , "Joons-Renderer : Use setAA(int aaMin, int aaMax), or"
127
+ , "Joons-Renderer : setAA(int aaMin, int aaMax, int aaSamples)."
128
+ );
129
+
130
+ public static final String GI_INSTANT_ERROR = String.join("\n"
131
+ , "Joons-Renderer : ERROR, background type \"gi_instant\" must have 0 or 4 parameters."
132
+ , "Joons-Renderer : int samples, int sets, float b, float biasSamples."
133
+ );
134
+
135
+ public static final String GI_AMB_OCC_ERROR = String.join("\n"
136
+ , "Joons-Renderer : ERROR, background type \"gi_ambient_occlusion\" must have 0 or 8 parameters."
137
+ , "Joons-Renderer : float bright R, G, B, dark R, G, B, float maxDistance, int samples."
138
+ );
139
+
140
+ public static final String FILLER_UNKOWN_ERROR = String.join("\n"
141
+ , "Joons-Renderer : ERROR, Unknown fill type."
142
+ , "Joons-Renderer : Choose from \"constant\", \"diffuse\", \"shiny\", \"mirror\", \"glass\", \"phong\","
143
+ , "Joons-Renderer : \"ambient_occlusion\" and \"light\"."
144
+ );
145
+
146
+ public static final String FILLER_LIGHT_ERROR = String.join("\n"
147
+ , "Joons-Renderer : ERROR, fill type \"light\" must have 0, 3 or 4 parameters."
148
+ , "Joons-Renderer : float radiance R, G, B, (3 params)"
149
+ , "Joons-Renderer : int samples. (4 params)"
150
+ );
151
+
152
+ public static final String FILLER_CONSTANT_ERROR = String.join("\n"
153
+ , "Joons-Renderer : ERROR, fill type \"constant\" must have 0 or 3 parameters."
154
+ , "Joons-Renderer : float R, G, B."
155
+ );
156
+
157
+ public static final String FILLER_DIFFUSE_ERROR = String.join("\n"
158
+ , "Joons-Renderer : ERROR, fill type \"diffuse\" must have 0 or 3 parameters."
159
+ , "Joons-Renderer : float R, G, B."
160
+ );
161
+
162
+ public static final String FILLER_SHINY_ERROR = String.join("\n"
163
+ , "Joons-Renderer : ERROR, fill type \"shiny\" must have 0, 3 or 4 parameters."
164
+ , "Joons-Renderer : float R, G, B, (3 params);,"
165
+ , "Joons-Renderer : float shininess. (4 params)"
166
+ );
167
+
168
+ public static final String FILLER_MIRROR_ERROR = String.join("\n"
169
+ , "Joons-Renderer : ERROR, fill type \"mirror\" must have 0 or 3 parameters."
170
+ , "Joons-Renderer : float R, G, B."
171
+ );
172
+
173
+ public static final String FILLER_GLASS_ERROR = String.join("\n"
174
+ , "Joons-Renderer : ERROR, fill type \"glass\" must have 0, 3, 4 or 8 parameters."
175
+ , "Joons-Renderer : float R, G, B, (3 params);,"
176
+ , "Joons-Renderer : float indexOfRefraction, (4 params);,"
177
+ , "Joons-Renderer : float absorptionDistance, float absorption R, G, B. (8 params)"
178
+ );
179
+
180
+ public static final String FILLER_PHONG_ERROR = String.join("\n"
181
+ , "Joons-Renderer : ERROR, fill type \"phong\" must have 0, 3, 6 or 8 parameters."
182
+ , "Joons-Renderer : float diffuse R, G, B, (3 params);,"
183
+ , "Joons-Renderer : float specular R, G, B, (6 params);,"
184
+ , "Joons-Renderer : float specularityHardness, float reflectionBluriness. (8 params)"
185
+ );
186
+
187
+ public static final String FILLER_AMB_OCC_ERROR = String.join("\n"
188
+ , "Joons-Renderer : ERROR, fill type \"ambient_occlusion\" must have 0, 3 or 8 parameters."
189
+ , "Joons-Renderer : float bright R, G, B, (3 params);,"
190
+ , "Joons-Renderer : float dark R, G, B, float maxDistance, int samples. (8 params)"
191
+ );
192
+
193
+ public static final String CORNELL_BOX_ERROR = String.join("\n"
194
+ , "Joons-Renderer : ERROR, background type \"cornell_box\" must have 3, 7 or 22 parameters."
195
+ , "Joons-Renderer : float width, height, depth, (3 params);,"
196
+ , "Joons-Renderer : float radiance R, G, B, int samples, (7 params);,"
197
+ , "Joons-Renderer : float left R, G, B, right R, G, B, back R, G, B, top R, G, B, bottom R, G, B. (21 params)"
198
+ );
199
+ }