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,266 @@
|
|
1
|
+
package org.sunflow.core.primitive;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Instance;
|
5
|
+
import org.sunflow.core.IntersectionState;
|
6
|
+
import org.sunflow.core.ParameterList;
|
7
|
+
import org.sunflow.core.PrimitiveList;
|
8
|
+
import org.sunflow.core.Ray;
|
9
|
+
import org.sunflow.core.ShadingState;
|
10
|
+
import org.sunflow.math.BoundingBox;
|
11
|
+
import org.sunflow.math.Matrix4;
|
12
|
+
import org.sunflow.math.OrthoNormalBasis;
|
13
|
+
import org.sunflow.math.Point3;
|
14
|
+
import org.sunflow.math.Solvers;
|
15
|
+
import org.sunflow.math.Vector3;
|
16
|
+
|
17
|
+
public class JuliaFractal implements PrimitiveList {
|
18
|
+
|
19
|
+
private static final float BOUNDING_RADIUS = (float) Math.sqrt(3);
|
20
|
+
private static final float BOUNDING_RADIUS2 = 3;
|
21
|
+
private static final float ESCAPE_THRESHOLD = 1e1f;
|
22
|
+
private static final float DELTA = 1e-4f;
|
23
|
+
// quaternion constant
|
24
|
+
private float cx;
|
25
|
+
private float cy;
|
26
|
+
private float cz;
|
27
|
+
private float cw;
|
28
|
+
private int maxIterations;
|
29
|
+
private float epsilon;
|
30
|
+
|
31
|
+
public JuliaFractal() {
|
32
|
+
// good defaults?
|
33
|
+
cw = -.4f;
|
34
|
+
cx = .2f;
|
35
|
+
cy = .3f;
|
36
|
+
cz = -.2f;
|
37
|
+
|
38
|
+
maxIterations = 15;
|
39
|
+
epsilon = 0.00001f;
|
40
|
+
}
|
41
|
+
|
42
|
+
@Override
|
43
|
+
public int getNumPrimitives() {
|
44
|
+
return 1;
|
45
|
+
}
|
46
|
+
|
47
|
+
@Override
|
48
|
+
public float getPrimitiveBound(int primID, int i) {
|
49
|
+
return ((i & 1) == 0) ? -BOUNDING_RADIUS : BOUNDING_RADIUS;
|
50
|
+
}
|
51
|
+
|
52
|
+
@Override
|
53
|
+
public BoundingBox getWorldBounds(Matrix4 o2w) {
|
54
|
+
BoundingBox bounds = new BoundingBox(BOUNDING_RADIUS);
|
55
|
+
if (o2w != null) {
|
56
|
+
bounds = o2w.transform(bounds);
|
57
|
+
}
|
58
|
+
return bounds;
|
59
|
+
}
|
60
|
+
|
61
|
+
@Override
|
62
|
+
public void intersectPrimitive(Ray r, int primID, IntersectionState state) {
|
63
|
+
// intersect with bounding sphere
|
64
|
+
float qc = ((r.ox * r.ox) + (r.oy * r.oy) + (r.oz * r.oz)) - BOUNDING_RADIUS2;
|
65
|
+
float qt = r.getMin();
|
66
|
+
if (qc > 0) {
|
67
|
+
// we are starting outside the sphere, find intersection on the
|
68
|
+
// sphere
|
69
|
+
float qa = r.dx * r.dx + r.dy * r.dy + r.dz * r.dz;
|
70
|
+
float qb = 2 * ((r.dx * r.ox) + (r.dy * r.oy) + (r.dz * r.oz));
|
71
|
+
double[] t = Solvers.solveQuadric(qa, qb, qc);
|
72
|
+
// early rejection
|
73
|
+
if (t == null || t[0] >= r.getMax() || t[1] <= r.getMin()) {
|
74
|
+
return;
|
75
|
+
}
|
76
|
+
qt = (float) t[0];
|
77
|
+
}
|
78
|
+
float dist = Float.POSITIVE_INFINITY;
|
79
|
+
float rox = r.ox + qt * r.dx;
|
80
|
+
float roy = r.oy + qt * r.dy;
|
81
|
+
float roz = r.oz + qt * r.dz;
|
82
|
+
float invRayLength = (float) (1 / Math.sqrt(r.dx * r.dx + r.dy * r.dy + r.dz * r.dz));
|
83
|
+
// now we can start intersection
|
84
|
+
while (true) {
|
85
|
+
float zw = rox;
|
86
|
+
float zx = roy;
|
87
|
+
float zy = roz;
|
88
|
+
float zz = 0;
|
89
|
+
|
90
|
+
float zpw = 1;
|
91
|
+
float zpx = 0;
|
92
|
+
float zpy = 0;
|
93
|
+
float zpz = 0;
|
94
|
+
|
95
|
+
// run several iterations
|
96
|
+
float dotz = 0;
|
97
|
+
for (int i = 0; i < maxIterations; i++) {
|
98
|
+
{
|
99
|
+
// zp = 2 * (z * zp)
|
100
|
+
float nw = zw * zpw - zx * zpx - zy * zpy - zz * zpz;
|
101
|
+
float nx = zw * zpx + zx * zpw + zy * zpz - zz * zpy;
|
102
|
+
float ny = zw * zpy + zy * zpw + zz * zpx - zx * zpz;
|
103
|
+
zpz = 2 * (zw * zpz + zz * zpw + zx * zpy - zy * zpx);
|
104
|
+
zpw = 2 * nw;
|
105
|
+
zpx = 2 * nx;
|
106
|
+
zpy = 2 * ny;
|
107
|
+
}
|
108
|
+
{
|
109
|
+
// z = z*z + c
|
110
|
+
float nw = zw * zw - zx * zx - zy * zy - zz * zz + cw;
|
111
|
+
zx = 2 * zw * zx + cx;
|
112
|
+
zy = 2 * zw * zy + cy;
|
113
|
+
zz = 2 * zw * zz + cz;
|
114
|
+
zw = nw;
|
115
|
+
}
|
116
|
+
dotz = zw * zw + zx * zx + zy * zy + zz * zz;
|
117
|
+
if (dotz > ESCAPE_THRESHOLD) {
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
|
121
|
+
}
|
122
|
+
float normZ = (float) Math.sqrt(dotz);
|
123
|
+
dist = 0.5f * normZ * (float) Math.log(normZ) / length(zpw, zpx, zpy, zpz);
|
124
|
+
rox += dist * r.dx;
|
125
|
+
roy += dist * r.dy;
|
126
|
+
roz += dist * r.dz;
|
127
|
+
qt += dist;
|
128
|
+
if (dist * invRayLength < epsilon) {
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
if (rox * rox + roy * roy + roz * roz > BOUNDING_RADIUS2) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
// now test t value again
|
136
|
+
if (!r.isInside(qt)) {
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
if (dist * invRayLength < epsilon) {
|
140
|
+
// valid hit
|
141
|
+
r.setMax(qt);
|
142
|
+
state.setIntersection(0);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
@Override
|
147
|
+
public void prepareShadingState(ShadingState state) {
|
148
|
+
state.init();
|
149
|
+
state.getRay().getPoint(state.getPoint());
|
150
|
+
Instance parent = state.getInstance();
|
151
|
+
// compute local normal
|
152
|
+
Point3 p = state.transformWorldToObject(state.getPoint());
|
153
|
+
float gx1w = p.x - DELTA;
|
154
|
+
float gx1x = p.y;
|
155
|
+
float gx1y = p.z;
|
156
|
+
float gx1z = 0;
|
157
|
+
float gx2w = p.x + DELTA;
|
158
|
+
float gx2x = p.y;
|
159
|
+
float gx2y = p.z;
|
160
|
+
float gx2z = 0;
|
161
|
+
|
162
|
+
float gy1w = p.x;
|
163
|
+
float gy1x = p.y - DELTA;
|
164
|
+
float gy1y = p.z;
|
165
|
+
float gy1z = 0;
|
166
|
+
float gy2w = p.x;
|
167
|
+
float gy2x = p.y + DELTA;
|
168
|
+
float gy2y = p.z;
|
169
|
+
float gy2z = 0;
|
170
|
+
|
171
|
+
float gz1w = p.x;
|
172
|
+
float gz1x = p.y;
|
173
|
+
float gz1y = p.z - DELTA;
|
174
|
+
float gz1z = 0;
|
175
|
+
float gz2w = p.x;
|
176
|
+
float gz2x = p.y;
|
177
|
+
float gz2y = p.z + DELTA;
|
178
|
+
float gz2z = 0;
|
179
|
+
|
180
|
+
for (int i = 0; i < maxIterations; i++) {
|
181
|
+
{
|
182
|
+
// z = z*z + c
|
183
|
+
float nw = gx1w * gx1w - gx1x * gx1x - gx1y * gx1y - gx1z * gx1z + cw;
|
184
|
+
gx1x = 2 * gx1w * gx1x + cx;
|
185
|
+
gx1y = 2 * gx1w * gx1y + cy;
|
186
|
+
gx1z = 2 * gx1w * gx1z + cz;
|
187
|
+
gx1w = nw;
|
188
|
+
}
|
189
|
+
{
|
190
|
+
// z = z*z + c
|
191
|
+
float nw = gx2w * gx2w - gx2x * gx2x - gx2y * gx2y - gx2z * gx2z + cw;
|
192
|
+
gx2x = 2 * gx2w * gx2x + cx;
|
193
|
+
gx2y = 2 * gx2w * gx2y + cy;
|
194
|
+
gx2z = 2 * gx2w * gx2z + cz;
|
195
|
+
gx2w = nw;
|
196
|
+
}
|
197
|
+
{
|
198
|
+
// z = z*z + c
|
199
|
+
float nw = gy1w * gy1w - gy1x * gy1x - gy1y * gy1y - gy1z * gy1z + cw;
|
200
|
+
gy1x = 2 * gy1w * gy1x + cx;
|
201
|
+
gy1y = 2 * gy1w * gy1y + cy;
|
202
|
+
gy1z = 2 * gy1w * gy1z + cz;
|
203
|
+
gy1w = nw;
|
204
|
+
}
|
205
|
+
{
|
206
|
+
// z = z*z + c
|
207
|
+
float nw = gy2w * gy2w - gy2x * gy2x - gy2y * gy2y - gy2z * gy2z + cw;
|
208
|
+
gy2x = 2 * gy2w * gy2x + cx;
|
209
|
+
gy2y = 2 * gy2w * gy2y + cy;
|
210
|
+
gy2z = 2 * gy2w * gy2z + cz;
|
211
|
+
gy2w = nw;
|
212
|
+
}
|
213
|
+
{
|
214
|
+
// z = z*z + c
|
215
|
+
float nw = gz1w * gz1w - gz1x * gz1x - gz1y * gz1y - gz1z * gz1z + cw;
|
216
|
+
gz1x = 2 * gz1w * gz1x + cx;
|
217
|
+
gz1y = 2 * gz1w * gz1y + cy;
|
218
|
+
gz1z = 2 * gz1w * gz1z + cz;
|
219
|
+
gz1w = nw;
|
220
|
+
}
|
221
|
+
{
|
222
|
+
// z = z*z + c
|
223
|
+
float nw = gz2w * gz2w - gz2x * gz2x - gz2y * gz2y - gz2z * gz2z + cw;
|
224
|
+
gz2x = 2 * gz2w * gz2x + cx;
|
225
|
+
gz2y = 2 * gz2w * gz2y + cy;
|
226
|
+
gz2z = 2 * gz2w * gz2z + cz;
|
227
|
+
gz2w = nw;
|
228
|
+
}
|
229
|
+
}
|
230
|
+
float gradX = length(gx2w, gx2x, gx2y, gx2z) - length(gx1w, gx1x, gx1y, gx1z);
|
231
|
+
float gradY = length(gy2w, gy2x, gy2y, gy2z) - length(gy1w, gy1x, gy1y, gy1z);
|
232
|
+
float gradZ = length(gz2w, gz2x, gz2y, gz2z) - length(gz1w, gz1x, gz1y, gz1z);
|
233
|
+
Vector3 n = new Vector3(gradX, gradY, gradZ);
|
234
|
+
state.getNormal().set(state.transformNormalObjectToWorld(n));
|
235
|
+
state.getNormal().normalize();
|
236
|
+
state.getGeoNormal().set(state.getNormal());
|
237
|
+
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
|
238
|
+
|
239
|
+
state.getPoint().x += state.getNormal().x * epsilon * 20;
|
240
|
+
state.getPoint().y += state.getNormal().y * epsilon * 20;
|
241
|
+
state.getPoint().z += state.getNormal().z * epsilon * 20;
|
242
|
+
|
243
|
+
state.setShader(parent.getShader(0));
|
244
|
+
state.setModifier(parent.getModifier(0));
|
245
|
+
}
|
246
|
+
|
247
|
+
private static float length(float w, float x, float y, float z) {
|
248
|
+
return (float) Math.sqrt(w * w + x * x + y * y + z * z);
|
249
|
+
}
|
250
|
+
|
251
|
+
@Override
|
252
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
253
|
+
maxIterations = pl.getInt("iterations", maxIterations);
|
254
|
+
epsilon = pl.getFloat("epsilon", epsilon);
|
255
|
+
cw = pl.getFloat("cw", cw);
|
256
|
+
cx = pl.getFloat("cx", cx);
|
257
|
+
cy = pl.getFloat("cy", cy);
|
258
|
+
cz = pl.getFloat("cz", cz);
|
259
|
+
return true;
|
260
|
+
}
|
261
|
+
|
262
|
+
@Override
|
263
|
+
public PrimitiveList getBakingPrimitives() {
|
264
|
+
return null;
|
265
|
+
}
|
266
|
+
}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
package org.sunflow.core.primitive;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.IntersectionState;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.PrimitiveList;
|
7
|
+
import org.sunflow.core.Ray;
|
8
|
+
import org.sunflow.core.ShadingState;
|
9
|
+
import org.sunflow.core.ParameterList.FloatParameter;
|
10
|
+
import org.sunflow.math.BoundingBox;
|
11
|
+
import org.sunflow.math.Matrix4;
|
12
|
+
import org.sunflow.math.OrthoNormalBasis;
|
13
|
+
import org.sunflow.math.Point3;
|
14
|
+
import org.sunflow.math.Solvers;
|
15
|
+
import org.sunflow.math.Vector3;
|
16
|
+
|
17
|
+
public class ParticleSurface implements PrimitiveList {
|
18
|
+
|
19
|
+
private float[] particles;
|
20
|
+
private float r, r2;
|
21
|
+
private int n;
|
22
|
+
|
23
|
+
public ParticleSurface() {
|
24
|
+
particles = null;
|
25
|
+
r = r2 = 1;
|
26
|
+
n = 0;
|
27
|
+
}
|
28
|
+
|
29
|
+
@Override
|
30
|
+
public int getNumPrimitives() {
|
31
|
+
return n;
|
32
|
+
}
|
33
|
+
|
34
|
+
@Override
|
35
|
+
public float getPrimitiveBound(int primID, int i) {
|
36
|
+
float c = particles[primID * 3 + (i >>> 1)];
|
37
|
+
return (i & 1) == 0 ? c - r : c + r;
|
38
|
+
}
|
39
|
+
|
40
|
+
@Override
|
41
|
+
public BoundingBox getWorldBounds(Matrix4 o2w) {
|
42
|
+
BoundingBox bounds = new BoundingBox();
|
43
|
+
for (int i = 0, i3 = 0; i < n; i++, i3 += 3) {
|
44
|
+
bounds.include(particles[i3], particles[i3 + 1], particles[i3 + 2]);
|
45
|
+
}
|
46
|
+
bounds.include(bounds.getMinimum().x - r, bounds.getMinimum().y - r, bounds.getMinimum().z - r);
|
47
|
+
bounds.include(bounds.getMaximum().x + r, bounds.getMaximum().y + r, bounds.getMaximum().z + r);
|
48
|
+
return o2w == null ? bounds : o2w.transform(bounds);
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public void intersectPrimitive(Ray r, int primID, IntersectionState state) {
|
53
|
+
int i3 = primID * 3;
|
54
|
+
float ocx = r.ox - particles[i3 + 0];
|
55
|
+
float ocy = r.oy - particles[i3 + 1];
|
56
|
+
float ocz = r.oz - particles[i3 + 2];
|
57
|
+
float qa = r.dx * r.dx + r.dy * r.dy + r.dz * r.dz;
|
58
|
+
float qb = 2 * ((r.dx * ocx) + (r.dy * ocy) + (r.dz * ocz));
|
59
|
+
float qc = ((ocx * ocx) + (ocy * ocy) + (ocz * ocz)) - r2;
|
60
|
+
double[] t = Solvers.solveQuadric(qa, qb, qc);
|
61
|
+
if (t != null) {
|
62
|
+
// early rejection
|
63
|
+
if (t[0] >= r.getMax() || t[1] <= r.getMin()) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
if (t[0] > r.getMin()) {
|
67
|
+
r.setMax((float) t[0]);
|
68
|
+
} else {
|
69
|
+
r.setMax((float) t[1]);
|
70
|
+
}
|
71
|
+
state.setIntersection(primID);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
@Override
|
76
|
+
public void prepareShadingState(ShadingState state) {
|
77
|
+
state.init();
|
78
|
+
state.getRay().getPoint(state.getPoint());
|
79
|
+
Point3 localPoint = state.transformWorldToObject(state.getPoint());
|
80
|
+
|
81
|
+
localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
|
82
|
+
localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
|
83
|
+
localPoint.z -= particles[3 * state.getPrimitiveID() + 2];
|
84
|
+
|
85
|
+
state.getNormal().set(localPoint.x, localPoint.y, localPoint.z);
|
86
|
+
state.getNormal().normalize();
|
87
|
+
|
88
|
+
state.setShader(state.getInstance().getShader(0));
|
89
|
+
state.setModifier(state.getInstance().getModifier(0));
|
90
|
+
// into object space
|
91
|
+
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
|
92
|
+
state.getNormal().set(worldNormal);
|
93
|
+
state.getNormal().normalize();
|
94
|
+
state.getGeoNormal().set(state.getNormal());
|
95
|
+
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
|
96
|
+
}
|
97
|
+
|
98
|
+
@Override
|
99
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
100
|
+
FloatParameter p = pl.getPointArray("particles");
|
101
|
+
if (p != null) {
|
102
|
+
particles = p.data;
|
103
|
+
}
|
104
|
+
r = pl.getFloat("radius", r);
|
105
|
+
r2 = r * r;
|
106
|
+
n = pl.getInt("num", n);
|
107
|
+
return particles != null && n <= (particles.length / 3);
|
108
|
+
}
|
109
|
+
|
110
|
+
@Override
|
111
|
+
public PrimitiveList getBakingPrimitives() {
|
112
|
+
return null;
|
113
|
+
}
|
114
|
+
}
|
@@ -0,0 +1,163 @@
|
|
1
|
+
package org.sunflow.core.primitive;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Instance;
|
5
|
+
import org.sunflow.core.IntersectionState;
|
6
|
+
import org.sunflow.core.ParameterList;
|
7
|
+
import org.sunflow.core.PrimitiveList;
|
8
|
+
import org.sunflow.core.Ray;
|
9
|
+
import org.sunflow.core.ShadingState;
|
10
|
+
import org.sunflow.math.BoundingBox;
|
11
|
+
import org.sunflow.math.Matrix4;
|
12
|
+
import org.sunflow.math.OrthoNormalBasis;
|
13
|
+
import org.sunflow.math.Point3;
|
14
|
+
import org.sunflow.math.Vector3;
|
15
|
+
|
16
|
+
public class Plane implements PrimitiveList {
|
17
|
+
|
18
|
+
private Point3 center;
|
19
|
+
private Vector3 normal;
|
20
|
+
int k;
|
21
|
+
private float bnu, bnv, bnd;
|
22
|
+
private float cnu, cnv, cnd;
|
23
|
+
|
24
|
+
public Plane() {
|
25
|
+
center = new Point3(0, 0, 0);
|
26
|
+
normal = new Vector3(0, 1, 0);
|
27
|
+
k = 3;
|
28
|
+
bnu = bnv = bnd = 0;
|
29
|
+
cnu = cnv = cnd = 0;
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
34
|
+
center = pl.getPoint("center", center);
|
35
|
+
Point3 b = pl.getPoint("point1", null);
|
36
|
+
Point3 c = pl.getPoint("point2", null);
|
37
|
+
if (b != null && c != null) {
|
38
|
+
Point3 v0 = center;
|
39
|
+
Point3 v1 = b;
|
40
|
+
Point3 v2 = c;
|
41
|
+
Vector3 ng = normal = Vector3.cross(Point3.sub(v1, v0, new Vector3()), Point3.sub(v2, v0, new Vector3()), new Vector3()).normalize();
|
42
|
+
if (Math.abs(ng.x) > Math.abs(ng.y) && Math.abs(ng.x) > Math.abs(ng.z)) {
|
43
|
+
k = 0;
|
44
|
+
} else if (Math.abs(ng.y) > Math.abs(ng.z)) {
|
45
|
+
k = 1;
|
46
|
+
} else {
|
47
|
+
k = 2;
|
48
|
+
}
|
49
|
+
float ax, ay, bx, by, cx, cy;
|
50
|
+
switch (k) {
|
51
|
+
case 0: {
|
52
|
+
ax = v0.y;
|
53
|
+
ay = v0.z;
|
54
|
+
bx = v2.y - ax;
|
55
|
+
by = v2.z - ay;
|
56
|
+
cx = v1.y - ax;
|
57
|
+
cy = v1.z - ay;
|
58
|
+
break;
|
59
|
+
}
|
60
|
+
case 1: {
|
61
|
+
ax = v0.z;
|
62
|
+
ay = v0.x;
|
63
|
+
bx = v2.z - ax;
|
64
|
+
by = v2.x - ay;
|
65
|
+
cx = v1.z - ax;
|
66
|
+
cy = v1.x - ay;
|
67
|
+
break;
|
68
|
+
}
|
69
|
+
case 2:
|
70
|
+
default: {
|
71
|
+
ax = v0.x;
|
72
|
+
ay = v0.y;
|
73
|
+
bx = v2.x - ax;
|
74
|
+
by = v2.y - ay;
|
75
|
+
cx = v1.x - ax;
|
76
|
+
cy = v1.y - ay;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
float det = bx * cy - by * cx;
|
80
|
+
bnu = -by / det;
|
81
|
+
bnv = bx / det;
|
82
|
+
bnd = (by * ax - bx * ay) / det;
|
83
|
+
cnu = cy / det;
|
84
|
+
cnv = -cx / det;
|
85
|
+
cnd = (cx * ay - cy * ax) / det;
|
86
|
+
} else {
|
87
|
+
normal = pl.getVector("normal", normal);
|
88
|
+
k = 3;
|
89
|
+
bnu = bnv = bnd = 0;
|
90
|
+
cnu = cnv = cnd = 0;
|
91
|
+
}
|
92
|
+
return true;
|
93
|
+
}
|
94
|
+
|
95
|
+
@Override
|
96
|
+
public void prepareShadingState(ShadingState state) {
|
97
|
+
state.init();
|
98
|
+
state.getRay().getPoint(state.getPoint());
|
99
|
+
Instance parent = state.getInstance();
|
100
|
+
Vector3 worldNormal = state.transformNormalObjectToWorld(normal);
|
101
|
+
state.getNormal().set(worldNormal);
|
102
|
+
state.getGeoNormal().set(worldNormal);
|
103
|
+
state.setShader(parent.getShader(0));
|
104
|
+
state.setModifier(parent.getModifier(0));
|
105
|
+
Point3 p = state.transformWorldToObject(state.getPoint());
|
106
|
+
float hu, hv;
|
107
|
+
switch (k) {
|
108
|
+
case 0: {
|
109
|
+
hu = p.y;
|
110
|
+
hv = p.z;
|
111
|
+
break;
|
112
|
+
}
|
113
|
+
case 1: {
|
114
|
+
hu = p.z;
|
115
|
+
hv = p.x;
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
case 2: {
|
119
|
+
hu = p.x;
|
120
|
+
hv = p.y;
|
121
|
+
break;
|
122
|
+
}
|
123
|
+
default:
|
124
|
+
hu = hv = 0;
|
125
|
+
}
|
126
|
+
state.getUV().x = hu * bnu + hv * bnv + bnd;
|
127
|
+
state.getUV().y = hu * cnu + hv * cnv + cnd;
|
128
|
+
state.setBasis(OrthoNormalBasis.makeFromW(normal));
|
129
|
+
}
|
130
|
+
|
131
|
+
@Override
|
132
|
+
public void intersectPrimitive(Ray r, int primID, IntersectionState state) {
|
133
|
+
float dn = normal.x * r.dx + normal.y * r.dy + normal.z * r.dz;
|
134
|
+
if (dn == 0.0) {
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
float t = (((center.x - r.ox) * normal.x) + ((center.y - r.oy) * normal.y) + ((center.z - r.oz) * normal.z)) / dn;
|
138
|
+
if (r.isInside(t)) {
|
139
|
+
r.setMax(t);
|
140
|
+
state.setIntersection(0);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
@Override
|
145
|
+
public int getNumPrimitives() {
|
146
|
+
return 1;
|
147
|
+
}
|
148
|
+
|
149
|
+
@Override
|
150
|
+
public float getPrimitiveBound(int primID, int i) {
|
151
|
+
return 0;
|
152
|
+
}
|
153
|
+
|
154
|
+
@Override
|
155
|
+
public BoundingBox getWorldBounds(Matrix4 o2w) {
|
156
|
+
return null;
|
157
|
+
}
|
158
|
+
|
159
|
+
@Override
|
160
|
+
public PrimitiveList getBakingPrimitives() {
|
161
|
+
return null;
|
162
|
+
}
|
163
|
+
}
|