Package org.sunflow.core
Class ShadingState
java.lang.Object
org.sunflow.core.ShadingState
- All Implemented Interfaces:
Iterable<LightSample>
Represents a point to be shaded and provides various options for the shading
of this point, including spawning of new rays.
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addSample
(LightSample sample) Add the specified light sample to the list of lights to be usedfinal Color
Computes a plain diffuse response to the current light samples and global illumination.final void
Flip the surface normals to ensure they are facing the current ray.final OrthoNormalBasis
getBasis()
Gets the local orthonormal basis for the current hit point.final Matrix4
Get a transformation matrix that will transform camera space points into world space.final float
getCosND()
Cosine between the shading normal and the ray.final int
getDepth()
Get the current total tracing depth.final int
Get the current diffuse tracing depth.final Vector3
Gets the geometric normal of the current hit point.final Color
Returns the glboal diffuse radiance estimate given by the currentGIEngine
if present.final Instance
Get the instance which was intersectedfinal Color
getIrradiance
(Color diffuseReflectance) Gets the total irradiance reaching the current point from diffuse surfaces.final Vector3
Get shading normal at the hit point.final Point3
getPoint()
Get hit point.final int
Get the primitive ID which was intersectedfinal double
getRandom
(int j, int dim) Get a QMC sample from an infinite sequence.final double
getRandom
(int j, int dim, int n) Get a QMC sample from a finite sequence of n elements.final float
Get x coordinate of the pixel being shaded.final float
Get y coordinate of the pixel being shaded.final Ray
getRay()
Gets the ray that is associated with this state.final int
Get the current reflection tracing depth.final int
Get the current refraction tracing depth.final Color
Get the result of shading this pointfinal Shader
Get the shader to be used to shade this surface.final int
final boolean
getTrianglePoints
(Point3[] p) Get the three triangle corners in object space if the hit object is a mesh, returns false otherwise.final float
getU()
Get u barycentric coordinate of the intersection point.final Point2
getUV()
Get texture coordinates at the hit point.final float
getV()
Get v barycentric coordinate of the intersection point.final float
getW()
Get w barycentric coordinate of the intersection point.final Matrix4
Get a transformation matrix that will transform world space points into camera space.final boolean
Checks to see if the shader should include emitted light.final boolean
Checks to see if the shader should include specular terms.final void
init()
Create objects needed for surface shading: point, normal, texture coordinates and basis.final void
Add caustic samples to the current light sample set.final void
Initialize the use of light samples.final boolean
isBehind()
Returns true if the ray hit the surface from behind.iterator()
Allows iteration over current light samples.final Color
occlusion
(int samples, float maxDist) Simple black and white ambient occlusion.final Color
Ambient occlusion routine, returns a value between bright and dark depending on the amount of geometric occlusion in the scene.final void
setBasis
(OrthoNormalBasis basis) Define the orthonormal basis for the current hit point.final void
setModifier
(Modifier modifier) Record which modifier should be applied to the intersected surfacefinal void
Record which shader should be executed for the intersected surface.final Color
shade()
Run the shader at this surface point.final Color
specularPhong
(Color spec, float power, int numRays) Computes a phong specular response to the current light samples and global illumination.final void
storePhoton
(Vector3 dir, Color power, Color diffuse) Records a photon at the specified location.final void
traceDiffusePhoton
(Ray r, Color power) Trace a new photon from the current location.final ShadingState
traceFinalGather
(Ray r, int i) Trace a final gather ray and return the intersection result as a new render statefinal Color
traceGlossy
(Ray r, int i) Returns the color obtained by recursively tracing the specified ray.final Color
traceReflection
(Ray r, int i) Returns the color obtained by recursively tracing the specified ray.final void
traceReflectionPhoton
(Ray r, Color power) Trace a new photon from the current location.final Color
traceRefraction
(Ray r, int i) Returns the color obtained by recursively tracing the specified ray.final void
traceRefractionPhoton
(Ray r, Color power) Trace a new photon from the current location.final Color
traceShadow
(Ray r) Trace a shadow ray against the scene, and computes the accumulated opacity along the ray.final Color
Trace transparency, this is equivalent to tracing a refraction ray in the incoming ray direction.traceTransparentShadow
(float oldMaxT) Transform the given normal from object space to world space.Transform the given normal from world space to object space.Transform the given point from object space to world space.Transform the given vector from object space to world space.Transform the given vector from world space to object space.Transform the given point from world space to object space.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
init
public final void init()Create objects needed for surface shading: point, normal, texture coordinates and basis. -
shade
Run the shader at this surface point.- Returns:
- shaded result
-
faceforward
public final void faceforward()Flip the surface normals to ensure they are facing the current ray. This method also offsets the shading point away from the surface so that new rays will not intersect the same surface again by mistake. -
getRasterX
public final float getRasterX()Get x coordinate of the pixel being shaded.- Returns:
- pixel x coordinate
-
getRasterY
public final float getRasterY()Get y coordinate of the pixel being shaded.- Returns:
- pixel y coordinate
-
getCosND
public final float getCosND()Cosine between the shading normal and the ray. This is set byfaceforward()
.- Returns:
- cosine between shading normal and the ray
-
isBehind
public final boolean isBehind()Returns true if the ray hit the surface from behind. This is set byfaceforward()
.- Returns:
true
if the surface was hit from behind.
-
getU
public final float getU()Get u barycentric coordinate of the intersection point.- Returns:
- u barycentric coordinate
-
getV
public final float getV()Get v barycentric coordinate of the intersection point.- Returns:
- v barycentric coordinate
-
getW
public final float getW()Get w barycentric coordinate of the intersection point.- Returns:
- w barycentric coordinate
-
getInstance
Get the instance which was intersected- Returns:
- intersected instance object
-
getPrimitiveID
public final int getPrimitiveID()Get the primitive ID which was intersected- Returns:
- intersected primitive ID
-
transformObjectToWorld
Transform the given point from object space to world space. A newPoint3
object is returned.- Parameters:
p
- object space position to transform- Returns:
- transformed position
-
transformWorldToObject
Transform the given point from world space to object space. A newPoint3
object is returned.- Parameters:
p
- world space position to transform- Returns:
- transformed position
-
transformNormalObjectToWorld
Transform the given normal from object space to world space. A newVector3
object is returned.- Parameters:
n
- object space normal to transform- Returns:
- transformed normal
-
transformNormalWorldToObject
Transform the given normal from world space to object space. A newVector3
object is returned.- Parameters:
n
- world space normal to transform- Returns:
- transformed normal
-
transformVectorObjectToWorld
Transform the given vector from object space to world space. A newVector3
object is returned.- Parameters:
v
- object space vector to transform- Returns:
- transformed vector
-
transformVectorWorldToObject
Transform the given vector from world space to object space. A newVector3
object is returned.- Parameters:
v
- world space vector to transform- Returns:
- transformed vector
-
getResult
Get the result of shading this point- Returns:
- shaded result
-
addSample
Add the specified light sample to the list of lights to be used- Parameters:
sample
- a valid light sample
-
getRandom
public final double getRandom(int j, int dim) Get a QMC sample from an infinite sequence.- Parameters:
j
- sample number (starts from 0)dim
- dimension to sample- Returns:
- pseudo-random value in [0,1)
-
getRandom
public final double getRandom(int j, int dim, int n) Get a QMC sample from a finite sequence of n elements. This provides better stratification than the infinite version, but does not allow for adaptive sampling.- Parameters:
j
- sample number (starts from 0)dim
- dimension to samplen
- number of samples- Returns:
- pseudo-random value in [0,1)
-
includeLights
public final boolean includeLights()Checks to see if the shader should include emitted light.- Returns:
true
if emitted light should be included,false
otherwise
-
includeSpecular
public final boolean includeSpecular()Checks to see if the shader should include specular terms.- Returns:
true
if specular terms should be included,false
otherwise
-
getShader
Get the shader to be used to shade this surface.- Returns:
- shader to be used
-
setShader
Record which shader should be executed for the intersected surface.- Parameters:
shader
- surface shader to use to shade the current intersection point
-
setModifier
Record which modifier should be applied to the intersected surface- Parameters:
modifier
- modifier to use the change this shading state
-
getDepth
public final int getDepth()Get the current total tracing depth. First generation rays have a depth of 0.- Returns:
- current tracing depth
-
getDiffuseDepth
public final int getDiffuseDepth()Get the current diffuse tracing depth. This is the number of diffuse surfaces reflected from.- Returns:
- current diffuse tracing depth
-
getReflectionDepth
public final int getReflectionDepth()Get the current reflection tracing depth. This is the number of specular surfaces reflected from.- Returns:
- current reflection tracing depth
-
getRefractionDepth
public final int getRefractionDepth()Get the current refraction tracing depth. This is the number of specular surfaces refracted from.- Returns:
- current refraction tracing depth
-
getPoint
Get hit point.- Returns:
- hit point
-
getNormal
Get shading normal at the hit point. This may differ from the geometric normal- Returns:
- shading normal
-
getUV
Get texture coordinates at the hit point.- Returns:
- texture coordinate
-
getGeoNormal
Gets the geometric normal of the current hit point.- Returns:
- geometric normal of the current hit point
-
getBasis
Gets the local orthonormal basis for the current hit point.- Returns:
- local basis or
null
if undefined
-
setBasis
Define the orthonormal basis for the current hit point.- Parameters:
basis
-
-
getRay
Gets the ray that is associated with this state.- Returns:
- ray associated with this state.
-
getCameraToWorld
Get a transformation matrix that will transform camera space points into world space.- Returns:
- camera to world transform
-
getWorldToCamera
Get a transformation matrix that will transform world space points into camera space.- Returns:
- world to camera transform
-
getTrianglePoints
Get the three triangle corners in object space if the hit object is a mesh, returns false otherwise.- Parameters:
p
- array of 3 points- Returns:
true
if the points were read succesfully,false
otherwise
-
initLightSamples
public final void initLightSamples()Initialize the use of light samples. Prepares a list of visible lights from the current point. -
initCausticSamples
public final void initCausticSamples()Add caustic samples to the current light sample set. This method does nothing if caustics are not enabled. -
traceGlossy
Returns the color obtained by recursively tracing the specified ray. The reflection is assumed to be glossy.- Parameters:
r
- ray to tracei
- instance number of this sample- Returns:
- color observed along specified ray.
-
traceReflection
Returns the color obtained by recursively tracing the specified ray. The reflection is assumed to be specular.- Parameters:
r
- ray to tracei
- instance number of this sample- Returns:
- color observed along specified ray.
-
traceRefraction
Returns the color obtained by recursively tracing the specified ray.- Parameters:
r
- ray to tracei
- instance number of this sample- Returns:
- color observed along specified ray.
-
traceTransparency
Trace transparency, this is equivalent to tracing a refraction ray in the incoming ray direction.- Returns:
- color observed behind the current shading point
-
traceShadow
Trace a shadow ray against the scene, and computes the accumulated opacity along the ray.- Parameters:
r
- ray to trace- Returns:
- opacity along the shadow ray
-
storePhoton
Records a photon at the specified location.- Parameters:
dir
- incoming direction of the photonpower
- photon powerdiffuse
- diffuse reflectance at the given point
-
traceReflectionPhoton
Trace a new photon from the current location. This assumes that the photon was reflected by a specular surface.- Parameters:
r
- ray to trace photon alongpower
- power of the new photon
-
traceRefractionPhoton
Trace a new photon from the current location. This assumes that the photon was refracted by a specular surface.- Parameters:
r
- ray to trace photon alongpower
- power of the new photon
-
traceDiffusePhoton
Trace a new photon from the current location. This assumes that the photon was reflected by a diffuse surface.- Parameters:
r
- ray to trace photon alongpower
- power of the new photon
-
getGlobalRadiance
Returns the glboal diffuse radiance estimate given by the currentGIEngine
if present.- Returns:
- global diffuse radiance estimate
-
getIrradiance
Gets the total irradiance reaching the current point from diffuse surfaces.- Parameters:
diffuseReflectance
- diffuse reflectance at the current point, can be used for importance tracking- Returns:
- indirect diffuse irradiance reaching the point
-
traceFinalGather
Trace a final gather ray and return the intersection result as a new render state- Parameters:
r
- ray to shooti
- instance of the ray- Returns:
- new render state object corresponding to the intersection result
-
occlusion
Simple black and white ambient occlusion.- Parameters:
samples
- number of sample raysmaxDist
- maximum length of the rays- Returns:
- occlusion color
-
occlusion
Ambient occlusion routine, returns a value between bright and dark depending on the amount of geometric occlusion in the scene.- Parameters:
samples
- number of sample raysmaxDist
- maximum length of the raysbright
- color when nothing is occludeddark
- color when fully occluded- Returns:
- occlusion color
-
diffuse
Computes a plain diffuse response to the current light samples and global illumination.- Parameters:
diff
- diffuse color- Returns:
- shaded result
-
specularPhong
Computes a phong specular response to the current light samples and global illumination.- Parameters:
spec
- specular colorpower
- phong exponentnumRays
- number of glossy rays to trace- Returns:
- shaded color
-
iterator
Allows iteration over current light samples.- Specified by:
iterator
in interfaceIterable<LightSample>
-
getShadowDepth
public final int getShadowDepth() -
traceTransparentShadow
-