Nuke binary plugins 16.1.1
 
Loading...
Searching...
No Matches
slr::SlrShadingContext Class Referenceabstract

#include <SlrShadingContext.h>

Public Member Functions

const SlrRayContextsrcRtx () const
 
bool isValid () const
 
 operator bool () const
 
const SlrShadingContextpreviousStx () const
 
SlrShadingContextcreateEditableShadingContextCopy (bool copyShadingLayers=true) const
 
int32_t nShadingChannels () const
 Number of assigned shading channels.
 
void setShadingParamsToZero ()
 Set all param channels in the Stx to 0. Does nothing if Stx is not writable.
 
virtual bool setIntShadingLayer (ndk::Channel chan, int32_t value)=0
 
virtual bool setFloatShadingLayer (ndk::Channel chan, float value)=0
 
virtual bool setVec2fShadingLayer (ndk::Channel startChan, const fdk::Vec2f &value)=0
 
virtual bool setVec3fShadingLayer (ndk::Channel startChan, const fdk::Vec3f &value)=0
 
virtual bool setVec4fShadingLayer (ndk::Channel startChan, const fdk::Vec4f &value)=0
 
virtual bool setDual2fShadingLayer (const Dual2Chans &chans, const Dual2f &value)=0
 
virtual bool setDual2dShadingLayer (const Dual2Chans &chans, const Dual2d &value)=0
 
virtual bool setDual2Vec2fShadingLayer (const Dual2Chans &chans, const Dual2Vec2f &value)=0
 
virtual bool setDual2Vec3fShadingLayer (const Dual2Chans &chans, const Dual2Vec3f &value)=0
 
virtual bool setDual2Vec4fShadingLayer (const Dual2Chans &chans, const Dual2Vec4f &value)=0
 
const SlrThreadContext & threadContext () const
 Thread memory context.
 
SlrIntegratorContextItx () const
 Integrator context that created this shading context.
 
fdk::TimeValue time () const
 Absolute time of the context, same as sampleInfo().time.
 
const SampleInfosampleInfo () const
 
uint32_t threadIndex () const
 Thread index from current SlrThreadContext, guaranteed to be unique and never reused.
 
DD::Image::ThreadId threadId () const
 Thread id from current SlrThreadContext.
 
SlrShaderThreadDatagetShaderThreadData (const SlrShader *shader) const
 
SlrShaderThreadDatagetShaderThreadData (int32_t shaderIdentifierIndex) const
 Same but uses shader index Id (SlrShader::identifierIndex()).
 
ndk::SamplingRng & samplingRng () const
 Sampling random number generator to use for this subpixel sample.
 
int32_t rayId () const
 Ray id of srcRtx.
 
int32_t hitIndex () const
 
uint64_t primId () const
 Unique ID of the current intersection renderable/subpart/subtri.
 
const std::string & primPath () const
 Path of prim currently being evaluated - for debugging only!
 
const SlrPrimInfoprimInfo () const
 Renderable currently being evaluated.
 
SlrPrimInfo::PrimFlag primFlags () const
 
int32_t renderableIndex () const
 PrimInfo index of current intersected object in SlrEngineContext.
 
bool isWritable () const
 This context's shading data can be written to.
 
const fdk::Mat4d & worldToShadingXform () const
 
const fdk::Mat4d & shadingToWorldXform () const
 Inverse of worldToShadingXform, for going from shading space to world.
 
const fdk::Vec3f & worldToShadingOffset () const
 Same as worldToShadingXform but single-precision for ray offset convenience.
 
bool enableColorChannels () const
 Shaders should output color layers + alphas.
 
bool enableDataChannels () const
 Shaders should output any data channels (Z, etc)
 
DD::Image::TextureFiltertextureFilter () const
 Texture filter to use. If null the texture will be impulse sampled.
 
void setTextureFilter (DD::Image::TextureFilter *filter)
 
const fdk::Mat4d & l2w () const
 Local-to-world matrix for current primitive.
 
const fdk::Mat4d & w2l () const
 World-to-local matrix for current primitive.
 
const fdk::Mat4d & camWorld2Eye () const
 Render camera world-to-eye xform (world-space coords to camera local-space)
 
const fdk::Mat4d & camEye2World () const
 Render camera eye-to-world xform (camera local-space coords to world-space)
 
const fdk::Vec3d & camP () const
 
const fdk::Vec3d & camHeroP () const
 Hero-view camera origin in world space - for specular copying.
 
bool useHeroCamForSpec () const
 
bool globalLightingEnabled () const
 If true, even if no lights the surface shaders should do illum calcs.
 
bool globalDirectLightingEnabled () const
 If true do direct-illumination calculations.
 
bool globalIndirectLightingEnabled () const
 If true handle indirect-illumation calculations.
 
bool globalShadowingEnabled () const
 If true do shadow occlusion for direct-illumination.
 
const fdk::Vec3f & ambientLightingBias () const
 
const SlrLightInfoList & allLights () const
 List of all active lights. If lightingEnabled is false an empty list is returned.
 
const SlrPrimEnabledLightingList & enabledLights () const
 
bool surfaceCanReceiveShadowsFor (const SlrPrimEnabledLighting &primLightingInfo) const
 Returns true if the enabled light can shadow this surface.
 
bool surfaceCanCastShadowsFor (const SlrPrimEnabledLighting &primLightingInfo) const
 Returns true if the enabled light can shadow this surface.
 
bool isCameraPath () const
 Did a camera ray create this shading context?
 
bool isThinTransmittedPath () const
 Is the ray that created this shading context evaluating thin transmission?
 
bool isShadowPath () const
 Did a shadow ray create this shading context?
 
bool isReflectedPath () const
 Did a reflected ray create this shading context?
 
bool isRefractedPath () const
 Did a refracted ray create this shading context?
 
float indexOfRefraction () const
 Index of refraction (ior) of the hit surface.
 
void setIndexOfRefraction (float ior)
 
float outsideIndexOfRefraction () const
 
int8_t shadeSides () const
 
bool shadeBothSides () const
 
bool shadeFrontSide () const
 
bool shadeBackSide () const
 
void setShadeSides (int8_t sides)
 
bool trace (const fdk::Vec3f &origin, const fdk::Vec3f &dir, ndk::RayContext::TypeMask type=ndk::RayContext::shadowRay(), float minDist=defaultMinDistance(), float maxDist=defaultMaxDistance()) const
 
bool trace (const SlrRayContext &Rtx) const
 
bool trace (const SlrRayContext &Rtx, ndk::RayHitPointf &hitPoint) const
 
bool getThinTransmissionFactor (const SlrRayContext &Rtx, fdk::Vec3f &transmissionFactor) const
 
float getPolygonEdgeDistanceSquared (const bool faceEdgesOnly) const
 
const fdk::Vec2i & pixelXY () const
 Current output screen coords.
 
const fdk::Vec2f & subpixelXY () const
 
int32_t sampleIndex () const
 Current pixel subsample/camera-ray index.
 
int32_t primaryRayIndex () const
 
float presenceThreshold () const
 
bool isDebugSample () const
 
bool isDebugPixel () const
 
bool isPixel (int32_t px, int32_t py) const
 
bool isPixelX (int32_t px) const
 
bool isPixelY (int32_t py) const
 
const fdk::Vec3f & viewVector () const
 Distance of this context's P from srcRtx().origin.
 
float distance () const
 Linear-projected distance (classic Z). Only valid if camera ray.
 
float Zlinear () const
 
const fdk::Vec3f & Ps () const
 Displaced shading point in common shading space where lighting is queried.
 
const fdk::Vec3f & Pg () const
 Geometric point (intersection) in common shading space.
 
const fdk::Vec3f & dPgdx () const
 P differential for dyDir ray direction. ('dx' is the ray cone x-axis, not screen-space 'x')
 
const fdk::Vec3f & dPgdy () const
 P differential for dyDir ray direction. ('dy' is the ray cone y-axis, not screen-space 'y')
 
const fdk::Vec3f & dPgdu () const
 P surface u-space partial derivative, not normalized.
 
const fdk::Vec3f & dPgdv () const
 P surface v-space partial derivative, not normalized.
 
const fdk::Vec3f & dPgdw () const
 P surface z-space partial derivative, not normalized. (for volumes)
 
fdk::Vec3f PWs () const
 Displaced shading point in world space where lighting is queried (common shading space offset by worldToShadingXform().)
 
fdk::Vec3f PWg () const
 Geometric point (intersection) in world space (common shading space offset by worldToShadingXform().)
 
const fdk::Vec3f & PgStart () const
 Geometric position at motion sample start.
 
const fdk::Vec3f & PgEnd () const
 Geometric position at motion sample end.
 
const fdk::Vec2f & PgMotionFwd () const
 Motion vector forward, only created on demand by calling generateMotionVectorAovs().
 
const fdk::Vec2f & PgMotionBwd () const
 Motion vector backwards, only created on demand by calling generateMotionVectorAovs().
 
const fdk::Vec3f & triUvw () const
 
const fdk::Vec3f & Ns () const
 Shading normal, normalized.
 
const fdk::Vec3f & Ng () const
 Geometric surface normal, normalized.
 
const fdk::Vec3f & Ts () const
 Shading tangent, normalized.
 
fdk::Vec3f NsFaceForward () const
 
fdk::Vec3f NgFaceForward () const
 
fdk::Vec3f faceForward (const fdk::Vec3f vector) const
 
const fdk::Vec2f & uv () const
 
const fdk::Vec2f & dUVdx () const
 Parametric-uv differential for dxDir ray direction.
 
const fdk::Vec2f & dUVdy () const
 Parametric-uv differential for dyDir ray direction.
 
float uvw () const
 Surface Z parametric coordinate of P (for volumes)
 
float dUVWdx () const
 Parametric-w differential for dxDir ray direction.
 
float dUVWdy () const
 Parametric-w differential for dyDir ray direction.
 
float presenceWeight () const
 
const fdk::Vec3f & Oi () const
 Rgb Opacity for colored transparency and thin-transmission.
 
float opacity () const
 Float version returns Oi.x (assumes all Oi elements are same value.)
 
const fdk::Vec2f & st () const
 Texture st(uv) coordinate (with w divided out)
 
const fdk::Vec2f & dStdx () const
 Texture coord st differential for dxDir ray direction.
 
const fdk::Vec2f & dStdy () const
 Texture coord st differential for dyDir ray direction.
 
const fdk::Vec2f & dStdu () const
 Texture coord st partial derivative in parametric-u direction, not normalized.
 
const fdk::Vec2f & dStdv () const
 Texture coord st partial derivative in parametric-u direction, not normalized.
 
const fdk::Vec4f & Cf () const
 Interpolated vertex color + alpha-transparency.
 
const fdk::Vec4f & rgba () const
 
const fdk::Vec3f & rgb () const
 
float alpha () const
 
float r () const
 
float g () const
 
float b () const
 
float a () const
 
fdk::Vec3f & albedoColor () const
 Surface albedo rgb reflectance.
 
fdk::Vec3f & diffuseLobe () const
 Surface diffuse scatter lobe contribution.
 
fdk::Vec3f & specularLobe () const
 Surface specular reflection lobe contribution.
 
fdk::Vec3f & transmissionLobe () const
 Surface transmission lobe contribution.
 
fdk::Vec3f & emissionLobe () const
 Surface emission lobe contribution.
 
fdk::Vec3f & shadowColor () const
 Surface accumulated shadow color.
 
fdk::Vec3f getAov (const SlrAovLayer &aov) const
 Retrieve value from Aov, if valid. If not valid returned value is 0,0,0.
 
void aovsCopy (DD::Image::Pixel &outputPixel) const
 
void aovsAReplaceB (const DD::Image::Pixel &A, DD::Image::Pixel &B) const
 
void aovsAUnderB (int32_t sampleIndex, const DD::Image::Pixel &A, DD::Image::Pixel &B, float Balpha) const
 
void aovsAOverB (int32_t sampleIndex, const DD::Image::Pixel &A, DD::Image::Pixel &B) const
 
void createMotionVectorAovs (DD::Image::Pixel &out, bool force=false) const
 
int32_t getIntShadingLayer (ndk::Channel chan, int32_t def_val) const
 
float getFloatShadingLayer (ndk::Channel chan, float def_val) const
 
double getDoubleShadingLayer (ndk::Channel chan, double def_val) const
 
const fdk::Vec2f & getVec2fShadingLayer (ndk::Channel startChan, const fdk::Vec2f &def_val) const
 
const fdk::Vec3f & getVec3fShadingLayer (ndk::Channel startChan, const fdk::Vec3f &def_val) const
 
const fdk::Vec4f & getVec4fShadingLayer (ndk::Channel startChan, const fdk::Vec4f &def_val) const
 
Dual2f getDual2fShadingLayer (const Dual2Chans &chans, float def_val) const
 
Dual2d getDual2dShadingLayer (const Dual2Chans &chans, double def_val) const
 
Dual2Vec2f getDual2Vec2fShadingLayer (const Dual2Chans &chans, const fdk::Vec2f &def_val) const
 
Dual2Vec3f getDual2Vec3fShadingLayer (const Dual2Chans &chans, const fdk::Vec3f &def_val) const
 
Dual2Vec4f getDual2Vec4fShadingLayer (const Dual2Chans &chans, const fdk::Vec4f &def_val) const
 
int32_t getIntPrimAttrib (ndk::Channel chan, int32_t def_val) const
 
float getFloatPrimAttrib (ndk::Channel chan, float def_val) const
 
double getDoublePrimAttrib (ndk::Channel chan, double def_val) const
 
const fdk::Vec2f & getVec2fPrimAttrib (ndk::Channel startChan, const fdk::Vec2f &def_val) const
 
const fdk::Vec3f & getVec3fPrimAttrib (ndk::Channel startChan, const fdk::Vec3f &def_val) const
 
const fdk::Vec4f & getVec4fPrimAttrib (ndk::Channel startChan, const fdk::Vec4f &def_val) const
 
Dual2f getDual2fPrimAttrib (const Dual2Chans &chans, float def_val) const
 
Dual2d getDual2dPrimAttrib (const Dual2Chans &chans, double def_val) const
 
Dual2Vec2f getDual2Vec2fPrimAttrib (const Dual2Chans &chans, const fdk::Vec2f &def_val) const
 
Dual2Vec3f getDual2Vec3fPrimAttrib (const Dual2Chans &chans, const fdk::Vec3f &def_val) const
 
Dual2Vec4f getDual2Vec4fPrimAttrib (const Dual2Chans &chans, const fdk::Vec4f &def_val) const
 
void sample (DD::Image::Sampler *sampler, const DD::Image::ChannelSet &get, DD::Image::Pixel &out) const
 
float sample (DD::Image::Sampler *sampler, DD::Image::Channel chan) const
 Same but for sampling a single channel.
 
void sample (DD::Image::Sampler *sampler, const Dual2Vec2f &st, const DD::Image::ChannelSet &get, DD::Image::Pixel &out) const
 Same as sample(Sampler*) but with overrides for st & derivatives currently in context.
 
float sample (DD::Image::Sampler *sampler, const Dual2Vec2f &st, DD::Image::Channel chan) const
 Same but for sampling a single channel.
 
void sample (DD::Image::Iop *texture, const DD::Image::ChannelSet &get, DD::Image::Pixel &out) const
 Slower versions using a raw Iop.
 
float sample (DD::Image::Iop *texture, DD::Image::Channel chan) const
 Same but for sampling a single channel.
 
void sample (DD::Image::Iop *texture, const Dual2Vec2f &st, const DD::Image::ChannelSet &get, DD::Image::Pixel &out) const
 Same as sample(Iop*) but with overrides for st & derivatives currently in context.
 
float sample (DD::Image::Iop *texture, const Dual2Vec2f &st, DD::Image::Channel chan) const
 Same but for sampling a single channel.
 
void getShadedSurfaceOutput (bool applyPresenceWeight=true)
 
DD::Image::PixelshadedOutput () const
 
DD::Image::PixeltextureColor () const
 
DD::Image::PixelbindingColor () const
 Per-thread context - for Connection sampling calls - defaults to RGBA.
 
DD::Image::PixelillumColor () const
 Per-ray - for LightShader evaluation - defaults to RGB.
 
DD::Image::PixelvolumeColor () const
 Per-ray - for VolumeShader color evaluation - defaults to RGB.
 
DD::Image::PixelindIllumColor () const
 Per-ray - or surface shader calls to retrieve indirect results - defaults to RGB.
 
void printParamData (std::ostream &) const
 

Public Attributes

uint16_t rayDepth
 Ray depth that created this context where 0 indicates a camera, or primary ray.
 
uint16_t diffuseDepth
 Ray depth along a diffuse/indirect scatter path.
 
uint16_t reflectionDepth
 Ray depth along a specular/glossy reflection path.
 
uint16_t refractionDepth
 Ray depth along a refraction/transmission path.
 
SlrSurfaceShader * surfaceShader
 Current surface shader being evaluated.
 
SlrVolumeShader * atmosphereShader
 Current atmospheric volume shader being evaluated, if any.
 

Protected Member Functions

 SlrShadingContext ()=default
 Member vars left intentionally uninitialized for performance reasons.
 

Protected Attributes

uint8_t _shadeSides
 Which sides to shade.
 
float _indexOfRefraction
 Index of refraction of the hit surface.
 
DD::Image::TextureFilter_textureFilter
 Global texture filter to use. May be null!
 

Friends

class ThreadContext
 
class StxBundle
 
class RenderEngine
 
class TraceableFaceTopology
 
std::ostream & operator<< (std::ostream &, const SlrShadingContext &)
 

Detailed Description

This class is intended to be passed up a SlrShader tree.

Member Function Documentation

◆ srcRtx()

const SlrRayContext & slr::SlrShadingContext::srcRtx ( ) const

Ray that created this shading context. If this is a 'virtual' surface (usually the camera origin stx) then this ray data will be the InvalidRay(), and isValid() will return false.

◆ isValid()

bool slr::SlrShadingContext::isValid ( ) const

Returns true is shading context is bound to valid ray data. If this returns false then any of the methods that access shading data (srcRtx) will crash!

◆ previousStx()

const SlrShadingContext * slr::SlrShadingContext::previousStx ( ) const

Previous SlrShadingContext, normally the last surface intersected/shaded and one level up in ray depth.

◆ createEditableShadingContextCopy()

SlrShadingContext * slr::SlrShadingContext::createEditableShadingContextCopy ( bool  copyShadingLayers = true) const

Create an editable shading context that's a copy of this one. Use the setAttrib() methods to change the values on the returned context. The setAttrib() methods will fail on a non-editable context. This is primarily used to modify the shading context when passing it to an input shader. A good example of this is modifying the UV attrib based on the current point location to perform high quality texture projections.

◆ sampleInfo()

const SampleInfo & slr::SlrShadingContext::sampleInfo ( ) const

Sample info of the context containing the sample time, motion step, motion step offset, etc.

Referenced by createMotionVectorAovs().

◆ getShaderThreadData()

SlrShaderThreadData & slr::SlrShadingContext::getShaderThreadData ( const SlrShader *  shader) const

Retrieve the optional thread-safe data blob an SlrShader can create in SlrShader::_initializeForShadingThread().

◆ hitIndex()

int32_t slr::SlrShadingContext::hitIndex ( ) const

Ray hit index in a bundle/stack of shading contexts. Typically the ray hit index order is the surface visibility order from front to back where hit index 0 is the closest hit.

◆ primFlags()

SlrPrimInfo::PrimFlag slr::SlrShadingContext::primFlags ( ) const

Surface quality flags from the renderable - same as calling primInfo().flags; See SlrPrimInfo for flag definitions.

◆ worldToShadingXform()

const fdk::Mat4d & slr::SlrShadingContext::worldToShadingXform ( ) const

World-space values are transformed into shading-space by this matrix, which is commonly just a translate.

Note - Shaders that have world-space values passed as inputs from scene shader nodes need to transform those values by this matrix to put them into shading-space. Lights and objects are transformed by the renderer during setup and have this xform applied.

◆ camP()

const Vec3d & slr::SlrShadingContext::camP ( ) const

Render camera origin (camera rays originate here). Same as camEye2World().getTranslation(), but cached for speed.

◆ useHeroCamForSpec()

bool slr::SlrShadingContext::useHeroCamForSpec ( ) const

If enabled viewVector() uses camHeroP() instead of camP() if rayDepth == 0. When rayDepth is > 0 (ie not a camera ray) then this ignored.

◆ ambientLightingBias()

const Vec3f & slr::SlrShadingContext::ambientLightingBias ( ) const

Adds light globally to the diffuse (albedo) surface response of surface shaders which respect this shading global.

◆ enabledLights()

const SlrPrimEnabledLightingList & slr::SlrShadingContext::enabledLights ( ) const

List of lights enabled for this renderable, always a subset of allLights(). Each SlrPrimEnabledLighting struct in this list is built for each renderable so that each renderable's illumination and shadow visibility can be unique.

◆ outsideIndexOfRefraction()

float slr::SlrShadingContext::outsideIndexOfRefraction ( ) const

Index of refraction (ior) of the 'outside' of the hit surface. This value is automatically determined when evaluating transmission rays, usually by taking the 'dielectric priority' of the surface into account to determine which surface is more important (which can ignored, really.)

◆ shadeSides()

int8_t slr::SlrShadingContext::shadeSides ( ) const
inline

Which side of the geometry should be shaded. This is not about intersection testing it's whether a surface shader should be run on the front side, back side or both.

◆ trace() [1/3]

bool slr::SlrShadingContext::trace ( const fdk::Vec3f &  origin,
const fdk::Vec3f &  dir,
ndk::RayContext::TypeMask  type = ndk::RayContext::shadowRay(),
float  minDist = defaultMinDistance(),
float  maxDist = defaultMaxDistance() 
) const

Returns true if anything is occluding the ray, including transparent objects. Does not call shaders or return information about the hit object.

◆ trace() [2/3]

bool slr::SlrShadingContext::trace ( const SlrRayContext Rtx) const

Returns true if anything is occluding the ray, including transparent objects. Does not call shaders or return information about the hit object.

◆ trace() [3/3]

bool slr::SlrShadingContext::trace ( const SlrRayContext Rtx,
ndk::RayHitPointf &  hitPoint 
) const

Returns true if anything is occluding the ray, filling in hitPoint with the nearest surface information, including hit distance and opacity. Calls presence and opacity shaders only.

◆ getThinTransmissionFactor()

bool slr::SlrShadingContext::getThinTransmissionFactor ( const SlrRayContext Rtx,
fdk::Vec3f &  transmissionFactor 
) const

Find the 'thin' transmission factor for all surfaces between Rtx.minT and Rtx.maxT, which is most commonly used for direct lighting shadow casting. Returns true on trivial 0% transmission (100% occlusion.) See SlrIntegratorContext::getThinTransmissionFactor() for more info.

◆ getPolygonEdgeDistanceSquared()

float slr::SlrShadingContext::getPolygonEdgeDistanceSquared ( const bool  faceEdgesOnly) const

Distance from Pg to the nearest not-occluded polygon edge for the current primitive (squared). If faceEdgesOnly is true then only the outside edged of the polygon face are tested against, otherwise the method checks all interior polygon edges (usually triangles).

Note - returns the closest distance squared. This is done to avoid an expensive sqrt() which the caller has the option of doing, but often it's cheaper to square the threshold value being compared to.

◆ subpixelXY()

const fdk::Vec2f & slr::SlrShadingContext::subpixelXY ( ) const

Current output subpixel coord inside pixelXY, where [0 0] is the center of the pixel and [-1 -1] is the lower-left corner.

◆ presenceThreshold()

float slr::SlrShadingContext::presenceThreshold ( ) const

Current presence threshold 0..1. If a hit surface's presence is below this value then it's considered to have no presence, not a hit, and the ray continues. This value will change randomly after each presence test.

◆ viewVector()

const fdk::Vec3f & slr::SlrShadingContext::viewVector ( ) const

Distance of this context's P from srcRtx().origin.

Returns a 'fake' stereo view vector built from the camHeroP, or the negated ray direction depending on context's stereo mode and rayDepth. When rayDepth > 0 (not a camera ray) then the inverted srcRtx().direction is returned.

For camera rays using the camHeroP camera ray makes specular calculations identical for all stereo cameras, visually 'flattening' the specular onto the surface.

◆ triUvw()

const fdk::Vec3f & slr::SlrShadingContext::triUvw ( ) const

Barycentric triangle uvw coordinates at srcRtx intersection. For a triangle with corners (p0 p1 p2) w=1 is along edge p0->p1, u=1 is along edge p1->p2, and v=1 is along edge p0->p2. If v or w are outside 0..1 then P is outside the bounds of the triangle and w in invalid. This happens when uvw is calculated for ray offsets dxDir & dyDir. They will always intersect the triangle plane but can often be outside the triangle's perimeter.

◆ NsFaceForward()

fdk::Vec3f slr::SlrShadingContext::NsFaceForward ( ) const

Ns() but facing toward 'view' vector (ray direction) so that backside surfaces can shade correctly.

◆ NgFaceForward()

fdk::Vec3f slr::SlrShadingContext::NgFaceForward ( ) const

Ng() but facing toward 'view' vector (ray direction) so that backside surfaces can shade correctly.

◆ faceForward()

fdk::Vec3f slr::SlrShadingContext::faceForward ( const fdk::Vec3f  vector) const

Return the vector facing toward the 'view' vector (ray direction) so that backside surfaces can shade correctly. Negates the vector if it's facing away otherwise vector is returned unchanged.

◆ uv()

const fdk::Vec2f & slr::SlrShadingContext::uv ( ) const

Surface 2D parametric coordinates of P Note - Parametric UVs are required for dPdu & dPdv and stable bump mapping, etc, and these are not neccessarily 'texture' UVs. For example texture coords can be projected onto a surface which can break the parametric-ness of the UVs along the surface. To avoid this we keep them logically separated to make sure shading operations like bump mapping are not adversely impacted. When not projecting texture coords the value of uv() and st() will likely be identical.

◆ presenceWeight()

float slr::SlrShadingContext::presenceWeight ( ) const

Note - presence contributes to pixel coverage weight, it does -not- influence opacity! 1.0 = solid, 0.0 = no object. Fractional values indicate multiple 0% or 100% samples have been combined together, usually due to filtering a texture.

Referenced by slr::SlrIntegratorContext::getPathIllumination().

◆ aovsCopy()

void slr::SlrShadingContext::aovsCopy ( DD::Image::Pixel outputPixel) const

Copy Aov values from this shading context's shading channels into the output Pixel, and call any custom Aov handlers for them to copy their values to the output Pixel.

References slr::SlrAovLayer::inHandler, slr::SlrAovLayer::inInterp, slr::SlrAovLayer::name, slr::SlrAovLayer::nInChans, slr::SlrAovLayer::outChan, and slr::SlrAovLayer::xformToSpace.

Referenced by getShadedSurfaceOutput().

◆ aovsAReplaceB()

void slr::SlrShadingContext::aovsAReplaceB ( const DD::Image::Pixel A,
DD::Image::Pixel B 
) const

Copy all Aov channels from pixel A to pixel B. If the Aov is set to mode MERGE_PREMULT_BLEND then the A channel is premulted by A.coverage() before copying to B. Note that opacity is not included in this premult!

Referenced by aovsAOverB(), and aovsAUnderB().

◆ aovsAUnderB()

void slr::SlrShadingContext::aovsAUnderB ( int32_t  sampleIndex,
const DD::Image::Pixel A,
DD::Image::Pixel B,
float  Balpha 
) const

Merge UNDER all Aov channels from pixel A under the mathcing pixel B channels. If the Aov is set to mode MERGE_PREMULT_BLEND then the A channel is premulted by A.coverage() while merging UNDER B. Note that opacity is not included in this premult!

References aovsAReplaceB(), and sampleIndex().

◆ aovsAOverB()

void slr::SlrShadingContext::aovsAOverB ( int32_t  sampleIndex,
const DD::Image::Pixel A,
DD::Image::Pixel B 
) const

Merge OVER all Aov channels from pixel A under the mathcing pixel B channels. If the Aov is set to mode MERGE_PREMULT_BLEND then the A channel is premulted by A.coverage() while merging OVER B. Note that opacity is not included in this premult!

References aovsAReplaceB(), and sampleIndex().

◆ createMotionVectorAovs()

void slr::SlrShadingContext::createMotionVectorAovs ( DD::Image::Pixel out,
bool  force = false 
) const

Create the motion vector values for the Aov layer Chan_MotionFwd. This should only be called on demand to reduce render cost by checking the IntegratorContext motionVectorsRequested() value.

References slr::SampleInfo::motionSampleStart, sampleInfo(), and slr::SampleInfo::shutterPercentage.

◆ sample()

void slr::SlrShadingContext::sample ( DD::Image::Sampler sampler,
const DD::Image::ChannelSet get,
DD::Image::Pixel out 
) const

Use st() and its xy derivatives dStdu() and dStdv() to sample the incoming image. The st coord 0,0 is mapped to the lower-left corner of the image's format, and 1,1 is mapped to the upper-right corner.

For texture sampling it's much faster to provide a DD::Image::Sampler rather than a raw Iop so Tile caching is properly leveraged, however the Sampler must not be shared between shading threads or its tile cache may crash.

References _textureFilter, dStdu(), dStdv(), DD::Image::Sampler::sampleTextureUV(), and st().

Referenced by sample().

◆ getShadedSurfaceOutput()

void slr::SlrShadingContext::getShadedSurfaceOutput ( bool  applyPresenceWeight = true)

Run the surface shader for this context, if valid, filling this context's shadedOutput() Pixel with the results.

This method first calls surfaceShader->surfaceShader() then overwrites the shaded output Pixel's Z (Chan_Z), Zf (Chan_DeepFront), Zb (Chan_DeepBack) and coverage (Chan_Coverage) channels with this context's values. This stops surface shaders from adversely affecting the Z location and coverage weight of the surface sample.

If applyPresenceWeight is true then the context's presenceWeight() value is used to attenuate (multiply down) only the -color- channels of the shaded output Pixel, leaving the data channels are unaffected (note that this uses the integrator's shaderChannelSet()). Shaded output coverage() is copied from presenceWeight().

Note that Z() will always be ray distance and not Zlinear, while Zf() and Zb() will contain Zlinear. coverage() is copied from presenceWeight() as at this point in the shading pipeline the sample's 'pixel coverage' is simply whether it has presence or not. See presenceWeight() for more info.

References aovsCopy(), DD::Image::Pixel::get(), shadedOutput(), and surfaceShader.

◆ shadedOutput()

DD::Image::Pixel & slr::SlrShadingContext::shadedOutput ( ) const

Final output, or shaded data for this surface sample, typically produced by a surface shader called by getShadedSurfaceOutput(). This Pixel contains all the output channel data including data AOVs.

This Pixel is fully read/write and an integrator or filter is free to change its contents as needed, even affected the Z and coverage values. However changing these channels may adversely affect the renderer's output layering logic.

These output channels can be layered together with other surface samples to produce a final 'flat' output pixel, or can be kept separate as deep sample data.

Note - this data is only valid while this shading context exists so it must be copied to the final Iop or DeepOp output, typically in an engine method according to that engine's rules. For example, channels written into which the Iop/DeepOp engine is unaware of may be lost.

Referenced by slr::SlrIntegratorContext::getPathIllumination(), and getShadedSurfaceOutput().

◆ textureColor()

DD::Image::Pixel & slr::SlrShadingContext::textureColor ( ) const

Per-thread context - for sampling texture map Iops - defaults to RGBA Note - has InterestRatchet set so should sample faster.

Referenced by sample().



©2026 The Foundry Visionmongers, Ltd. All Rights Reserved.
www.foundry.com