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,296 @@
|
|
1
|
+
package org.sunflow.core.light;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Instance;
|
5
|
+
import org.sunflow.core.LightSample;
|
6
|
+
import org.sunflow.core.LightSource;
|
7
|
+
import org.sunflow.core.ParameterList;
|
8
|
+
import org.sunflow.core.Ray;
|
9
|
+
import org.sunflow.core.Shader;
|
10
|
+
import org.sunflow.core.ShadingState;
|
11
|
+
import org.sunflow.core.primitive.TriangleMesh;
|
12
|
+
import org.sunflow.image.Color;
|
13
|
+
import org.sunflow.math.MathUtils;
|
14
|
+
import org.sunflow.math.OrthoNormalBasis;
|
15
|
+
import org.sunflow.math.Point3;
|
16
|
+
import org.sunflow.math.Vector3;
|
17
|
+
|
18
|
+
public class TriangleMeshLight extends TriangleMesh implements Shader, LightSource {
|
19
|
+
|
20
|
+
private Color radiance;
|
21
|
+
private int numSamples;
|
22
|
+
private float[] areas;
|
23
|
+
private float totalArea;
|
24
|
+
private Vector3[] ngs;
|
25
|
+
|
26
|
+
public TriangleMeshLight() {
|
27
|
+
radiance = Color.WHITE;
|
28
|
+
numSamples = 4;
|
29
|
+
}
|
30
|
+
|
31
|
+
@Override
|
32
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
33
|
+
radiance = pl.getColor("radiance", radiance);
|
34
|
+
numSamples = pl.getInt("samples", numSamples);
|
35
|
+
if (super.update(pl, api)) {
|
36
|
+
// precompute triangle areas and normals
|
37
|
+
areas = new float[getNumPrimitives()];
|
38
|
+
ngs = new Vector3[getNumPrimitives()];
|
39
|
+
totalArea = 0;
|
40
|
+
for (int tri3 = 0, i = 0; tri3 < triangles.length; tri3 += 3, i++) {
|
41
|
+
int a = triangles[tri3 + 0];
|
42
|
+
int b = triangles[tri3 + 1];
|
43
|
+
int c = triangles[tri3 + 2];
|
44
|
+
Point3 v0p = getPoint(a);
|
45
|
+
Point3 v1p = getPoint(b);
|
46
|
+
Point3 v2p = getPoint(c);
|
47
|
+
ngs[i] = Point3.normal(v0p, v1p, v2p);
|
48
|
+
areas[i] = 0.5f * ngs[i].length();
|
49
|
+
ngs[i].normalize();
|
50
|
+
totalArea += areas[i];
|
51
|
+
}
|
52
|
+
} else {
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
return true;
|
56
|
+
}
|
57
|
+
|
58
|
+
private boolean intersectTriangleKensler(int tri3, Ray r) {
|
59
|
+
int a = 3 * triangles[tri3 + 0];
|
60
|
+
int b = 3 * triangles[tri3 + 1];
|
61
|
+
int c = 3 * triangles[tri3 + 2];
|
62
|
+
float edge0x = points[b + 0] - points[a + 0];
|
63
|
+
float edge0y = points[b + 1] - points[a + 1];
|
64
|
+
float edge0z = points[b + 2] - points[a + 2];
|
65
|
+
float edge1x = points[a + 0] - points[c + 0];
|
66
|
+
float edge1y = points[a + 1] - points[c + 1];
|
67
|
+
float edge1z = points[a + 2] - points[c + 2];
|
68
|
+
float nx = edge0y * edge1z - edge0z * edge1y;
|
69
|
+
float ny = edge0z * edge1x - edge0x * edge1z;
|
70
|
+
float nz = edge0x * edge1y - edge0y * edge1x;
|
71
|
+
float v = r.dot(nx, ny, nz);
|
72
|
+
float iv = 1 / v;
|
73
|
+
float edge2x = points[a + 0] - r.ox;
|
74
|
+
float edge2y = points[a + 1] - r.oy;
|
75
|
+
float edge2z = points[a + 2] - r.oz;
|
76
|
+
float va = nx * edge2x + ny * edge2y + nz * edge2z;
|
77
|
+
float t = iv * va;
|
78
|
+
if (t <= 0) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
float ix = edge2y * r.dz - edge2z * r.dy;
|
82
|
+
float iy = edge2z * r.dx - edge2x * r.dz;
|
83
|
+
float iz = edge2x * r.dy - edge2y * r.dx;
|
84
|
+
float v1 = ix * edge1x + iy * edge1y + iz * edge1z;
|
85
|
+
float beta = iv * v1;
|
86
|
+
if (beta < 0) {
|
87
|
+
return false;
|
88
|
+
}
|
89
|
+
float v2 = ix * edge0x + iy * edge0y + iz * edge0z;
|
90
|
+
if ((v1 + v2) * v > v * v) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
float gamma = iv * v2;
|
94
|
+
if (gamma < 0) {
|
95
|
+
return false;
|
96
|
+
}
|
97
|
+
// FIXME: arbitrary bias, should handle as in other places
|
98
|
+
r.setMax(t - 1e-3f);
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
|
102
|
+
@Override
|
103
|
+
public Color getRadiance(ShadingState state) {
|
104
|
+
if (!state.includeLights()) {
|
105
|
+
return Color.BLACK;
|
106
|
+
}
|
107
|
+
state.faceforward();
|
108
|
+
// emit constant radiance
|
109
|
+
return state.isBehind() ? Color.BLACK : radiance;
|
110
|
+
}
|
111
|
+
|
112
|
+
@Override
|
113
|
+
public void scatterPhoton(ShadingState state, Color power) {
|
114
|
+
// do not scatter photons
|
115
|
+
}
|
116
|
+
|
117
|
+
@Override
|
118
|
+
public Instance createInstance() {
|
119
|
+
return Instance.createTemporary(this, null, this);
|
120
|
+
}
|
121
|
+
|
122
|
+
@Override
|
123
|
+
public int getNumSamples() {
|
124
|
+
return numSamples * getNumPrimitives();
|
125
|
+
}
|
126
|
+
|
127
|
+
@Override
|
128
|
+
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) {
|
129
|
+
double rnd = randX1 * totalArea;
|
130
|
+
int j = areas.length - 1;
|
131
|
+
for (int i = 0; i < areas.length; i++) {
|
132
|
+
if (rnd < areas[i]) {
|
133
|
+
j = i;
|
134
|
+
break;
|
135
|
+
}
|
136
|
+
rnd -= areas[i]; // try next triangle
|
137
|
+
}
|
138
|
+
rnd /= areas[j];
|
139
|
+
randX1 = rnd;
|
140
|
+
double s = Math.sqrt(1 - randX2);
|
141
|
+
float u = (float) (randY2 * s);
|
142
|
+
float v = (float) (1 - s);
|
143
|
+
float w = 1 - u - v;
|
144
|
+
int tri3 = j * 3;
|
145
|
+
int index0 = 3 * triangles[tri3 + 0];
|
146
|
+
int index1 = 3 * triangles[tri3 + 1];
|
147
|
+
int index2 = 3 * triangles[tri3 + 2];
|
148
|
+
p.x = w * points[index0 + 0] + u * points[index1 + 0] + v * points[index2 + 0];
|
149
|
+
p.y = w * points[index0 + 1] + u * points[index1 + 1] + v * points[index2 + 1];
|
150
|
+
p.z = w * points[index0 + 2] + u * points[index1 + 2] + v * points[index2 + 2];
|
151
|
+
p.x += 0.001f * ngs[j].x;
|
152
|
+
p.y += 0.001f * ngs[j].y;
|
153
|
+
p.z += 0.001f * ngs[j].z;
|
154
|
+
OrthoNormalBasis onb = OrthoNormalBasis.makeFromW(ngs[j]);
|
155
|
+
u = (float) (2 * Math.PI * randX1);
|
156
|
+
s = Math.sqrt(randY1);
|
157
|
+
onb.transform(new Vector3((float) (Math.cos(u) * s), (float) (Math.sin(u) * s), (float) (Math.sqrt(1 - randY1))), dir);
|
158
|
+
Color.mul((float) Math.PI * areas[j], radiance, power);
|
159
|
+
}
|
160
|
+
|
161
|
+
@Override
|
162
|
+
public float getPower() {
|
163
|
+
return radiance.copy().mul((float) Math.PI * totalArea).getLuminance();
|
164
|
+
}
|
165
|
+
|
166
|
+
@Override
|
167
|
+
public void getSamples(ShadingState state) {
|
168
|
+
if (numSamples == 0) {
|
169
|
+
return;
|
170
|
+
}
|
171
|
+
Vector3 n = state.getNormal();
|
172
|
+
Point3 p = state.getPoint();
|
173
|
+
for (int tri3 = 0, i = 0; tri3 < triangles.length; tri3 += 3, i++) {
|
174
|
+
// vector towards each vertex of the light source
|
175
|
+
Vector3 p0 = Point3.sub(getPoint(triangles[tri3 + 0]), p, new Vector3());
|
176
|
+
// cull triangle if it is facing the wrong way
|
177
|
+
if (Vector3.dot(p0, ngs[i]) >= 0) {
|
178
|
+
continue;
|
179
|
+
}
|
180
|
+
Vector3 p1 = Point3.sub(getPoint(triangles[tri3 + 1]), p, new Vector3());
|
181
|
+
Vector3 p2 = Point3.sub(getPoint(triangles[tri3 + 2]), p, new Vector3());
|
182
|
+
// if all three vertices are below the hemisphere, stop
|
183
|
+
if (Vector3.dot(p0, n) <= 0 && Vector3.dot(p1, n) <= 0 && Vector3.dot(p2, n) <= 0) {
|
184
|
+
continue;
|
185
|
+
}
|
186
|
+
p0.normalize();
|
187
|
+
p1.normalize();
|
188
|
+
p2.normalize();
|
189
|
+
float dot = Vector3.dot(p2, p0);
|
190
|
+
Vector3 h = new Vector3();
|
191
|
+
h.x = p2.x - dot * p0.x;
|
192
|
+
h.y = p2.y - dot * p0.y;
|
193
|
+
h.z = p2.z - dot * p0.z;
|
194
|
+
float hlen = h.length();
|
195
|
+
if (hlen > 1e-6f) {
|
196
|
+
h.div(hlen);
|
197
|
+
} else {
|
198
|
+
continue;
|
199
|
+
}
|
200
|
+
Vector3 n0 = Vector3.cross(p0, p1, new Vector3());
|
201
|
+
float len0 = n0.length();
|
202
|
+
if (len0 > 1e-6f) {
|
203
|
+
n0.div(len0);
|
204
|
+
} else {
|
205
|
+
continue;
|
206
|
+
}
|
207
|
+
Vector3 n1 = Vector3.cross(p1, p2, new Vector3());
|
208
|
+
float len1 = n1.length();
|
209
|
+
if (len1 > 1e-6f) {
|
210
|
+
n1.div(len1);
|
211
|
+
} else {
|
212
|
+
continue;
|
213
|
+
}
|
214
|
+
Vector3 n2 = Vector3.cross(p2, p0, new Vector3());
|
215
|
+
float len2 = n2.length();
|
216
|
+
if (len2 > 1e-6f) {
|
217
|
+
n2.div(len2);
|
218
|
+
} else {
|
219
|
+
continue;
|
220
|
+
}
|
221
|
+
|
222
|
+
float cosAlpha = MathUtils.clamp(-Vector3.dot(n2, n0), -1.0f, 1.0f);
|
223
|
+
float cosBeta = MathUtils.clamp(-Vector3.dot(n0, n1), -1.0f, 1.0f);
|
224
|
+
float cosGamma = MathUtils.clamp(-Vector3.dot(n1, n2), -1.0f, 1.0f);
|
225
|
+
|
226
|
+
float alpha = (float) Math.acos(cosAlpha);
|
227
|
+
float beta = (float) Math.acos(cosBeta);
|
228
|
+
float gamma = (float) Math.acos(cosGamma);
|
229
|
+
|
230
|
+
float area = alpha + beta + gamma - (float) Math.PI;
|
231
|
+
|
232
|
+
float cosC = MathUtils.clamp(Vector3.dot(p0, p1), -1.0f, 1.0f);
|
233
|
+
float salpha = (float) Math.sin(alpha);
|
234
|
+
float product = salpha * cosC;
|
235
|
+
|
236
|
+
// use lower sampling depth for diffuse bounces
|
237
|
+
int samples = state.getDiffuseDepth() > 0 ? 1 : numSamples;
|
238
|
+
Color c = Color.mul(area / samples, radiance);
|
239
|
+
for (int j = 0; j < samples; j++) {
|
240
|
+
// random offset on unit square
|
241
|
+
double randX = state.getRandom(j, 0, samples);
|
242
|
+
double randY = state.getRandom(j, 1, samples);
|
243
|
+
|
244
|
+
float phi = (float) randX * area - alpha + (float) Math.PI;
|
245
|
+
float sinPhi = (float) Math.sin(phi);
|
246
|
+
float cosPhi = (float) Math.cos(phi);
|
247
|
+
|
248
|
+
float u = cosPhi + cosAlpha;
|
249
|
+
float v = sinPhi - product;
|
250
|
+
|
251
|
+
float q = (-v + cosAlpha * (cosPhi * -v + sinPhi * u)) / (salpha * (sinPhi * -v - cosPhi * u));
|
252
|
+
float q1 = 1.0f - q * q;
|
253
|
+
if (q1 < 0.0f) {
|
254
|
+
q1 = 0.0f;
|
255
|
+
}
|
256
|
+
|
257
|
+
float sqrtq1 = (float) Math.sqrt(q1);
|
258
|
+
float ncx = q * p0.x + sqrtq1 * h.x;
|
259
|
+
float ncy = q * p0.y + sqrtq1 * h.y;
|
260
|
+
float ncz = q * p0.z + sqrtq1 * h.z;
|
261
|
+
dot = p1.dot(ncx, ncy, ncz);
|
262
|
+
float z = 1.0f - (float) randY * (1.0f - dot);
|
263
|
+
float z1 = 1.0f - z * z;
|
264
|
+
if (z1 < 0.0f) {
|
265
|
+
z1 = 0.0f;
|
266
|
+
}
|
267
|
+
Vector3 nd = new Vector3();
|
268
|
+
nd.x = ncx - dot * p1.x;
|
269
|
+
nd.y = ncy - dot * p1.y;
|
270
|
+
nd.z = ncz - dot * p1.z;
|
271
|
+
nd.normalize();
|
272
|
+
float sqrtz1 = (float) Math.sqrt(z1);
|
273
|
+
Vector3 result = new Vector3();
|
274
|
+
result.x = z * p1.x + sqrtz1 * nd.x;
|
275
|
+
result.y = z * p1.y + sqrtz1 * nd.y;
|
276
|
+
result.z = z * p1.z + sqrtz1 * nd.z;
|
277
|
+
|
278
|
+
// make sure the sample is in the right hemisphere - facing in
|
279
|
+
// the right direction
|
280
|
+
if (Vector3.dot(result, n) > 0 && Vector3.dot(result, state.getGeoNormal()) > 0 && Vector3.dot(result, ngs[i]) < 0) {
|
281
|
+
// compute intersection with triangle (if any)
|
282
|
+
Ray shadowRay = new Ray(state.getPoint(), result);
|
283
|
+
if (!intersectTriangleKensler(tri3, shadowRay)) {
|
284
|
+
continue;
|
285
|
+
}
|
286
|
+
LightSample dest = new LightSample();
|
287
|
+
dest.setShadowRay(shadowRay);
|
288
|
+
// prepare sample
|
289
|
+
dest.setRadiance(c, c);
|
290
|
+
dest.traceShadow(state);
|
291
|
+
state.addSample(dest);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
package org.sunflow.core.modifiers;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Modifier;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.ShadingState;
|
7
|
+
import org.sunflow.core.Texture;
|
8
|
+
import org.sunflow.core.TextureCache;
|
9
|
+
import org.sunflow.math.OrthoNormalBasis;
|
10
|
+
|
11
|
+
public class BumpMappingModifier implements Modifier {
|
12
|
+
|
13
|
+
private Texture bumpTexture;
|
14
|
+
private float scale;
|
15
|
+
|
16
|
+
public BumpMappingModifier() {
|
17
|
+
bumpTexture = null;
|
18
|
+
scale = 1;
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
23
|
+
String filename = pl.getString("texture", null);
|
24
|
+
if (filename != null) {
|
25
|
+
bumpTexture = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
|
26
|
+
}
|
27
|
+
scale = pl.getFloat("scale", scale);
|
28
|
+
return bumpTexture != null;
|
29
|
+
}
|
30
|
+
|
31
|
+
@Override
|
32
|
+
public void modify(ShadingState state) {
|
33
|
+
// apply bump
|
34
|
+
state.getNormal().set(bumpTexture.getBump(state.getUV().x, state.getUV().y, state.getBasis(), scale));
|
35
|
+
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
package org.sunflow.core.modifiers;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Modifier;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.ShadingState;
|
7
|
+
import org.sunflow.core.Texture;
|
8
|
+
import org.sunflow.core.TextureCache;
|
9
|
+
import org.sunflow.math.OrthoNormalBasis;
|
10
|
+
|
11
|
+
public class NormalMapModifier implements Modifier {
|
12
|
+
|
13
|
+
private Texture normalMap;
|
14
|
+
|
15
|
+
public NormalMapModifier() {
|
16
|
+
normalMap = null;
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
21
|
+
String filename = pl.getString("texture", null);
|
22
|
+
if (filename != null) {
|
23
|
+
normalMap = TextureCache.getTexture(api.resolveTextureFilename(filename), true);
|
24
|
+
}
|
25
|
+
return normalMap != null;
|
26
|
+
}
|
27
|
+
|
28
|
+
@Override
|
29
|
+
public void modify(ShadingState state) {
|
30
|
+
// apply normal map
|
31
|
+
state.getNormal().set(normalMap.getNormal(state.getUV().x, state.getUV().y, state.getBasis()));
|
32
|
+
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
package org.sunflow.core.modifiers;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.core.Modifier;
|
5
|
+
import org.sunflow.core.ParameterList;
|
6
|
+
import org.sunflow.core.ShadingState;
|
7
|
+
import org.sunflow.math.OrthoNormalBasis;
|
8
|
+
import org.sunflow.math.PerlinScalar;
|
9
|
+
import org.sunflow.math.Point3;
|
10
|
+
import org.sunflow.math.Vector3;
|
11
|
+
|
12
|
+
public class PerlinModifier implements Modifier {
|
13
|
+
|
14
|
+
private int function = 0;
|
15
|
+
private float scale = 50;
|
16
|
+
private float size = 1;
|
17
|
+
|
18
|
+
@Override
|
19
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
20
|
+
function = pl.getInt("function", function);
|
21
|
+
size = pl.getFloat("size", size);
|
22
|
+
scale = pl.getFloat("scale", scale);
|
23
|
+
return true;
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
public void modify(ShadingState state) {
|
28
|
+
Point3 p = state.transformWorldToObject(state.getPoint());
|
29
|
+
p.x *= size;
|
30
|
+
p.y *= size;
|
31
|
+
p.z *= size;
|
32
|
+
Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
|
33
|
+
double f0 = f(p.x, p.y, p.z);
|
34
|
+
double fx = f(p.x + .0001, p.y, p.z);
|
35
|
+
double fy = f(p.x, p.y + .0001, p.z);
|
36
|
+
double fz = f(p.x, p.y, p.z + .0001);
|
37
|
+
|
38
|
+
normal.x -= scale * (fx - f0) / .0001;
|
39
|
+
normal.y -= scale * (fy - f0) / .0001;
|
40
|
+
normal.z -= scale * (fz - f0) / .0001;
|
41
|
+
normal.normalize();
|
42
|
+
|
43
|
+
state.getNormal().set(state.transformNormalObjectToWorld(normal));
|
44
|
+
state.getNormal().normalize();
|
45
|
+
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
|
46
|
+
}
|
47
|
+
|
48
|
+
double f(double x, double y, double z) {
|
49
|
+
switch (function) {
|
50
|
+
case 0:
|
51
|
+
return .03 * noise(x, y, z, 8);
|
52
|
+
case 1:
|
53
|
+
return .01 * stripes(x + 2 * turbulence(x, y, z, 1), 1.6);
|
54
|
+
default:
|
55
|
+
return -.10 * turbulence(x, y, z, 1);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
private static double stripes(double x, double f) {
|
60
|
+
double t = .5 + .5 * Math.sin(f * 2 * Math.PI * x);
|
61
|
+
return t * t - .5;
|
62
|
+
}
|
63
|
+
|
64
|
+
private static double turbulence(double x, double y, double z, double freq) {
|
65
|
+
double t = -.5;
|
66
|
+
for (; freq <= 300 / 12; freq *= 2) {
|
67
|
+
t += Math.abs(noise(x, y, z, freq) / freq);
|
68
|
+
}
|
69
|
+
return t;
|
70
|
+
}
|
71
|
+
|
72
|
+
private static double noise(double x, double y, double z, double freq) {
|
73
|
+
double x1, y1, z1;
|
74
|
+
x1 = .707 * x - .707 * z;
|
75
|
+
z1 = .707 * x + .707 * z;
|
76
|
+
y1 = .707 * x1 + .707 * y;
|
77
|
+
x1 = .707 * x1 - .707 * y;
|
78
|
+
return PerlinScalar.snoise((float) (freq * x1 + 100), (float) (freq * y1), (float) (freq * z1));
|
79
|
+
}
|
80
|
+
}
|