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,27 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Shader;
6
+ import org.sunflow.core.ShadingState;
7
+ import org.sunflow.image.Color;
8
+ import org.sunflow.math.Vector3;
9
+
10
+ public class IDShader implements Shader {
11
+
12
+ @Override
13
+ public boolean update(ParameterList pl, SunflowAPI api) {
14
+ return true;
15
+ }
16
+
17
+ @Override
18
+ public Color getRadiance(ShadingState state) {
19
+ Vector3 n = state.getNormal();
20
+ float f = n == null ? 1.0f : Math.abs(state.getRay().dot(n));
21
+ return new Color(state.getInstance().hashCode()).mul(f);
22
+ }
23
+
24
+ @Override
25
+ public void scatterPhoton(ShadingState state, Color power) {
26
+ }
27
+ }
@@ -0,0 +1,68 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Ray;
6
+ import org.sunflow.core.Shader;
7
+ import org.sunflow.core.ShadingState;
8
+ import org.sunflow.image.Color;
9
+ import org.sunflow.math.Vector3;
10
+
11
+ public class MirrorShader implements Shader {
12
+
13
+ private Color color;
14
+
15
+ public MirrorShader() {
16
+ color = Color.WHITE;
17
+ }
18
+
19
+ @Override
20
+ public boolean update(ParameterList pl, SunflowAPI api) {
21
+ color = pl.getColor("color", color);
22
+ return true;
23
+ }
24
+
25
+ @Override
26
+ public Color getRadiance(ShadingState state) {
27
+ if (!state.includeSpecular()) {
28
+ return Color.BLACK;
29
+ }
30
+ state.faceforward();
31
+ float cos = state.getCosND();
32
+ float dn = 2 * cos;
33
+ Vector3 refDir = new Vector3();
34
+ refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
35
+ refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
36
+ refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
37
+ Ray refRay = new Ray(state.getPoint(), refDir);
38
+
39
+ // compute Fresnel term
40
+ cos = 1 - cos;
41
+ float cos2 = cos * cos;
42
+ float cos5 = cos2 * cos2 * cos;
43
+ Color ret = Color.white();
44
+ ret.sub(color);
45
+ ret.mul(cos5);
46
+ ret.add(color);
47
+ return ret.mul(state.traceReflection(refRay, 0));
48
+ }
49
+
50
+ @Override
51
+ public void scatterPhoton(ShadingState state, Color power) {
52
+ float avg = color.getAverage();
53
+ double rnd = state.getRandom(0, 0, 1);
54
+ if (rnd >= avg) {
55
+ return;
56
+ }
57
+ state.faceforward();
58
+ float cos = state.getCosND();
59
+ power.mul(color).mul(1.0f / avg);
60
+ // photon is reflected
61
+ float dn = 2 * cos;
62
+ Vector3 dir = new Vector3();
63
+ dir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
64
+ dir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
65
+ dir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
66
+ state.traceReflectionPhoton(new Ray(state.getPoint(), dir), power);
67
+ }
68
+ }
@@ -0,0 +1,32 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Shader;
6
+ import org.sunflow.core.ShadingState;
7
+ import org.sunflow.image.Color;
8
+ import org.sunflow.math.Vector3;
9
+
10
+ public class NormalShader implements Shader {
11
+
12
+ @Override
13
+ public boolean update(ParameterList pl, SunflowAPI api) {
14
+ return true;
15
+ }
16
+
17
+ @Override
18
+ public Color getRadiance(ShadingState state) {
19
+ Vector3 n = state.getNormal();
20
+ if (n == null) {
21
+ return Color.BLACK;
22
+ }
23
+ float r = (n.x + 1) * 0.5f;
24
+ float g = (n.y + 1) * 0.5f;
25
+ float b = (n.z + 1) * 0.5f;
26
+ return new Color(r, g, b);
27
+ }
28
+
29
+ @Override
30
+ public void scatterPhoton(ShadingState state, Color power) {
31
+ }
32
+ }
@@ -0,0 +1,89 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Ray;
6
+ import org.sunflow.core.Shader;
7
+ import org.sunflow.core.ShadingState;
8
+ import org.sunflow.image.Color;
9
+ import org.sunflow.math.OrthoNormalBasis;
10
+ import org.sunflow.math.Vector3;
11
+
12
+ public class PhongShader implements Shader {
13
+
14
+ private Color diff;
15
+ private Color spec;
16
+ private float power;
17
+ private int numRays;
18
+
19
+ public PhongShader() {
20
+ diff = Color.GRAY;
21
+ spec = Color.GRAY;
22
+ power = 20;
23
+ numRays = 4;
24
+ }
25
+
26
+ @Override
27
+ public boolean update(ParameterList pl, SunflowAPI api) {
28
+ diff = pl.getColor("diffuse", diff);
29
+ spec = pl.getColor("specular", spec);
30
+ power = pl.getFloat("power", power);
31
+ numRays = pl.getInt("samples", numRays);
32
+ return true;
33
+ }
34
+
35
+ protected Color getDiffuse(ShadingState state) {
36
+ return diff;
37
+ }
38
+
39
+ @Override
40
+ public Color getRadiance(ShadingState state) {
41
+ // make sure we are on the right side of the material
42
+ state.faceforward();
43
+ // setup lighting
44
+ state.initLightSamples();
45
+ state.initCausticSamples();
46
+ // execute shader
47
+ return state.diffuse(getDiffuse(state)).add(state.specularPhong(spec, power, numRays));
48
+ }
49
+
50
+ @Override
51
+ public void scatterPhoton(ShadingState state, Color power) {
52
+ // make sure we are on the right side of the material
53
+ state.faceforward();
54
+ Color d = getDiffuse(state);
55
+ state.storePhoton(state.getRay().getDirection(), power, d);
56
+ float avgD = d.getAverage();
57
+ float avgS = spec.getAverage();
58
+ double rnd = state.getRandom(0, 0, 1);
59
+ if (rnd < avgD) {
60
+ // photon is scattered diffusely
61
+ power.mul(d).mul(1.0f / avgD);
62
+ OrthoNormalBasis onb = state.getBasis();
63
+ double u = 2 * Math.PI * rnd / avgD;
64
+ double v = state.getRandom(0, 1, 1);
65
+ float s = (float) Math.sqrt(v);
66
+ float s1 = (float) Math.sqrt(1.0f - v);
67
+ Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
68
+ w = onb.transform(w, new Vector3());
69
+ state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
70
+ } else if (rnd < avgD + avgS) {
71
+ // photon is scattered specularly
72
+ float dn = 2.0f * state.getCosND();
73
+ // reflected direction
74
+ Vector3 refDir = new Vector3();
75
+ refDir.x = (dn * state.getNormal().x) + state.getRay().dx;
76
+ refDir.y = (dn * state.getNormal().y) + state.getRay().dy;
77
+ refDir.z = (dn * state.getNormal().z) + state.getRay().dz;
78
+ power.mul(spec).mul(1.0f / avgS);
79
+ OrthoNormalBasis onb = state.getBasis();
80
+ double u = 2 * Math.PI * (rnd - avgD) / avgS;
81
+ double v = state.getRandom(0, 1, 1);
82
+ float s = (float) Math.pow(v, 1 / (this.power + 1));
83
+ float s1 = (float) Math.sqrt(1 - s * s);
84
+ Vector3 w = new Vector3((float) Math.cos(u) * s1, (float) Math.sin(u) * s1, s);
85
+ w = onb.transform(w, new Vector3());
86
+ state.traceReflectionPhoton(new Ray(state.getPoint(), w), power);
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,30 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Shader;
6
+ import org.sunflow.core.ShadingState;
7
+ import org.sunflow.image.Color;
8
+ import org.sunflow.math.Vector3;
9
+
10
+ public class PrimIDShader implements Shader {
11
+
12
+ private static final Color[] BORDERS = {Color.RED, Color.GREEN,
13
+ Color.BLUE, Color.YELLOW, Color.CYAN, Color.MAGENTA};
14
+
15
+ @Override
16
+ public boolean update(ParameterList pl, SunflowAPI api) {
17
+ return true;
18
+ }
19
+
20
+ @Override
21
+ public Color getRadiance(ShadingState state) {
22
+ Vector3 n = state.getNormal();
23
+ float f = n == null ? 1.0f : Math.abs(state.getRay().dot(n));
24
+ return BORDERS[state.getPrimitiveID() % BORDERS.length].copy().mul(f);
25
+ }
26
+
27
+ @Override
28
+ public void scatterPhoton(ShadingState state, Color power) {
29
+ }
30
+ }
@@ -0,0 +1,63 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Ray;
6
+ import org.sunflow.core.Shader;
7
+ import org.sunflow.core.ShadingState;
8
+ import org.sunflow.image.Color;
9
+ import org.sunflow.math.OrthoNormalBasis;
10
+ import org.sunflow.math.Vector3;
11
+
12
+ public class QuickGrayShader implements Shader {
13
+
14
+ public QuickGrayShader() {
15
+ }
16
+
17
+ @Override
18
+ public boolean update(ParameterList pl, SunflowAPI api) {
19
+ return true;
20
+ }
21
+
22
+ @Override
23
+ public Color getRadiance(ShadingState state) {
24
+ if (state.getNormal() == null) {
25
+ // if this shader has been applied to an infinite instance because
26
+ // of shader overrides
27
+ // run the default shader, otherwise, just shade black
28
+ return state.getShader() != this ? state.getShader().getRadiance(state) : Color.BLACK;
29
+ }
30
+ // make sure we are on the right side of the material
31
+ state.faceforward();
32
+ // setup lighting
33
+ state.initLightSamples();
34
+ state.initCausticSamples();
35
+ return state.diffuse(Color.GRAY);
36
+ }
37
+
38
+ @Override
39
+ public void scatterPhoton(ShadingState state, Color power) {
40
+ Color diffuse;
41
+ // make sure we are on the right side of the material
42
+ if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0) {
43
+ state.getNormal().negate();
44
+ state.getGeoNormal().negate();
45
+ }
46
+ diffuse = Color.GRAY;
47
+ state.storePhoton(state.getRay().getDirection(), power, diffuse);
48
+ float avg = diffuse.getAverage();
49
+ double rnd = state.getRandom(0, 0, 1);
50
+ if (rnd < avg) {
51
+ // photon is scattered
52
+ power.mul(diffuse).mul(1.0f / avg);
53
+ OrthoNormalBasis onb = state.getBasis();
54
+ double u = 2 * Math.PI * rnd / avg;
55
+ double v = state.getRandom(0, 1, 1);
56
+ float s = (float) Math.sqrt(v);
57
+ float s1 = (float) Math.sqrt(1.0 - v);
58
+ Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
59
+ w = onb.transform(w, new Vector3());
60
+ state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,98 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Ray;
6
+ import org.sunflow.core.Shader;
7
+ import org.sunflow.core.ShadingState;
8
+ import org.sunflow.image.Color;
9
+ import org.sunflow.math.OrthoNormalBasis;
10
+ import org.sunflow.math.Vector3;
11
+
12
+ public class ShinyDiffuseShader implements Shader {
13
+
14
+ private Color diff;
15
+ private float refl;
16
+
17
+ public ShinyDiffuseShader() {
18
+ diff = Color.GRAY;
19
+ refl = 0.5f;
20
+ }
21
+
22
+ @Override
23
+ public boolean update(ParameterList pl, SunflowAPI api) {
24
+ diff = pl.getColor("diffuse", diff);
25
+ refl = pl.getFloat("shiny", refl);
26
+ return true;
27
+ }
28
+
29
+ public Color getDiffuse(ShadingState state) {
30
+ return diff;
31
+ }
32
+
33
+ @Override
34
+ public Color getRadiance(ShadingState state) {
35
+ // make sure we are on the right side of the material
36
+ state.faceforward();
37
+ // direct lighting
38
+ state.initLightSamples();
39
+ state.initCausticSamples();
40
+ Color d = getDiffuse(state);
41
+ Color lr = state.diffuse(d);
42
+ if (!state.includeSpecular()) {
43
+ return lr;
44
+ }
45
+ float cos = state.getCosND();
46
+ float dn = 2 * cos;
47
+ Vector3 refDir = new Vector3();
48
+ refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
49
+ refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
50
+ refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
51
+ Ray refRay = new Ray(state.getPoint(), refDir);
52
+ // compute Fresnel term
53
+ cos = 1 - cos;
54
+ float cos2 = cos * cos;
55
+ float cos5 = cos2 * cos2 * cos;
56
+
57
+ Color ret = Color.white();
58
+ Color r = d.copy().mul(refl);
59
+ ret.sub(r);
60
+ ret.mul(cos5);
61
+ ret.add(r);
62
+ return lr.add(ret.mul(state.traceReflection(refRay, 0)));
63
+ }
64
+
65
+ @Override
66
+ public void scatterPhoton(ShadingState state, Color power) {
67
+ Color diffuse;
68
+ // make sure we are on the right side of the material
69
+ state.faceforward();
70
+ diffuse = getDiffuse(state);
71
+ state.storePhoton(state.getRay().getDirection(), power, diffuse);
72
+ float d = diffuse.getAverage();
73
+ float r = d * refl;
74
+ double rnd = state.getRandom(0, 0, 1);
75
+ if (rnd < d) {
76
+ // photon is scattered
77
+ power.mul(diffuse).mul(1.0f / d);
78
+ OrthoNormalBasis onb = state.getBasis();
79
+ double u = 2 * Math.PI * rnd / d;
80
+ double v = state.getRandom(0, 1, 1);
81
+ float s = (float) Math.sqrt(v);
82
+ float s1 = (float) Math.sqrt(1.0 - v);
83
+ Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
84
+ w = onb.transform(w, new Vector3());
85
+ state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
86
+ } else if (rnd < d + r) {
87
+ float cos = -Vector3.dot(state.getNormal(), state.getRay().getDirection());
88
+ power.mul(diffuse).mul(1.0f / d);
89
+ // photon is reflected
90
+ float dn = 2 * cos;
91
+ Vector3 dir = new Vector3();
92
+ dir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
93
+ dir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
94
+ dir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
95
+ state.traceReflectionPhoton(new Ray(state.getPoint(), dir), power);
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,24 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.Shader;
6
+ import org.sunflow.core.ShadingState;
7
+ import org.sunflow.image.Color;
8
+
9
+ public class SimpleShader implements Shader {
10
+
11
+ @Override
12
+ public boolean update(ParameterList pl, SunflowAPI api) {
13
+ return true;
14
+ }
15
+
16
+ @Override
17
+ public Color getRadiance(ShadingState state) {
18
+ return new Color(Math.abs(state.getRay().dot(state.getNormal())));
19
+ }
20
+
21
+ @Override
22
+ public void scatterPhoton(ShadingState state, Color power) {
23
+ }
24
+ }
@@ -0,0 +1,31 @@
1
+ package org.sunflow.core.shader;
2
+
3
+ import org.sunflow.SunflowAPI;
4
+ import org.sunflow.core.ParameterList;
5
+ import org.sunflow.core.ShadingState;
6
+ import org.sunflow.core.Texture;
7
+ import org.sunflow.core.TextureCache;
8
+ import org.sunflow.image.Color;
9
+
10
+ public class TexturedAmbientOcclusionShader extends AmbientOcclusionShader {
11
+
12
+ private Texture tex;
13
+
14
+ public TexturedAmbientOcclusionShader() {
15
+ tex = null;
16
+ }
17
+
18
+ @Override
19
+ public boolean update(ParameterList pl, SunflowAPI api) {
20
+ String filename = pl.getString("texture", null);
21
+ if (filename != null) {
22
+ tex = TextureCache.getTexture(api.resolveTextureFilename(filename), false);
23
+ }
24
+ return tex != null && super.update(pl, api);
25
+ }
26
+
27
+ @Override
28
+ public Color getBrightColor(ShadingState state) {
29
+ return tex.getPixel(state.getUV().x, state.getUV().y);
30
+ }
31
+ }