MaterialX 1.38.2
OslRenderer.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_OSLRENDERER_H
7#define MATERIALX_OSLRENDERER_H
8
11
13
16
17namespace MaterialX
18{
19
20// Shared pointer to an OslRenderer
21using OslRendererPtr = std::shared_ptr<class OslRenderer>;
22
33class MX_RENDEROSL_API OslRenderer : public ShaderRenderer
34{
35 public:
37 static OslRendererPtr create(unsigned int width = 512, unsigned int height = 512, Image::BaseType baseType = Image::BaseType::UINT8);
38
40 virtual ~OslRenderer();
41
44
47
51 void initialize() override;
52
56
68 void createProgram(ShaderPtr shader) override;
69
72 void createProgram(const StageMap& stages) override;
73
76 void validateInputs() override;
77
79 void setSize(unsigned int width, unsigned int height) override;
80
88 void render() override;
89
93
95 ImagePtr captureImage(ImagePtr image = nullptr) override;
96
100
104 void setOslCompilerExecutable(const FilePath& executableFilePath)
105 {
106 _oslCompilerExecutable = executableFilePath;
107 }
108
112 void setOslIncludePath(const FilePath& dirPath)
113 {
114 _oslIncludePath = dirPath;
115 }
116
119 void setOslOutputFilePath(const FilePath& dirPath)
120 {
121 _oslOutputFilePath = dirPath;
122 }
123
126 void setShaderParameterOverrides(const StringVec& parameterOverrides)
127 {
128 _oslShaderParameterOverrides = parameterOverrides;
129 }
130
133 void setEnvShaderParameterOverrides(const StringVec& parameterOverrides)
134 {
135 _envOslShaderParameterOverrides = parameterOverrides;
136 }
137
144 void setOslShaderOutput(const string& outputName, const string& outputType)
145 {
146 _oslShaderOutputName = outputName;
147 _oslShaderOutputType = outputType;
148 }
149
153 void setOslTestShadeExecutable(const FilePath& executableFilePath)
154 {
155 _oslTestShadeExecutable = executableFilePath;
156 }
157
161 void setOslTestRenderExecutable(const FilePath& executableFilePath)
162 {
163 _oslTestRenderExecutable = executableFilePath;
164 }
165
171 void setOslTestRenderSceneTemplateFile(const FilePath& templateFilePath)
172 {
173 _oslTestRenderSceneTemplateFile = templateFilePath;
174 }
175
179 void setOslShaderName(const string& shaderName)
180 {
181 _oslShaderName = shaderName;
182 }
183
187 void setOslUtilityOSOPath(const FilePath& dirPath)
188 {
189 _oslUtilityOSOPath = dirPath;
190 }
191
195 void useTestRender(bool useTestRender)
196 {
197 _useTestRender = useTestRender;
198 }
199
203 void compileOSL(const FilePath& oslFilePath);
204
206
207 protected:
213 void shadeOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
214
220 void renderOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
221
223 OslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType);
224
225 private:
227 FilePath _oslCompilerExecutable;
229 FilePath _oslIncludePath;
231 FilePath _oslOutputFilePath;
233 FilePath _oslOutputFileName;
234
236 FilePath _oslTestShadeExecutable;
238 FilePath _oslTestRenderExecutable;
240 FilePath _oslTestRenderSceneTemplateFile;
242 string _oslShaderName;
244 StringVec _oslShaderParameterOverrides;
246 StringVec _envOslShaderParameterOverrides;
248 string _oslShaderOutputName;
250 string _oslShaderOutputType;
252 FilePath _oslUtilityOSOPath;
254 bool _useTestRender;
255};
256
257} // namespace MaterialX
258
259#endif
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:24
Image handler interfaces.
vector< string > StringVec
A vector of strings.
Definition: Library.h:56
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Macros for declaring imported and exported symbols.
Base class for shader rendering.
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:28
Helper class for rendering generated OSL code to produce images.
Definition: OslRenderer.h:34
void setOslTestRenderSceneTemplateFile(const FilePath &templateFilePath)
Set the XML scene file to use for testrender.
Definition: OslRenderer.h:171
void setOslUtilityOSOPath(const FilePath &dirPath)
Set the search path for dependent shaders (.oso files) which are used when rendering with testrender.
Definition: OslRenderer.h:187
void setOslCompilerExecutable(const FilePath &executableFilePath)
Set the path to the OSL executable.
Definition: OslRenderer.h:104
void setOslTestRenderExecutable(const FilePath &executableFilePath)
Set the path to the OSL rendering tester.
Definition: OslRenderer.h:161
void setOslShaderOutput(const string &outputName, const string &outputType)
Set the OSL shader output.
Definition: OslRenderer.h:144
static string OSL_CLOSURE_COLOR_STRING
Color closure OSL string.
Definition: OslRenderer.h:43
void setShaderParameterOverrides(const StringVec &parameterOverrides)
Set shader parameter strings to be added to the scene XML file.
Definition: OslRenderer.h:126
void setOslIncludePath(const FilePath &dirPath)
Set the search locations for OSL include files.
Definition: OslRenderer.h:112
void setOslShaderName(const string &shaderName)
Set the name of the shader to be used for the input XML scene file.
Definition: OslRenderer.h:179
void setEnvShaderParameterOverrides(const StringVec &parameterOverrides)
Set shader parameter strings to be added to the scene XML file.
Definition: OslRenderer.h:133
void useTestRender(bool useTestRender)
Used to toggle to either use testrender or testshade during render validation By default testshade is...
Definition: OslRenderer.h:195
void setOslOutputFilePath(const FilePath &dirPath)
Set the location where compiled OSL files will reside.
Definition: OslRenderer.h:119
void setOslTestShadeExecutable(const FilePath &executableFilePath)
Set the path to the OSL shading tester.
Definition: OslRenderer.h:153
Base class for renderers that generate shader code to produce images.
Definition: ShaderRenderer.h:29
StringMap StageMap
A map with name and source code for each shader stage.
Definition: ShaderRenderer.h:32