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