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,119 @@
|
|
1
|
+
package org.sunflow.math;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* This class describes a transformation matrix that changes over time. Note
|
5
|
+
* that while unlimited motion segments are supported, it is assumed that these
|
6
|
+
* segments represent equidistant samples within a given time range.
|
7
|
+
*/
|
8
|
+
public final class MovingMatrix4 {
|
9
|
+
|
10
|
+
private Matrix4[] transforms;
|
11
|
+
private float t0, t1, inv;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Constructs a simple static matrix.
|
15
|
+
*
|
16
|
+
* @param m matrix value at all times
|
17
|
+
*/
|
18
|
+
public MovingMatrix4(Matrix4 m) {
|
19
|
+
transforms = new Matrix4[]{m};
|
20
|
+
t0 = t1 = 0;
|
21
|
+
inv = 1;
|
22
|
+
}
|
23
|
+
|
24
|
+
private MovingMatrix4(int n, float t0, float t1, float inv) {
|
25
|
+
transforms = new Matrix4[n];
|
26
|
+
this.t0 = t0;
|
27
|
+
this.t1 = t1;
|
28
|
+
this.inv = inv;
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Redefines the number of steps in the matrix. The contents are only
|
33
|
+
* re-allocated if the number of steps changes. This is to allow the matrix
|
34
|
+
* to be incrementally specified.
|
35
|
+
*
|
36
|
+
* @param n
|
37
|
+
*/
|
38
|
+
public void setSteps(int n) {
|
39
|
+
if (transforms.length != n) {
|
40
|
+
transforms = new Matrix4[n];
|
41
|
+
if (t0 < t1) {
|
42
|
+
inv = (transforms.length - 1) / (t1 - t0);
|
43
|
+
} else {
|
44
|
+
inv = 1;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Updates the matrix for the given time step.
|
51
|
+
*
|
52
|
+
* @param i time step to update
|
53
|
+
* @param m new value for the matrix at this time step
|
54
|
+
*/
|
55
|
+
public void updateData(int i, Matrix4 m) {
|
56
|
+
transforms[i] = m;
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Get the matrix for the given time step.
|
61
|
+
*
|
62
|
+
* @param i time step to get
|
63
|
+
* @return matrix for the specfied time step
|
64
|
+
*/
|
65
|
+
public Matrix4 getData(int i) {
|
66
|
+
return transforms[i];
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Get the number of matrix segments
|
71
|
+
*
|
72
|
+
* @return number of segments
|
73
|
+
*/
|
74
|
+
public int numSegments() {
|
75
|
+
return transforms.length;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Update the time extents over which the matrix data is changing. If the
|
80
|
+
* interval is empty, no motion will be produced, even if multiple values
|
81
|
+
* have been specified.
|
82
|
+
*
|
83
|
+
* @param t0
|
84
|
+
* @param t1
|
85
|
+
*/
|
86
|
+
public void updateTimes(float t0, float t1) {
|
87
|
+
this.t0 = t0;
|
88
|
+
this.t1 = t1;
|
89
|
+
if (t0 < t1) {
|
90
|
+
inv = (transforms.length - 1) / (t1 - t0);
|
91
|
+
} else {
|
92
|
+
inv = 1;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
public MovingMatrix4 inverse() {
|
97
|
+
MovingMatrix4 mi = new MovingMatrix4(transforms.length, t0, t1, inv);
|
98
|
+
for (int i = 0; i < transforms.length; i++) {
|
99
|
+
if (transforms[i] != null) {
|
100
|
+
mi.transforms[i] = transforms[i].inverse();
|
101
|
+
if (mi.transforms[i] == null) {
|
102
|
+
return null; // unable to invert
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return mi;
|
107
|
+
}
|
108
|
+
|
109
|
+
public Matrix4 sample(float time) {
|
110
|
+
if (transforms.length == 1 || t0 >= t1) {
|
111
|
+
return transforms[0];
|
112
|
+
} else {
|
113
|
+
float nt = (MathUtils.clamp(time, t0, t1) - t0) * inv;
|
114
|
+
int idx0 = (int) nt;
|
115
|
+
int idx1 = Math.min(idx0 + 1, transforms.length - 1);
|
116
|
+
return Matrix4.blend(transforms[idx0], transforms[idx1], (float) (nt - idx0));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
package org.sunflow.math;
|
2
|
+
|
3
|
+
public final class OrthoNormalBasis {
|
4
|
+
|
5
|
+
private Vector3 u, v, w;
|
6
|
+
|
7
|
+
private OrthoNormalBasis() {
|
8
|
+
u = new Vector3();
|
9
|
+
v = new Vector3();
|
10
|
+
w = new Vector3();
|
11
|
+
}
|
12
|
+
|
13
|
+
public void flipU() {
|
14
|
+
u.negate();
|
15
|
+
}
|
16
|
+
|
17
|
+
public void flipV() {
|
18
|
+
v.negate();
|
19
|
+
}
|
20
|
+
|
21
|
+
public void flipW() {
|
22
|
+
w.negate();
|
23
|
+
}
|
24
|
+
|
25
|
+
public void swapUV() {
|
26
|
+
Vector3 t = u;
|
27
|
+
u = v;
|
28
|
+
v = t;
|
29
|
+
}
|
30
|
+
|
31
|
+
public void swapVW() {
|
32
|
+
Vector3 t = v;
|
33
|
+
v = w;
|
34
|
+
w = t;
|
35
|
+
}
|
36
|
+
|
37
|
+
public void swapWU() {
|
38
|
+
Vector3 t = w;
|
39
|
+
w = u;
|
40
|
+
u = t;
|
41
|
+
}
|
42
|
+
|
43
|
+
public Vector3 transform(Vector3 a, Vector3 dest) {
|
44
|
+
dest.x = (a.x * u.x) + (a.y * v.x) + (a.z * w.x);
|
45
|
+
dest.y = (a.x * u.y) + (a.y * v.y) + (a.z * w.y);
|
46
|
+
dest.z = (a.x * u.z) + (a.y * v.z) + (a.z * w.z);
|
47
|
+
return dest;
|
48
|
+
}
|
49
|
+
|
50
|
+
public Vector3 transform(Vector3 a) {
|
51
|
+
float x = (a.x * u.x) + (a.y * v.x) + (a.z * w.x);
|
52
|
+
float y = (a.x * u.y) + (a.y * v.y) + (a.z * w.y);
|
53
|
+
float z = (a.x * u.z) + (a.y * v.z) + (a.z * w.z);
|
54
|
+
return a.set(x, y, z);
|
55
|
+
}
|
56
|
+
|
57
|
+
public Vector3 untransform(Vector3 a, Vector3 dest) {
|
58
|
+
dest.x = Vector3.dot(a, u);
|
59
|
+
dest.y = Vector3.dot(a, v);
|
60
|
+
dest.z = Vector3.dot(a, w);
|
61
|
+
return dest;
|
62
|
+
}
|
63
|
+
|
64
|
+
public Vector3 untransform(Vector3 a) {
|
65
|
+
float x = Vector3.dot(a, u);
|
66
|
+
float y = Vector3.dot(a, v);
|
67
|
+
float z = Vector3.dot(a, w);
|
68
|
+
return a.set(x, y, z);
|
69
|
+
}
|
70
|
+
|
71
|
+
public float untransformX(Vector3 a) {
|
72
|
+
return Vector3.dot(a, u);
|
73
|
+
}
|
74
|
+
|
75
|
+
public float untransformY(Vector3 a) {
|
76
|
+
return Vector3.dot(a, v);
|
77
|
+
}
|
78
|
+
|
79
|
+
public float untransformZ(Vector3 a) {
|
80
|
+
return Vector3.dot(a, w);
|
81
|
+
}
|
82
|
+
|
83
|
+
public static final OrthoNormalBasis makeFromW(Vector3 w) {
|
84
|
+
OrthoNormalBasis onb = new OrthoNormalBasis();
|
85
|
+
w.normalize(onb.w);
|
86
|
+
if ((Math.abs(onb.w.x) < Math.abs(onb.w.y)) && (Math.abs(onb.w.x) < Math.abs(onb.w.z))) {
|
87
|
+
onb.v.x = 0;
|
88
|
+
onb.v.y = onb.w.z;
|
89
|
+
onb.v.z = -onb.w.y;
|
90
|
+
} else if (Math.abs(onb.w.y) < Math.abs(onb.w.z)) {
|
91
|
+
onb.v.x = onb.w.z;
|
92
|
+
onb.v.y = 0;
|
93
|
+
onb.v.z = -onb.w.x;
|
94
|
+
} else {
|
95
|
+
onb.v.x = onb.w.y;
|
96
|
+
onb.v.y = -onb.w.x;
|
97
|
+
onb.v.z = 0;
|
98
|
+
}
|
99
|
+
Vector3.cross(onb.v.normalize(), onb.w, onb.u);
|
100
|
+
return onb;
|
101
|
+
}
|
102
|
+
|
103
|
+
public static final OrthoNormalBasis makeFromWV(Vector3 w, Vector3 v) {
|
104
|
+
OrthoNormalBasis onb = new OrthoNormalBasis();
|
105
|
+
w.normalize(onb.w);
|
106
|
+
Vector3.cross(v, onb.w, onb.u).normalize();
|
107
|
+
Vector3.cross(onb.w, onb.u, onb.v);
|
108
|
+
return onb;
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,331 @@
|
|
1
|
+
package org.sunflow.math;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Noise function from Ken Perlin. Additional routines are provided to emulate
|
5
|
+
* standard Renderman calls. This code was adapted mainly from the mrclasses
|
6
|
+
* package by Gonzalo Garramuno (http://sourceforge.net/projects/mrclasses/).
|
7
|
+
*
|
8
|
+
* @link http://mrl.nyu.edu/~perlin/noise/
|
9
|
+
*/
|
10
|
+
public final class PerlinScalar {
|
11
|
+
|
12
|
+
private static final float[] G1 = {-1, 1};
|
13
|
+
private static final float[][] G2 = {{1, 0}, {-1, 0}, {0, 1},
|
14
|
+
{0, -1}};
|
15
|
+
private static final float[][] G3 = {{1, 1, 0}, {-1, 1, 0},
|
16
|
+
{1, -1, 0}, {-1, -1, 0}, {1, 0, 1}, {-1, 0, 1},
|
17
|
+
{1, 0, -1}, {-1, 0, -1}, {0, 1, 1}, {0, -1, 1},
|
18
|
+
{0, 1, -1}, {0, -1, -1}, {1, 1, 0}, {-1, 1, 0},
|
19
|
+
{0, -1, 1}, {0, -1, -1}};
|
20
|
+
private static final float[][] G4 = {{-1, -1, -1, 0}, {-1, -1, 1, 0},
|
21
|
+
{-1, 1, -1, 0}, {-1, 1, 1, 0}, {1, -1, -1, 0},
|
22
|
+
{1, -1, 1, 0}, {1, 1, -1, 0}, {1, 1, 1, 0},
|
23
|
+
{-1, -1, 0, -1}, {-1, 1, 0, -1}, {1, -1, 0, -1},
|
24
|
+
{1, 1, 0, -1}, {-1, -1, 0, 1}, {-1, 1, 0, 1},
|
25
|
+
{1, -1, 0, 1}, {1, 1, 0, 1}, {-1, 0, -1, -1},
|
26
|
+
{1, 0, -1, -1}, {-1, 0, -1, 1}, {1, 0, -1, 1},
|
27
|
+
{-1, 0, 1, -1}, {1, 0, 1, -1}, {-1, 0, 1, 1}, {1, 0, 1, 1},
|
28
|
+
{0, -1, -1, -1}, {0, -1, -1, 1}, {0, -1, 1, -1},
|
29
|
+
{0, -1, 1, 1}, {0, 1, -1, -1}, {0, 1, -1, 1},
|
30
|
+
{0, 1, 1, -1}, {0, 1, 1, 1}};
|
31
|
+
private static final int[] p = {151, 160, 137, 91, 90, 15, 131, 13, 201,
|
32
|
+
95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37,
|
33
|
+
240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62,
|
34
|
+
94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56,
|
35
|
+
87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139,
|
36
|
+
48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133,
|
37
|
+
230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25,
|
38
|
+
63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200,
|
39
|
+
196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3,
|
40
|
+
64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255,
|
41
|
+
82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
|
42
|
+
223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153,
|
43
|
+
101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79,
|
44
|
+
113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242,
|
45
|
+
193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249,
|
46
|
+
14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204,
|
47
|
+
176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222,
|
48
|
+
114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,
|
49
|
+
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7,
|
50
|
+
225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6,
|
51
|
+
148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35,
|
52
|
+
11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171,
|
53
|
+
168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158,
|
54
|
+
231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55,
|
55
|
+
46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73,
|
56
|
+
209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188,
|
57
|
+
159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250,
|
58
|
+
124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206,
|
59
|
+
59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, 213, 119,
|
60
|
+
248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
|
61
|
+
129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185,
|
62
|
+
112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12,
|
63
|
+
191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192,
|
64
|
+
214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45,
|
65
|
+
127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243,
|
66
|
+
141, 128, 195, 78, 66, 215, 61, 156, 180};
|
67
|
+
|
68
|
+
public static final float snoise(float x) {
|
69
|
+
int xf = (int) Math.floor(x);
|
70
|
+
int X = xf & 255;
|
71
|
+
x -= xf;
|
72
|
+
float u = fade(x);
|
73
|
+
int A = p[X], B = p[X + 1];
|
74
|
+
return lerp(u, grad(p[A], x), grad(p[B], x - 1));
|
75
|
+
}
|
76
|
+
|
77
|
+
public static final float snoise(float x, float y) {
|
78
|
+
int xf = (int) Math.floor(x);
|
79
|
+
int yf = (int) Math.floor(y);
|
80
|
+
int X = xf & 255;
|
81
|
+
int Y = yf & 255;
|
82
|
+
x -= xf;
|
83
|
+
y -= yf;
|
84
|
+
float u = fade(x);
|
85
|
+
float v = fade(y);
|
86
|
+
int A = p[X] + Y, B = p[X + 1] + Y;
|
87
|
+
return lerp(v, lerp(u, grad(p[A], x, y), grad(p[B], x - 1, y)), lerp(u, grad(p[A + 1], x, y - 1), grad(p[B + 1], x - 1, y - 1)));
|
88
|
+
}
|
89
|
+
|
90
|
+
public static final float snoise(float x, float y, float z) {
|
91
|
+
int xf = (int) Math.floor(x);
|
92
|
+
int yf = (int) Math.floor(y);
|
93
|
+
int zf = (int) Math.floor(z);
|
94
|
+
int X = xf & 255;
|
95
|
+
int Y = yf & 255;
|
96
|
+
int Z = zf & 255;
|
97
|
+
x -= xf;
|
98
|
+
y -= yf;
|
99
|
+
z -= zf;
|
100
|
+
float u = fade(x);
|
101
|
+
float v = fade(y);
|
102
|
+
float w = fade(z);
|
103
|
+
int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z, B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z;
|
104
|
+
return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))), lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)), lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1))));
|
105
|
+
}
|
106
|
+
|
107
|
+
public static final float snoise(float x, float y, float z, float w) {
|
108
|
+
int xf = (int) Math.floor(x);
|
109
|
+
int yf = (int) Math.floor(y);
|
110
|
+
int zf = (int) Math.floor(z);
|
111
|
+
int wf = (int) Math.floor(w);
|
112
|
+
int X = xf & 255;
|
113
|
+
int Y = yf & 255;
|
114
|
+
int Z = zf & 255;
|
115
|
+
int W = wf & 255;
|
116
|
+
x -= xf;
|
117
|
+
y -= yf;
|
118
|
+
z -= zf;
|
119
|
+
w -= wf;
|
120
|
+
float u = fade(x);
|
121
|
+
float v = fade(y);
|
122
|
+
float t = fade(z);
|
123
|
+
float s = fade(w);
|
124
|
+
int A = p[X] + Y, AA = p[A] + Z, AB = p[A + 1] + Z, B = p[X + 1] + Y, BA = p[B] + Z, BB = p[B + 1] + Z, AAA = p[AA] + W, AAB = p[AA + 1] + W, ABA = p[AB] + W, ABB = p[AB + 1] + W, BAA = p[BA] + W, BAB = p[BA + 1] + W, BBA = p[BB] + W, BBB = p[BB + 1] + W;
|
125
|
+
return lerp(s, lerp(t, lerp(v, lerp(u, grad(p[AAA], x, y, z, w), grad(p[BAA], x - 1, y, z, w)), lerp(u, grad(p[ABA], x, y - 1, z, w), grad(p[BBA], x - 1, y - 1, z, w))), lerp(v, lerp(u, grad(p[AAB], x, y, z - 1, w), grad(p[BAB], x - 1, y, z - 1, w)), lerp(u, grad(p[ABB], x, y - 1, z - 1, w), grad(p[BBB], x - 1, y - 1, z - 1, w)))), lerp(t, lerp(v, lerp(u, grad(p[AAA + 1], x, y, z, w - 1), grad(p[BAA + 1], x - 1, y, z, w - 1)), lerp(u, grad(p[ABA + 1], x, y - 1, z, w - 1), grad(p[BBA + 1], x - 1, y - 1, z, w - 1))), lerp(v, lerp(u, grad(p[AAB + 1], x, y, z - 1, w - 1), grad(p[BAB + 1], x - 1, y, z - 1, w - 1)), lerp(u, grad(p[ABB + 1], x, y - 1, z - 1, w - 1), grad(p[BBB + 1], x - 1, y - 1, z - 1, w - 1)))));
|
126
|
+
}
|
127
|
+
|
128
|
+
public static final float snoise(Point2 p) {
|
129
|
+
return snoise(p.x, p.y);
|
130
|
+
}
|
131
|
+
|
132
|
+
public static final float snoise(Point3 p) {
|
133
|
+
return snoise(p.x, p.y, p.z);
|
134
|
+
}
|
135
|
+
|
136
|
+
public static final float snoise(Point3 p, float t) {
|
137
|
+
return snoise(p.x, p.y, p.z, t);
|
138
|
+
}
|
139
|
+
|
140
|
+
public static final float noise(float x) {
|
141
|
+
return 0.5f + 0.5f * snoise(x);
|
142
|
+
}
|
143
|
+
|
144
|
+
public static final float noise(float x, float y) {
|
145
|
+
return 0.5f + 0.5f * snoise(x, y);
|
146
|
+
}
|
147
|
+
|
148
|
+
public static final float noise(float x, float y, float z) {
|
149
|
+
return 0.5f + 0.5f * snoise(x, y, z);
|
150
|
+
}
|
151
|
+
|
152
|
+
public static final float noise(float x, float y, float z, float t) {
|
153
|
+
return 0.5f + 0.5f * snoise(x, y, z, t);
|
154
|
+
}
|
155
|
+
|
156
|
+
public static final float noise(Point2 p) {
|
157
|
+
return 0.5f + 0.5f * snoise(p.x, p.y);
|
158
|
+
}
|
159
|
+
|
160
|
+
public static final float noise(Point3 p) {
|
161
|
+
return 0.5f + 0.5f * snoise(p.x, p.y, p.z);
|
162
|
+
}
|
163
|
+
|
164
|
+
public static final float noise(Point3 p, float t) {
|
165
|
+
return 0.5f + 0.5f * snoise(p.x, p.y, p.z, t);
|
166
|
+
}
|
167
|
+
|
168
|
+
public static final float pnoise(float xi, float period) {
|
169
|
+
float x = (xi % period) + ((xi < 0) ? period : 0);
|
170
|
+
return ((period - x) * noise(x) + x * noise(x - period)) / period;
|
171
|
+
}
|
172
|
+
|
173
|
+
public static final float pnoise(float xi, float yi, float w, float h) {
|
174
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
175
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
176
|
+
float w_x = w - x;
|
177
|
+
float h_y = h - y;
|
178
|
+
float x_w = x - w;
|
179
|
+
float y_h = y - h;
|
180
|
+
return (noise(x, y) * (w_x) * (h_y) + noise(x_w, y) * (x) * (h_y) + noise(x_w, y_h) * (x) * (y) + noise(x, y_h) * (w_x) * (y)) / (w * h);
|
181
|
+
}
|
182
|
+
|
183
|
+
public static final float pnoise(float xi, float yi, float zi, float w, float h, float d) {
|
184
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
185
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
186
|
+
float z = (zi % d) + ((zi < 0) ? d : 0);
|
187
|
+
float w_x = w - x;
|
188
|
+
float h_y = h - y;
|
189
|
+
float d_z = d - z;
|
190
|
+
float x_w = x - w;
|
191
|
+
float y_h = y - h;
|
192
|
+
float z_d = z - d;
|
193
|
+
float xy = x * y;
|
194
|
+
float h_yXd_z = h_y * d_z;
|
195
|
+
float h_yXz = h_y * z;
|
196
|
+
float w_xXy = w_x * y;
|
197
|
+
return (noise(x, y, z) * (w_x) * h_yXd_z + noise(x, y_h, z) * w_xXy * (d_z) + noise(x_w, y, z) * (x) * h_yXd_z + noise(x_w, y_h, z) * (xy) * (d_z) + noise(x_w, y_h, z_d) * (xy) * (z) + noise(x, y, z_d) * (w_x) * h_yXz + noise(x, y_h, z_d) * w_xXy * (z) + noise(x_w, y, z_d) * (x) * h_yXz) / (w * h * d);
|
198
|
+
}
|
199
|
+
|
200
|
+
public static final float pnoise(float xi, float yi, float zi, float ti, float w, float h, float d, float p) {
|
201
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
202
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
203
|
+
float z = (zi % d) + ((zi < 0) ? d : 0);
|
204
|
+
float t = (ti % p) + ((ti < 0) ? p : 0);
|
205
|
+
float w_x = w - x;
|
206
|
+
float h_y = h - y;
|
207
|
+
float d_z = d - z;
|
208
|
+
float p_t = p - t;
|
209
|
+
float x_w = x - w;
|
210
|
+
float y_h = y - h;
|
211
|
+
float z_d = z - d;
|
212
|
+
float t_p = t - p;
|
213
|
+
float xy = x * y;
|
214
|
+
float d_zXp_t = (d_z) * (p_t);
|
215
|
+
float zXp_t = z * (p_t);
|
216
|
+
float zXt = z * t;
|
217
|
+
float d_zXt = d_z * t;
|
218
|
+
float w_xXy = w_x * y;
|
219
|
+
float w_xXh_y = w_x * h_y;
|
220
|
+
float xXh_y = x * h_y;
|
221
|
+
return (noise(x, y, z, t) * (w_xXh_y) * d_zXp_t + noise(x_w, y, z, t) * (xXh_y) * d_zXp_t + noise(x_w, y_h, z, t) * (xy) * d_zXp_t + noise(x, y_h, z, t) * (w_xXy) * d_zXp_t + noise(x_w, y_h, z_d, t) * (xy) * (zXp_t) + noise(x, y, z_d, t) * (w_xXh_y) * (zXp_t) + noise(x, y_h, z_d, t) * (w_xXy) * (zXp_t) + noise(x_w, y, z_d, t) * (xXh_y) * (zXp_t) + noise(x, y, z, t_p) * (w_xXh_y) * (d_zXt) + noise(x_w, y, z, t_p) * (xXh_y) * (d_zXt) + noise(x_w, y_h, z, t_p) * (xy) * (d_zXt) + noise(x, y_h, z, t_p) * (w_xXy) * (d_zXt) + noise(x_w, y_h, z_d, t_p) * (xy) * (zXt) + noise(x, y, z_d, t_p) * (w_xXh_y) * (zXt) + noise(x, y_h, z_d, t_p) * (w_xXy) * (zXt) + noise(x_w, y, z_d, t_p) * (xXh_y) * (zXt)) / (w * h * d * t);
|
222
|
+
}
|
223
|
+
|
224
|
+
public static final float pnoise(Point2 p, float periodx, float periody) {
|
225
|
+
return pnoise(p.x, p.y, periodx, periody);
|
226
|
+
}
|
227
|
+
|
228
|
+
public static final float pnoise(Point3 p, Vector3 period) {
|
229
|
+
return pnoise(p.x, p.y, p.z, period.x, period.y, period.z);
|
230
|
+
}
|
231
|
+
|
232
|
+
public static final float pnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
|
233
|
+
return pnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
|
234
|
+
}
|
235
|
+
|
236
|
+
public static final float spnoise(float xi, float period) {
|
237
|
+
float x = (xi % period) + ((xi < 0) ? period : 0);
|
238
|
+
return (((period - x) * snoise(x) + x * snoise(x - period)) / period);
|
239
|
+
}
|
240
|
+
|
241
|
+
public static final float spnoise(float xi, float yi, float w, float h) {
|
242
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
243
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
244
|
+
float w_x = w - x;
|
245
|
+
float h_y = h - y;
|
246
|
+
float x_w = x - w;
|
247
|
+
float y_h = y - h;
|
248
|
+
return ((snoise(x, y) * (w_x) * (h_y) + snoise(x_w, y) * (x) * (h_y) + snoise(x_w, y_h) * (x) * (y) + snoise(x, y_h) * (w_x) * (y)) / (w * h));
|
249
|
+
}
|
250
|
+
|
251
|
+
public static final float spnoise(float xi, float yi, float zi, float w, float h, float d) {
|
252
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
253
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
254
|
+
float z = (zi % d) + ((zi < 0) ? d : 0);
|
255
|
+
float w_x = w - x;
|
256
|
+
float h_y = h - y;
|
257
|
+
float d_z = d - z;
|
258
|
+
float x_w = x - w;
|
259
|
+
float y_h = y - h;
|
260
|
+
float z_d = z - d;
|
261
|
+
float xy = x * y;
|
262
|
+
float h_yXd_z = h_y * d_z;
|
263
|
+
float h_yXz = h_y * z;
|
264
|
+
float w_xXy = w_x * y;
|
265
|
+
return ((snoise(x, y, z) * (w_x) * h_yXd_z + snoise(x, y_h, z) * w_xXy * (d_z) + snoise(x_w, y, z) * (x) * h_yXd_z + snoise(x_w, y_h, z) * (xy) * (d_z) + snoise(x_w, y_h, z_d) * (xy) * (z) + snoise(x, y, z_d) * (w_x) * h_yXz + snoise(x, y_h, z_d) * w_xXy * (z) + snoise(x_w, y, z_d) * (x) * h_yXz) / (w * h * d));
|
266
|
+
}
|
267
|
+
|
268
|
+
public static final float spnoise(float xi, float yi, float zi, float ti, float w, float h, float d, float p) {
|
269
|
+
float x = (xi % w) + ((xi < 0) ? w : 0);
|
270
|
+
float y = (yi % h) + ((yi < 0) ? h : 0);
|
271
|
+
float z = (zi % d) + ((zi < 0) ? d : 0);
|
272
|
+
float t = (ti % p) + ((ti < 0) ? p : 0);
|
273
|
+
float w_x = w - x;
|
274
|
+
float h_y = h - y;
|
275
|
+
float d_z = d - z;
|
276
|
+
float p_t = p - t;
|
277
|
+
float x_w = x - w;
|
278
|
+
float y_h = y - h;
|
279
|
+
float z_d = z - d;
|
280
|
+
float t_p = t - p;
|
281
|
+
float xy = x * y;
|
282
|
+
float d_zXp_t = (d_z) * (p_t);
|
283
|
+
float zXp_t = z * (p_t);
|
284
|
+
float zXt = z * t;
|
285
|
+
float d_zXt = d_z * t;
|
286
|
+
float w_xXy = w_x * y;
|
287
|
+
float w_xXh_y = w_x * h_y;
|
288
|
+
float xXh_y = x * h_y;
|
289
|
+
return ((snoise(x, y, z, t) * (w_xXh_y) * d_zXp_t + snoise(x_w, y, z, t) * (xXh_y) * d_zXp_t + snoise(x_w, y_h, z, t) * (xy) * d_zXp_t + snoise(x, y_h, z, t) * (w_xXy) * d_zXp_t + snoise(x_w, y_h, z_d, t) * (xy) * (zXp_t) + snoise(x, y, z_d, t) * (w_xXh_y) * (zXp_t) + snoise(x, y_h, z_d, t) * (w_xXy) * (zXp_t) + snoise(x_w, y, z_d, t) * (xXh_y) * (zXp_t) + snoise(x, y, z, t_p) * (w_xXh_y) * (d_zXt) + snoise(x_w, y, z, t_p) * (xXh_y) * (d_zXt) + snoise(x_w, y_h, z, t_p) * (xy) * (d_zXt) + snoise(x, y_h, z, t_p) * (w_xXy) * (d_zXt) + snoise(x_w, y_h, z_d, t_p) * (xy) * (zXt) + snoise(x, y, z_d, t_p) * (w_xXh_y) * (zXt) + snoise(x, y_h, z_d, t_p) * (w_xXy) * (zXt) + snoise(x_w, y, z_d, t_p) * (xXh_y) * (zXt)) / (w * h * d * t));
|
290
|
+
}
|
291
|
+
|
292
|
+
public static final float spnoise(Point2 p, float periodx, float periody) {
|
293
|
+
return spnoise(p.x, p.y, periodx, periody);
|
294
|
+
}
|
295
|
+
|
296
|
+
public static final float spnoise(Point3 p, Vector3 period) {
|
297
|
+
return spnoise(p.x, p.y, p.z, period.x, period.y, period.z);
|
298
|
+
}
|
299
|
+
|
300
|
+
public static final float spnoise(Point3 p, float t, Vector3 pperiod, float tperiod) {
|
301
|
+
return spnoise(p.x, p.y, p.z, t, pperiod.x, pperiod.y, pperiod.z, tperiod);
|
302
|
+
}
|
303
|
+
|
304
|
+
private static final float fade(float t) {
|
305
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
306
|
+
}
|
307
|
+
|
308
|
+
private static final float lerp(float t, float a, float b) {
|
309
|
+
return a + t * (b - a);
|
310
|
+
}
|
311
|
+
|
312
|
+
private static final float grad(int hash, float x) {
|
313
|
+
int h = hash & 0x1;
|
314
|
+
return x * G1[h];
|
315
|
+
}
|
316
|
+
|
317
|
+
private static final float grad(int hash, float x, float y) {
|
318
|
+
int h = hash & 0x3;
|
319
|
+
return x * G2[h][0] + y * G2[h][1];
|
320
|
+
}
|
321
|
+
|
322
|
+
private static final float grad(int hash, float x, float y, float z) {
|
323
|
+
int h = hash & 15;
|
324
|
+
return x * G3[h][0] + y * G3[h][1] + z * G3[h][2];
|
325
|
+
}
|
326
|
+
|
327
|
+
private static final float grad(int hash, float x, float y, float z, float w) {
|
328
|
+
int h = hash & 31;
|
329
|
+
return x * G4[h][0] + y * G4[h][1] + z * G4[h][2] + w * G4[h][3];
|
330
|
+
}
|
331
|
+
}
|