Nuke binary plugins 15.1.5
 
Loading...
Searching...
No Matches
slr::SlrShadingContext Class Reference

#include <SlrShadingContext.h>

Public Member Functions

bool operator< (const SlrShadingContext &i) const
 
bool operator<= (const SlrShadingContext &i) const
 
bool operator> (const SlrShadingContext &i) const
 
bool operator>= (const SlrShadingContext &i) const
 
bool operator== (const SlrShadingContext &i) const
 
bool operator!= (const SlrShadingContext &i) const
 
bool operator< (float v) const
 
bool operator<= (float v) const
 
bool operator> (float v) const
 
bool operator>= (float v) const
 
bool operator== (float v) const
 
bool operator!= (float v) const
 
bool isSlr1LegacyMode () 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.
 
bool setIntShadingLayer (ndk::Channel chan, int32_t value)
 
bool setFloatShadingLayer (ndk::Channel chan, float value)
 
bool setVec2fShadingLayer (ndk::Channel startChan, const fdk::Vec2f &value)
 
bool setVec3fShadingLayer (ndk::Channel startChan, const fdk::Vec3f &value)
 
bool setVec4fShadingLayer (ndk::Channel startChan, const fdk::Vec4f &value)
 
bool setDual2fShadingLayer (const Dual2Chans &chans, const Dual2f &value)
 
bool setDual2dShadingLayer (const Dual2Chans &chans, const Dual2d &value)
 
bool setDual2Vec2fShadingLayer (const Dual2Chans &chans, const Dual2Vec2f &value)
 
bool setDual2Vec3fShadingLayer (const Dual2Chans &chans, const Dual2Vec3f &value)
 
bool setDual2Vec4fShadingLayer (const Dual2Chans &chans, const Dual2Vec4f &value)
 
fdk::TimeValue time () const
 Absolute time of the context.
 
DD::Image::ThreadId threadId () const
 Thread id from current SlrThreadContext.
 
const SlrIntegratorContextItx () const
 Integrator context that created this shading context.
 
ndk::SamplingRngSet & samplingRng () const
 Sampling random number generator owned by this thread.
 
int32_t rayId () const
 Ray id of srcRtx.
 
uint64_t primId () const
 Unique ID of the current intersection renderable/subpart/subtri.
 
int32_t renderableIndex () const
 PrimInfo index of current intersected object in SlrRenderContext.
 
bool isWritable () const
 This context's shading data can be written to.
 
bool blendBackToFront () const
 Blending Z order is back-to-front (true) or front-to-back (false)
 
bool enableColorChannels () const
 Shaders should output color layers + alphas.
 
bool enableDataChannels () const
 Shaders should output any data channels (Z, etc)
 
bool textureSamplingEnabled () const
 
void setTextureSampling (bool enabled)
 
void enableTextureSampling ()
 
void disableTextureSampling ()
 
DD::Image::TextureFiltertextureFilter () const
 Texture filter to use. If null the texture will be impulse sampled.
 
bool lightingEnabled () const
 If true, even if no lights the surface shaders should do illum calcs.
 
bool directLightingEnabled () const
 If true do direct-illumination calculations.
 
bool indirectLightingEnabled () const
 If true handle indirect-illumation calculations.
 
bool shadowingEnabled () const
 If true do shadow occlusion for direct-illumination.
 
bool useHeroCamForSpec () const
 If enabled getViewVector() uses camHeroP() instead of camP().
 
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.
 
const SlrLightInfoList & lights () const
 List of active lights. If lightingEnabled is false an empty list is returned.
 
fdk::Vec3f getViewVector () const
 
bool shadeBothSides () const
 Shade both sides of surface (front and back) ignoring surface normal to camera.
 
bool shadeFrontOnly () const
 Shade only front side of surface.
 
bool shadeBackOnly () const
 Shade only front side of surface.
 
void setSidesMode (ndk::RayContext::SidesMode mode)
 Override sides mode. By default sides mode is copied from surface shader.
 
const fdk::Vec3f & ambientLightingBias () const
 
bool intersect (const ndk::RayContext &Rtx=ndk::RayContext()) const
 
bool getNearestIntersection (const ndk::RayContext &Rtx, SlrShadingContext &hitStx) const
 
ndk::RayContextBundle & startNewRtxBundle () const
 
ndk::RayContextBundle & currentRtxBundle () const
 
float getPolygonEdgeDistance (float minDist) const
 
const fdk::Vec2i & pixelXY () const
 Current output screen coords.
 
const fdk::Vec2f & subpixelXY () const
 Current output subpixel coord inside pixelXY.
 
int32_t sampleIndex () const
 Current subsample/camera-ray index.
 
int32_t primaryRayIndex () 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 & Ps () const
 Displaced shading point in common shading space where lighting is queried.
 
const fdk::Vec3f & P () const
 Geometric point (intersection) in common shading space.
 
const fdk::Vec3f & dPdx () const
 P differential for dyDir ray direction. ('dx' is the ray cone x-axis, not screen-space 'x')
 
const fdk::Vec3f & dPdy () const
 P differential for dyDir ray direction. ('dy' is the ray cone y-axis, not screen-space 'y')
 
const fdk::Vec3f & dPdu () const
 P surface u-space partial derivative, not normalized.
 
const fdk::Vec3f & dPdv () const
 P surface v-space partial derivative, not normalized.
 
const fdk::Vec3f & dPdw () const
 P surface z-space partial derivative, not normalized. (for volumes)
 
const fdk::Vec3f & triUvw () const
 
const fdk::Vec3f & N () const
 Shading normal, normalized.
 
const fdk::Vec3f & Ng () const
 Geometric surface normal, normalized.
 
const fdk::Vec3f & T () const
 Shading tangent, normalized.
 
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.
 
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 + opacity.
 
const fdk::Vec4f & rgba () const
 
const fdk::Vec3f & rgb () const
 
float r () const
 
float g () const
 
float b () const
 
float a () const
 
float opacity () 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 startChan, 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
 
int32_t getIntShadingLayer (ndk::Channel chan, int32_t def_val) const
 
float getFloatShadingLayer (ndk::Channel chan, float def_val) const
 
double getDoubleShadingLayer (ndk::Channel startChan, 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
 
void sample (DD::Image::Sampler *sampler, DD::Image::Pixel &out) const
 
void sample (DD::Image::Sampler *sampler, const Dual2Vec2f &v, DD::Image::Pixel &out) const
 Same as sample(Sampler*) but with overrides for st & derivatives currently in context.
 
void sample (DD::Image::Iop *texture, DD::Image::Pixel &out) const
 Slower version using a raw Iop.
 
void sample (DD::Image::Iop *texture, const Dual2Vec2f &v, DD::Image::Pixel &out) const
 Same as sample(Iop*) but with overrides for st & derivatives currently in context.
 
DD::Image::PixeltextureColor () const
 For sampling texture map Iops - defaults to RGBA.
 
DD::Image::PixelbindingColor () const
 For Connection sampling calls - defaults to RGBA.
 
DD::Image::PixelillumColor () const
 For LightShader evaluation - defaults to RGB.
 
DD::Image::PixelshadowColor () const
 For LightShader shadow transmission evaluation - defaults to RGB (no depth!)
 
DD::Image::PixelvolumeColor () const
 For VolumeShader color evaluation - defaults to RGB.
 
SlrThreadContext * sttx () const
 Access to the owner thread context. For internal use only.
 
void printParamData (std::ostream &) const
 
SlrRenderObject * rPrim () const
 

Public Attributes

ndk::RayContext srcRtx
 Ray that created this context.
 
int32_t rayDepth
 Current ray depth where 0 indicates a camera, or primary ray.
 
float distance
 Distance of this context's P from srcRtx origin.
 
SlrSurfaceShader * surfaceShader
 Current surface shader being evaluated.
 
SlrGeometryShader * displacementShader
 Current displacement shader being evaluated, if any.
 
SlrVolumeShader * atmosphereShader
 Current atmospheric volume shader being evaluated, if any.
 
float _vP [28]
 Current values for shader - in homogeneous-space! (deprecated)
 
float _vdX [28]
 Change if X of render pixel is increased by 1 (deprecated)
 
float _vdY [28]
 Change if Y of render pixel is increased by 1 (deprecated)
 

Protected Attributes

SlrThreadContext * _sttx
 Owner of the shading data.
 
const SlrShadingContext_previousStx
 Previous SlrShadingContext, normally the last surface intersected/shaded.
 
class ShadingDataCache * _dataCache
 Shading data storage.
 
int32_t _dataCacheIndex
 Index of shading data in cache.
 
ndk::RayContext::SidesMode _sidesMode
 Which sides to intersect against and shade (use methods to query)
 
bool _doTextureSampling
 Whether shaders should sample their textures.
 
DD::Image::TextureFilter_textureFilter
 Global texture filter to use. May be null!
 
SlrRenderObject * _oIf
 Object intersection info.
 

Friends

class SlrThreadContext
 
class SlrIntegratorContext
 
class ShadingDataCache
 
class RenderEngine
 
class RenderSpan
 
class IntersectedSurfaces
 
std::ostream & operator<< (std::ostream &, const SlrShadingContext &)
 

Detailed Description

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

Member Function Documentation

◆ isSlr1LegacyMode()

bool slr::SlrShadingContext::isSlr1LegacyMode ( ) const

Is shading context is operating in 'legacy' mode? ie using the old ScanlineRender1 architecture? In legacy mode certain features such as dynamic primvar retrieval are not supported, so a shader can test this before deciding to sample primar channels it expects to be filled in. This method will be deprecated at some point after the legacy system is removed. After the legacy system is gone it will return 'false' until the method's eventual removal.

References _sttx.

◆ previousStx()

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

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.

References _sttx.

◆ textureSamplingEnabled()

bool slr::SlrShadingContext::textureSamplingEnabled ( ) const
inline

Should textures sample? This may be disabled for camera rays when shading a pre-rendered scene with pixel containing the surface albedo.

◆ camP()

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

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

References _sttx.

Referenced by getViewVector().

◆ getViewVector()

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

Returns a 'fake' stereo view vector built from the camHeroP, or the negated ray direction depending on context's stereo mode. Using the camHeroP camera-ray makes specular calculations identical for all stereo cameras, visually 'flattening' the specular onto the surface.

References camHeroP(), camP(), P(), rayDepth, and useHeroCamForSpec().

◆ ambientLightingBias()

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

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

References _sttx.

◆ intersect()

bool slr::SlrShadingContext::intersect ( const ndk::RayContext &  Rtx = ndk::RayContext()) const

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

References _sttx.

◆ getNearestIntersection()

bool slr::SlrShadingContext::getNearestIntersection ( const ndk::RayContext &  Rtx,
SlrShadingContext hitStx 
) const

Intersect the scene with the RayContext Rtx, returning true if there was a hit within Rtx's distance range, and filling in hitStx with the information about the hit surface.

References _sttx, and rayDepth.

◆ startNewRtxBundle()

RayContextBundle & slr::SlrShadingContext::startNewRtxBundle ( ) const

Start a new RayContext bundle making it the current bundle and returning a reference to it. Note that only one bundle may be active at a time since each bundle must be a contiguous section of RayContexts in the cache.

References _sttx.

◆ currentRtxBundle()

RayContextBundle & slr::SlrShadingContext::currentRtxBundle ( ) const

Access the current RayContextBundle for this thread which can then be added to. Note that only one bundle may be current at a time.

References _sttx.

◆ getPolygonEdgeDistance()

float slr::SlrShadingContext::getPolygonEdgeDistance ( float  minDist) const

Distance from P to the nearest not-occluded polygon edge in screen-space for the current primitive. All triangles generated from the tessellation of the original SlrPrimInfo are tested, so the method checks all polygon edges. Returns when the first edge distance is under minDist.

References _dataCache, _dataCacheIndex, _sttx, _vP, and P().

◆ 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.

References _dataCache, and _dataCacheIndex.

◆ 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.

References _dataCache, and _dataCacheIndex.

◆ sample()

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

Use st() and the derivatives of st() 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.

References dStdu(), dStdv(), sample(), and st().

Referenced by sample().



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