HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OslRenderer Class Reference

#include <OslRenderer.h>

+ Inheritance diagram for OslRenderer:

Public Member Functions

virtual ~OslRenderer ()
 Destructor. More...
 
Setup
void initialize (RenderContextHandle renderContextHandle=nullptr) override
 
Rendering
void createProgram (ShaderPtr shader) override
 
void createProgram (const StageMap &stages) override
 
void validateInputs () override
 
void setSize (unsigned int width, unsigned int height) override
 Set the size for rendered image. More...
 
void render () override
 
Utilities
ImagePtr captureImage (ImagePtr image=nullptr) override
 Capture the current rendered output as an image. More...
 
Compilation settings
void setOslCompilerExecutable (const FilePath &executableFilePath)
 
void setOslIncludePath (const FileSearchPath &dirPath)
 
void setOslOutputFilePath (const FilePath &dirPath)
 
void setShaderParameterOverrides (const StringVec &parameterOverrides)
 
void setEnvShaderParameterOverrides (const StringVec &parameterOverrides)
 
void setOslShaderOutput (const string &outputName, const string &outputType)
 
void setOslTestShadeExecutable (const FilePath &executableFilePath)
 
void setOslTestRenderExecutable (const FilePath &executableFilePath)
 
void setOslTestRenderSceneTemplateFile (const FilePath &templateFilePath)
 
void setOslShaderName (const string &shaderName)
 
void setOslUtilityOSOPath (const FilePath &dirPath)
 
void useTestRender (bool useTestRender)
 
void setRaysPerPixelLit (int rays)
 Set the number of rays per pixel to be used for lit surfaces. More...
 
void setRaysPerPixelUnlit (int rays)
 Set the number of rays per pixel to be used for unlit surfaces. More...
 
void compileOSL (const FilePath &oslFilePath)
 
- Public Member Functions inherited from ShaderRenderer
virtual ~ShaderRenderer ()
 
void setCamera (CameraPtr camera)
 Set the camera. More...
 
CameraPtr getCamera () const
 Return the camera. More...
 
void setImageHandler (ImageHandlerPtr imageHandler)
 Set the image handler used by this renderer for image I/O. More...
 
ImageHandlerPtr getImageHandler () const
 Return the image handler. More...
 
void setLightHandler (LightHandlerPtr lightHandler)
 Set the light handler used by this renderer for light bindings. More...
 
LightHandlerPtr getLightHandler () const
 Return the light handler. More...
 
void setGeometryHandler (GeometryHandlerPtr geometryHandler)
 Set the geometry handler. More...
 
GeometryHandlerPtr getGeometryHandler () const
 Return the geometry handler. More...
 
virtual void updateUniform (const string &name, ConstValuePtr value)
 Update the program with value of the uniform. More...
 

Static Public Member Functions

static OslRendererPtr create (unsigned int width=512, unsigned int height=512, Image::BaseType baseType=Image::BaseType::UINT8)
 Create an OSL renderer instance. More...
 

Static Public Attributes

static string OSL_CLOSURE_COLOR_STRING
 Color closure OSL string. More...
 

Protected Member Functions

void shadeOSL (const FilePath &dirPath, const string &shaderName, const string &outputName)
 
void renderOSL (const FilePath &dirPath, const string &shaderName, const string &outputName)
 
 OslRenderer (unsigned int width, unsigned int height, Image::BaseType baseType)
 Constructor. More...
 
- Protected Member Functions inherited from ShaderRenderer
 ShaderRenderer (unsigned int width, unsigned int height, Image::BaseType baseType, MatrixConvention matrixConvention=MatrixConvention::OpenGL)
 

Additional Inherited Members

- Public Types inherited from ShaderRenderer
enum  MatrixConvention { MatrixConvention::OpenGL = 0, MatrixConvention::Metal = 1 }
 Viewing API matrix conventions designation (default to OpenGL). More...
 
using StageMap = StringMap
 A map with name and source code for each shader stage. More...
 
- Protected Attributes inherited from ShaderRenderer
unsigned int _width
 
unsigned int _height
 
Image::BaseType _baseType
 
MatrixConvention _matrixConvention
 
CameraPtr _camera
 
ImageHandlerPtr _imageHandler
 
GeometryHandlerPtr _geometryHandler
 
LightHandlerPtr _lightHandler
 

Detailed Description

Helper class for rendering generated OSL code to produce images.

The main services provided are:

  • Source code validation: Use of "oslc" to compile and test output results
  • Introspection check: None at this time.
  • Binding: None at this time.
  • Render validation: Use of "testrender" to output rendered images. Assumes source compliation was success as it depends on the existence of corresponding .oso files.

Definition at line 32 of file OslRenderer.h.

Constructor & Destructor Documentation

virtual OslRenderer::~OslRenderer ( )
virtual

Destructor.

OslRenderer::OslRenderer ( unsigned int  width,
unsigned int  height,
Image::BaseType  baseType 
)
protected

Constructor.

Member Function Documentation

ImagePtr OslRenderer::captureImage ( ImagePtr  image = nullptr)
overridevirtual

Capture the current rendered output as an image.

Reimplemented from ShaderRenderer.

void OslRenderer::compileOSL ( const FilePath oslFilePath)

Compile OSL code stored in a file. Will throw an exception if an error occurs.

Parameters
oslFilePathOSL file path.
static OslRendererPtr OslRenderer::create ( unsigned int  width = 512,
unsigned int  height = 512,
Image::BaseType  baseType = Image::BaseType::UINT8 
)
static

Create an OSL renderer instance.

void OslRenderer::createProgram ( ShaderPtr  shader)
overridevirtual

Create OSL program based on an input shader

A valid executable and include path must be specified before calling this method. setOslCompilerExecutable(), and setOslIncludePath().

Additionally setOslOutputFilePath() should be set to allow for output of .osl and .oso files to the appropriate path location to be used as input for render validation.

If render validation is not required, then the same temporary name will be used for all shaders validated using this method.

Parameters
shaderInput shader

Reimplemented from ShaderRenderer.

void OslRenderer::createProgram ( const StageMap stages)
overridevirtual

Create OSL program based on shader stage source code.

Parameters
stagesMap of name and source code for the shader stages.

Reimplemented from ShaderRenderer.

void OslRenderer::initialize ( RenderContextHandle  renderContextHandle = nullptr)
overridevirtual

Internal initialization required for program validation and rendering. An exception is thrown on failure. The exception will contain a list of initialization errors.

Reimplemented from ShaderRenderer.

void OslRenderer::render ( )
overridevirtual

Render OSL program to disk. This is done by using either "testshade" or "testrender". Currently only "testshade" is supported.

Usage of both executables requires compiled source (.oso) files as input. A shader output must be set before running this test via the setOslOutputName() method to ensure that the appropriate .oso files can be located.

Reimplemented from ShaderRenderer.

void OslRenderer::renderOSL ( const FilePath dirPath,
const string shaderName,
const string outputName 
)
protected

Render using OSO input file. Will throw an exception if an error occurs.

Parameters
dirPathPath to location containing input .oso file.
shaderNameName of OSL shader. A corresponding .oso file is assumed to exist in the output path folder.
outputNameName of OSL shader output to use.
void OslRenderer::setEnvShaderParameterOverrides ( const StringVec parameterOverrides)
inline

Set shader parameter strings to be added to the scene XML file. These strings will set parameter overrides for the shader.

Definition at line 132 of file OslRenderer.h.

void OslRenderer::setOslCompilerExecutable ( const FilePath executableFilePath)
inline

Set the path to the OSL executable. Note that it is assumed that this references the location of the oslc executable.

Parameters
executableFilePathPath to OSL compiler executable

Definition at line 103 of file OslRenderer.h.

void OslRenderer::setOslIncludePath ( const FileSearchPath dirPath)
inline

Set the search locations for OSL include files.

Parameters
dirPathInclude path(s) for the OSL compiler. This should include the path to stdosl.h.

Definition at line 111 of file OslRenderer.h.

void OslRenderer::setOslOutputFilePath ( const FilePath dirPath)
inline

Set the location where compiled OSL files will reside.

Parameters
dirPathPath to output location

Definition at line 118 of file OslRenderer.h.

void OslRenderer::setOslShaderName ( const string shaderName)
inline

Set the name of the shader to be used for the input XML scene file. The value is used to replace the shader% token in the file.

Parameters
shaderNameName of shader

Definition at line 178 of file OslRenderer.h.

void OslRenderer::setOslShaderOutput ( const string outputName,
const string outputType 
)
inline

Set the OSL shader output. This is used during render validation if "testshade" or "testrender" is executed. For testrender this value is used to replace the shader_output% token in the input scene file.

Parameters
outputNameName of shader output
outputTypeThe MaterialX type of the output

Definition at line 143 of file OslRenderer.h.

void OslRenderer::setOslTestRenderExecutable ( const FilePath executableFilePath)
inline

Set the path to the OSL rendering tester. Note that it is assumed that this references the location of the "testrender" executable.

Parameters
executableFilePathPath to OSL "testrender" executable

Definition at line 160 of file OslRenderer.h.

void OslRenderer::setOslTestRenderSceneTemplateFile ( const FilePath templateFilePath)
inline

Set the XML scene file to use for testrender. This is a template file with the following tokens for replacement:

  • shader% : which will be replaced with the name of the shader to use
  • shader_output% : which will be replace with the name of the shader output to use
    Parameters
    templateFilePathScene file name

Definition at line 170 of file OslRenderer.h.

void OslRenderer::setOslTestShadeExecutable ( const FilePath executableFilePath)
inline

Set the path to the OSL shading tester. Note that it is assumed that this references the location of the "testshade" executable.

Parameters
executableFilePathPath to OSL "testshade" executable

Definition at line 152 of file OslRenderer.h.

void OslRenderer::setOslUtilityOSOPath ( const FilePath dirPath)
inline

Set the search path for dependent shaders (.oso files) which are used when rendering with testrender.

Parameters
dirPathPath to location containing .oso files.

Definition at line 186 of file OslRenderer.h.

void OslRenderer::setRaysPerPixelLit ( int  rays)
inline

Set the number of rays per pixel to be used for lit surfaces.

Definition at line 200 of file OslRenderer.h.

void OslRenderer::setRaysPerPixelUnlit ( int  rays)
inline

Set the number of rays per pixel to be used for unlit surfaces.

Definition at line 206 of file OslRenderer.h.

void OslRenderer::setShaderParameterOverrides ( const StringVec parameterOverrides)
inline

Set shader parameter strings to be added to the scene XML file. These strings will set parameter overrides for the shader.

Definition at line 125 of file OslRenderer.h.

void OslRenderer::setSize ( unsigned int  width,
unsigned int  height 
)
overridevirtual

Set the size for rendered image.

Reimplemented from ShaderRenderer.

void OslRenderer::shadeOSL ( const FilePath dirPath,
const string shaderName,
const string outputName 
)
protected

Shade using OSO input file. Will throw an exception if an error occurs.

Parameters
dirPathPath to location containing input .oso file.
shaderNameName of OSL shader. A corresponding .oso file is assumed to exist in the output path folder.
outputNameName of OSL shader output to use.
void OslRenderer::useTestRender ( bool  useTestRender)
inline

Used to toggle to either use testrender or testshade during render validation By default testshade is used.

Parameters
useTestRenderIndicate whether to use testrender.

Definition at line 194 of file OslRenderer.h.

void OslRenderer::validateInputs ( )
overridevirtual

Validate inputs for the compiled OSL program. Note: Currently no validation has been implemented.

Reimplemented from ShaderRenderer.

Member Data Documentation

string OslRenderer::OSL_CLOSURE_COLOR_STRING
static

Color closure OSL string.

Definition at line 42 of file OslRenderer.h.


The documentation for this class was generated from the following file: