joonsrenderer 1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.mvn/extensions.xml +8 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +2 -0
- data/Rakefile +43 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +20 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +15 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
- data/docs/_posts/2017-01-08-welcome.md +78 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +12 -0
- data/docs/assets/Animation.ogv +0 -0
- data/docs/assets/Animation.png +0 -0
- data/docs/assets/basic.png +0 -0
- data/docs/assets/basic_traced.png +0 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/joonsrenderer.gemspec +23 -0
- data/lib/joonsrenderer.rb +12 -0
- data/lib/joonsrenderer/version.rb +3 -0
- data/pom.rb +75 -0
- data/pom.xml +163 -0
- data/src/main/java/SunflowGUI.java +1354 -0
- data/src/main/java/joons/JRFiller.java +79 -0
- data/src/main/java/joons/JRImagePanel.java +141 -0
- data/src/main/java/joons/JRRecorder.java +183 -0
- data/src/main/java/joons/JRStatics.java +199 -0
- data/src/main/java/joons/JoonsRenderer.java +837 -0
- data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
- data/src/main/java/org/sunflow/Benchmark.java +313 -0
- data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
- data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
- data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
- data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
- data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
- data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
- data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
- data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
- data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
- data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/Camera.java +125 -0
- data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
- data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
- data/src/main/java/org/sunflow/core/Display.java +78 -0
- data/src/main/java/org/sunflow/core/Filter.java +27 -0
- data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
- data/src/main/java/org/sunflow/core/Geometry.java +157 -0
- data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
- data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
- data/src/main/java/org/sunflow/core/Instance.java +224 -0
- data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
- data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
- data/src/main/java/org/sunflow/core/LightSample.java +104 -0
- data/src/main/java/org/sunflow/core/LightServer.java +382 -0
- data/src/main/java/org/sunflow/core/LightSource.java +67 -0
- data/src/main/java/org/sunflow/core/Modifier.java +16 -0
- data/src/main/java/org/sunflow/core/Options.java +20 -0
- data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
- data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
- data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
- data/src/main/java/org/sunflow/core/Ray.java +219 -0
- data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
- data/src/main/java/org/sunflow/core/Scene.java +377 -0
- data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
- data/src/main/java/org/sunflow/core/Shader.java +30 -0
- data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
- data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
- data/src/main/java/org/sunflow/core/Statistics.java +85 -0
- data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
- data/src/main/java/org/sunflow/core/Texture.java +128 -0
- data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
- data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
- data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
- data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
- data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
- data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
- data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
- data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
- data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
- data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
- data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
- data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
- data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
- data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
- data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
- data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
- data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
- data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
- data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
- data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
- data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
- data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
- data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
- data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
- data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
- data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
- data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
- data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
- data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
- data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
- data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
- data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
- data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
- data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
- data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
- data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
- data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
- data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
- data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
- data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
- data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
- data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
- data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
- data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
- data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
- data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
- data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
- data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
- data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
- data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
- data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
- data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
- data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
- data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
- data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
- data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
- data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
- data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
- data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
- data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
- data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
- data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
- data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
- data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
- data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
- data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
- data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
- data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
- data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
- data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
- data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
- data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
- data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
- data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
- data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
- data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
- data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
- data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
- data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
- data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
- data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
- data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
- data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
- data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
- data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
- data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
- data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
- data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
- data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
- data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
- data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
- data/src/main/java/org/sunflow/image/Color.java +374 -0
- data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
- data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
- data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
- data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
- data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
- data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
- data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
- data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
- data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
- data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
- data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
- data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
- data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
- data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
- data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
- data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
- data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
- data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
- data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
- data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
- data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
- data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
- data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
- data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
- data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
- data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
- data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
- data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
- data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
- data/src/main/java/org/sunflow/math/Point2.java +36 -0
- data/src/main/java/org/sunflow/math/Point3.java +133 -0
- data/src/main/java/org/sunflow/math/QMC.java +209 -0
- data/src/main/java/org/sunflow/math/Solvers.java +142 -0
- data/src/main/java/org/sunflow/math/Vector3.java +197 -0
- data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
- data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
- data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
- data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
- data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
- data/src/main/java/org/sunflow/system/Memory.java +18 -0
- data/src/main/java/org/sunflow/system/Parser.java +162 -0
- data/src/main/java/org/sunflow/system/Plugins.java +142 -0
- data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
- data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
- data/src/main/java/org/sunflow/system/Timer.java +53 -0
- data/src/main/java/org/sunflow/system/UI.java +112 -0
- data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
- data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
- data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
- data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
- data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
- data/src/main/java/org/sunflow/util/IntArray.java +77 -0
- data/src/test/java/a_maintest.java +129 -0
- metadata +300 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
package org.sunflow.core.bucket;
|
2
|
+
|
3
|
+
import org.sunflow.core.BucketOrder;
|
4
|
+
|
5
|
+
public class InvertedBucketOrder implements BucketOrder {
|
6
|
+
|
7
|
+
private BucketOrder order;
|
8
|
+
|
9
|
+
public InvertedBucketOrder(BucketOrder order) {
|
10
|
+
this.order = order;
|
11
|
+
}
|
12
|
+
|
13
|
+
@Override
|
14
|
+
public int[] getBucketSequence(int nbw, int nbh) {
|
15
|
+
int[] coords = order.getBucketSequence(nbw, nbh);
|
16
|
+
for (int i = 0; i < coords.length / 2; i += 2) {
|
17
|
+
int src = i;
|
18
|
+
int dst = coords.length - 2 - i;
|
19
|
+
int tmp = coords[src + 0];
|
20
|
+
coords[src + 0] = coords[dst + 0];
|
21
|
+
coords[dst + 0] = tmp;
|
22
|
+
tmp = coords[src + 1];
|
23
|
+
coords[src + 1] = coords[dst + 1];
|
24
|
+
coords[dst + 1] = tmp;
|
25
|
+
}
|
26
|
+
return coords;
|
27
|
+
}
|
28
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
package org.sunflow.core.bucket;
|
2
|
+
|
3
|
+
import org.sunflow.core.BucketOrder;
|
4
|
+
|
5
|
+
public class RandomBucketOrder implements BucketOrder {
|
6
|
+
|
7
|
+
@Override
|
8
|
+
public int[] getBucketSequence(int nbw, int nbh) {
|
9
|
+
int[] coords = new int[2 * nbw * nbh];
|
10
|
+
for (int i = 0; i < nbw * nbh; i++) {
|
11
|
+
int by = i / nbw;
|
12
|
+
int bx = i % nbw;
|
13
|
+
if ((by & 1) == 1) {
|
14
|
+
bx = nbw - 1 - bx;
|
15
|
+
}
|
16
|
+
coords[2 * i + 0] = bx;
|
17
|
+
coords[2 * i + 1] = by;
|
18
|
+
}
|
19
|
+
|
20
|
+
long seed = 2463534242L;
|
21
|
+
for (int i = 0; i < coords.length; i++) {
|
22
|
+
// pick 2 random indices
|
23
|
+
seed = xorshift(seed);
|
24
|
+
int src = mod((int) seed, nbw * nbh);
|
25
|
+
seed = xorshift(seed);
|
26
|
+
int dst = mod((int) seed, nbw * nbh);
|
27
|
+
int tmp = coords[2 * src + 0];
|
28
|
+
coords[2 * src + 0] = coords[2 * dst + 0];
|
29
|
+
coords[2 * dst + 0] = tmp;
|
30
|
+
tmp = coords[2 * src + 1];
|
31
|
+
coords[2 * src + 1] = coords[2 * dst + 1];
|
32
|
+
coords[2 * dst + 1] = tmp;
|
33
|
+
}
|
34
|
+
|
35
|
+
return coords;
|
36
|
+
}
|
37
|
+
|
38
|
+
private int mod(int a, int b) {
|
39
|
+
int m = a % b;
|
40
|
+
return (m < 0) ? m + b : m;
|
41
|
+
}
|
42
|
+
|
43
|
+
private long xorshift(long y) {
|
44
|
+
y = y ^ (y << 13);
|
45
|
+
y = y ^ (y >>> 17); // unsigned
|
46
|
+
y = y ^ (y << 5);
|
47
|
+
return y;
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
package org.sunflow.core.bucket;
|
2
|
+
|
3
|
+
import org.sunflow.core.BucketOrder;
|
4
|
+
|
5
|
+
public class RowBucketOrder implements BucketOrder {
|
6
|
+
|
7
|
+
@Override
|
8
|
+
public int[] getBucketSequence(int nbw, int nbh) {
|
9
|
+
int[] coords = new int[2 * nbw * nbh];
|
10
|
+
for (int i = 0; i < nbw * nbh; i++) {
|
11
|
+
int by = i / nbw;
|
12
|
+
int bx = i % nbw;
|
13
|
+
if ((by & 1) == 1) {
|
14
|
+
bx = nbw - 1 - bx;
|
15
|
+
}
|
16
|
+
coords[2 * i + 0] = bx;
|
17
|
+
coords[2 * i + 1] = by;
|
18
|
+
}
|
19
|
+
return coords;
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
package org.sunflow.core.bucket;
|
2
|
+
|
3
|
+
import org.sunflow.core.BucketOrder;
|
4
|
+
|
5
|
+
public class SpiralBucketOrder implements BucketOrder {
|
6
|
+
|
7
|
+
@Override
|
8
|
+
public int[] getBucketSequence(int nbw, int nbh) {
|
9
|
+
int[] coords = new int[2 * nbw * nbh];
|
10
|
+
for (int i = 0; i < nbw * nbh; i++) {
|
11
|
+
int bx, by;
|
12
|
+
int center = (Math.min(nbw, nbh) - 1) / 2;
|
13
|
+
int nx = nbw;
|
14
|
+
int ny = nbh;
|
15
|
+
while (i < (nx * ny)) {
|
16
|
+
nx--;
|
17
|
+
ny--;
|
18
|
+
}
|
19
|
+
int nxny = nx * ny;
|
20
|
+
int minnxny = Math.min(nx, ny);
|
21
|
+
if ((minnxny & 1) == 1) {
|
22
|
+
if (i <= (nxny + ny)) {
|
23
|
+
bx = nx - minnxny / 2;
|
24
|
+
by = -minnxny / 2 + i - nxny;
|
25
|
+
} else {
|
26
|
+
bx = nx - minnxny / 2 - (i - (nxny + ny));
|
27
|
+
by = ny - minnxny / 2;
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
if (i <= (nxny + ny)) {
|
31
|
+
bx = -minnxny / 2;
|
32
|
+
by = ny - minnxny / 2 - (i - nxny);
|
33
|
+
} else {
|
34
|
+
bx = -minnxny / 2 + (i - (nxny + ny));
|
35
|
+
by = -minnxny / 2;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
coords[2 * i + 0] = bx + center;
|
39
|
+
coords[2 * i + 1] = by + center;
|
40
|
+
}
|
41
|
+
return coords;
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
package org.sunflow.core.camera;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.CameraLens;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.Ray;
|
7
|
+
|
8
|
+
public class FisheyeLens implements CameraLens {
|
9
|
+
|
10
|
+
@Override
|
11
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time) {
|
17
|
+
float cx = 2.0f * x / imageWidth - 1.0f;
|
18
|
+
float cy = 2.0f * y / imageHeight - 1.0f;
|
19
|
+
float r2 = cx * cx + cy * cy;
|
20
|
+
if (r2 > 1) {
|
21
|
+
return null; // outside the fisheye
|
22
|
+
}
|
23
|
+
return new Ray(0, 0, 0, cx, cy, (float) -Math.sqrt(1 - r2));
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
package org.sunflow.core.camera;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.CameraLens;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.Ray;
|
7
|
+
|
8
|
+
public class PinholeLens implements CameraLens {
|
9
|
+
|
10
|
+
private float au, av;
|
11
|
+
private float aspect, fov;
|
12
|
+
private float shiftX, shiftY;
|
13
|
+
|
14
|
+
public PinholeLens() {
|
15
|
+
fov = 90;
|
16
|
+
aspect = 1;
|
17
|
+
shiftX = shiftY = 0;
|
18
|
+
update();
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
23
|
+
// get parameters
|
24
|
+
fov = pl.getFloat("fov", fov);
|
25
|
+
aspect = pl.getFloat("aspect", aspect);
|
26
|
+
shiftX = pl.getFloat("shift.x", shiftX);
|
27
|
+
shiftY = pl.getFloat("shift.y", shiftY);
|
28
|
+
update();
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
|
32
|
+
private void update() {
|
33
|
+
au = (float) Math.tan(Math.toRadians(fov * 0.5f));
|
34
|
+
av = au / aspect;
|
35
|
+
}
|
36
|
+
|
37
|
+
@Override
|
38
|
+
public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time) {
|
39
|
+
float du = shiftX - au + ((2.0f * au * x) / (imageWidth - 1.0f));
|
40
|
+
float dv = shiftY - av + ((2.0f * av * y) / (imageHeight - 1.0f));
|
41
|
+
return new Ray(0, 0, 0, du, dv, -1);
|
42
|
+
}
|
43
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
package org.sunflow.core.camera;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.CameraLens;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.Ray;
|
7
|
+
|
8
|
+
public class SphericalLens implements CameraLens {
|
9
|
+
|
10
|
+
@Override
|
11
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
12
|
+
return true;
|
13
|
+
}
|
14
|
+
|
15
|
+
@Override
|
16
|
+
public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time) {
|
17
|
+
// Generate environment camera ray direction
|
18
|
+
double theta = 2 * Math.PI * x / imageWidth + Math.PI / 2;
|
19
|
+
double phi = Math.PI * (imageHeight - 1 - y) / imageHeight;
|
20
|
+
return new Ray(0, 0, 0, (float) (Math.cos(theta) * Math.sin(phi)), (float) (Math.cos(phi)), (float) (Math.sin(theta) * Math.sin(phi)));
|
21
|
+
}
|
22
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
package org.sunflow.core.camera;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.CameraLens;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.Ray;
|
7
|
+
|
8
|
+
public class ThinLens implements CameraLens {
|
9
|
+
|
10
|
+
private float au, av;
|
11
|
+
private float aspect, fov;
|
12
|
+
private float shiftX, shiftY;
|
13
|
+
private float focusDistance;
|
14
|
+
private float lensRadius;
|
15
|
+
private int lensSides;
|
16
|
+
private float lensRotation;
|
17
|
+
private float lensRotationRadians;
|
18
|
+
|
19
|
+
public ThinLens() {
|
20
|
+
focusDistance = 1;
|
21
|
+
lensRadius = 0;
|
22
|
+
fov = 90;
|
23
|
+
aspect = 1;
|
24
|
+
lensSides = 0; // < 3 means use circular lens
|
25
|
+
lensRotation = lensRotationRadians = 0; // this rotates polygonal lenses
|
26
|
+
}
|
27
|
+
|
28
|
+
@Override
|
29
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
30
|
+
// get parameters
|
31
|
+
fov = pl.getFloat("fov", fov);
|
32
|
+
aspect = pl.getFloat("aspect", aspect);
|
33
|
+
shiftX = pl.getFloat("shift.x", shiftX);
|
34
|
+
shiftY = pl.getFloat("shift.y", shiftY);
|
35
|
+
focusDistance = pl.getFloat("focus.distance", focusDistance);
|
36
|
+
lensRadius = pl.getFloat("lens.radius", lensRadius);
|
37
|
+
lensSides = pl.getInt("lens.sides", lensSides);
|
38
|
+
lensRotation = pl.getFloat("lens.rotation", lensRotation);
|
39
|
+
update();
|
40
|
+
return true;
|
41
|
+
}
|
42
|
+
|
43
|
+
private void update() {
|
44
|
+
au = (float) Math.tan(Math.toRadians(fov * 0.5f)) * focusDistance;
|
45
|
+
av = au / aspect;
|
46
|
+
lensRotationRadians = (float) Math.toRadians(lensRotation);
|
47
|
+
}
|
48
|
+
|
49
|
+
@Override
|
50
|
+
public Ray getRay(float x, float y, int imageWidth, int imageHeight, double lensX, double lensY, double time) {
|
51
|
+
float du = shiftX * focusDistance - au + ((2.0f * au * x) / (imageWidth - 1.0f));
|
52
|
+
float dv = shiftY * focusDistance - av + ((2.0f * av * y) / (imageHeight - 1.0f));
|
53
|
+
|
54
|
+
float eyeX, eyeY;
|
55
|
+
if (lensSides < 3) {
|
56
|
+
double angle, r;
|
57
|
+
// concentric map sampling
|
58
|
+
double r1 = 2 * lensX - 1;
|
59
|
+
double r2 = 2 * lensY - 1;
|
60
|
+
if (r1 > -r2) {
|
61
|
+
if (r1 > r2) {
|
62
|
+
r = r1;
|
63
|
+
angle = 0.25 * Math.PI * r2 / r1;
|
64
|
+
} else {
|
65
|
+
r = r2;
|
66
|
+
angle = 0.25 * Math.PI * (2 - r1 / r2);
|
67
|
+
}
|
68
|
+
} else {
|
69
|
+
if (r1 < r2) {
|
70
|
+
r = -r1;
|
71
|
+
angle = 0.25 * Math.PI * (4 + r2 / r1);
|
72
|
+
} else {
|
73
|
+
r = -r2;
|
74
|
+
if (r2 != 0) {
|
75
|
+
angle = 0.25 * Math.PI * (6 - r1 / r2);
|
76
|
+
} else {
|
77
|
+
angle = 0;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
r *= lensRadius;
|
82
|
+
// point on the lens
|
83
|
+
eyeX = (float) (Math.cos(angle) * r);
|
84
|
+
eyeY = (float) (Math.sin(angle) * r);
|
85
|
+
} else {
|
86
|
+
// sample N-gon
|
87
|
+
// FIXME: this could use concentric sampling
|
88
|
+
lensY *= lensSides;
|
89
|
+
float side = (int) lensY;
|
90
|
+
float offs = (float) lensY - side;
|
91
|
+
float dist = (float) Math.sqrt(lensX);
|
92
|
+
float a0 = (float) (side * Math.PI * 2.0f / lensSides + lensRotationRadians);
|
93
|
+
float a1 = (float) ((side + 1.0f) * Math.PI * 2.0f / lensSides + lensRotationRadians);
|
94
|
+
eyeX = (float) ((Math.cos(a0) * (1.0f - offs) + Math.cos(a1) * offs) * dist);
|
95
|
+
eyeY = (float) ((Math.sin(a0) * (1.0f - offs) + Math.sin(a1) * offs) * dist);
|
96
|
+
eyeX *= lensRadius;
|
97
|
+
eyeY *= lensRadius;
|
98
|
+
}
|
99
|
+
float eyeZ = 0;
|
100
|
+
// point on the image plane
|
101
|
+
float dirX = du;
|
102
|
+
float dirY = dv;
|
103
|
+
float dirZ = -focusDistance;
|
104
|
+
// ray
|
105
|
+
return new Ray(eyeX, eyeY, eyeZ, dirX - eyeX, dirY - eyeY, dirZ - eyeZ);
|
106
|
+
}
|
107
|
+
}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
package org.sunflow.core.display;
|
2
|
+
|
3
|
+
import java.awt.Dimension;
|
4
|
+
import java.awt.Graphics;
|
5
|
+
import java.awt.event.KeyAdapter;
|
6
|
+
import java.awt.event.KeyEvent;
|
7
|
+
import java.awt.image.BufferedImage;
|
8
|
+
|
9
|
+
import javax.swing.JFrame;
|
10
|
+
import javax.swing.JPanel;
|
11
|
+
|
12
|
+
import org.sunflow.SunflowAPI;
|
13
|
+
import org.sunflow.core.Display;
|
14
|
+
import org.sunflow.image.Color;
|
15
|
+
import org.sunflow.system.Timer;
|
16
|
+
|
17
|
+
@SuppressWarnings("serial")
|
18
|
+
public class FastDisplay extends JPanel implements Display {
|
19
|
+
|
20
|
+
private JFrame frame;
|
21
|
+
private BufferedImage image;
|
22
|
+
private int[] pixels;
|
23
|
+
private final Timer t;
|
24
|
+
private float seconds;
|
25
|
+
private int frames;
|
26
|
+
|
27
|
+
public FastDisplay() {
|
28
|
+
image = null;
|
29
|
+
frame = null;
|
30
|
+
t = new Timer();
|
31
|
+
frames = 0;
|
32
|
+
seconds = 0;
|
33
|
+
}
|
34
|
+
|
35
|
+
@Override
|
36
|
+
public synchronized void imageBegin(int w, int h, int bucketSize) {
|
37
|
+
if (frame != null && image != null && w == image.getWidth() && h == image.getHeight()) {
|
38
|
+
// nothing to do
|
39
|
+
} else {
|
40
|
+
// allocate new framebuffer
|
41
|
+
pixels = new int[w * h];
|
42
|
+
image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
43
|
+
// prepare frame
|
44
|
+
if (frame == null) {
|
45
|
+
setPreferredSize(new Dimension(w, h));
|
46
|
+
frame = new JFrame("Sunflow v" + SunflowAPI.VERSION);
|
47
|
+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
48
|
+
frame.addKeyListener(new KeyAdapter() {
|
49
|
+
@Override
|
50
|
+
public void keyPressed(KeyEvent e) {
|
51
|
+
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
52
|
+
System.exit(0);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
});
|
56
|
+
frame.setContentPane(this);
|
57
|
+
frame.pack();
|
58
|
+
frame.setLocationRelativeTo(null);
|
59
|
+
frame.setVisible(true);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
// start counter
|
63
|
+
t.start();
|
64
|
+
}
|
65
|
+
|
66
|
+
@Override
|
67
|
+
public void imagePrepare(int x, int y, int w, int h, int id) {
|
68
|
+
}
|
69
|
+
|
70
|
+
@Override
|
71
|
+
public void imageUpdate(int x, int y, int w, int h, Color[] data, float[] alpha) {
|
72
|
+
int iw = image.getWidth();
|
73
|
+
int off = x + iw * y;
|
74
|
+
iw -= w;
|
75
|
+
for (int j = 0, index = 0; j < h; j++, off += iw) {
|
76
|
+
for (int i = 0; i < w; i++, index++, off++) {
|
77
|
+
pixels[off] = 0xFF000000 | data[index].toRGB();
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
@Override
|
83
|
+
public void imageFill(int x, int y, int w, int h, Color c, float alpha) {
|
84
|
+
int iw = image.getWidth();
|
85
|
+
int off = x + iw * y;
|
86
|
+
iw -= w;
|
87
|
+
int rgb = 0xFF000000 | c.toRGB();
|
88
|
+
for (int j = 0, index = 0; j < h; j++, off += iw) {
|
89
|
+
for (int i = 0; i < w; i++, index++, off++) {
|
90
|
+
pixels[off] = rgb;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
@Override
|
96
|
+
public synchronized void imageEnd() {
|
97
|
+
// copy buffer
|
98
|
+
image.setRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
|
99
|
+
repaint();
|
100
|
+
// update stats
|
101
|
+
t.end();
|
102
|
+
seconds += t.seconds();
|
103
|
+
frames++;
|
104
|
+
if (seconds > 1) {
|
105
|
+
// display average fps every second
|
106
|
+
frame.setTitle(String.format("Sunflow v%s - %.2f fps", SunflowAPI.VERSION, frames / seconds));
|
107
|
+
frames = 0;
|
108
|
+
seconds = 0;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
@Override
|
113
|
+
public synchronized void paint(Graphics g) {
|
114
|
+
if (image == null) {
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
g.drawImage(image, 0, 0, null);
|
118
|
+
}
|
119
|
+
}
|