MaterialX 1.39.5
Loading...
Searching...
No Matches
OslRenderer.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_OSLRENDERER_H
7#define MATERIALX_OSLRENDERER_H
8
11
13
16
17MATERIALX_NAMESPACE_BEGIN
18
19// Shared pointer to an OslRenderer
20using OslRendererPtr = std::shared_ptr<class OslRenderer>;
21
32class MX_RENDEROSL_API OslRenderer : public ShaderRenderer
33{
34 public:
36 static OslRendererPtr create(unsigned int width = 512, unsigned int height = 512, Image::BaseType baseType = Image::BaseType::UINT8);
37
39 virtual ~OslRenderer();
40
43
46
50 void initialize(RenderContextHandle renderContextHandle = nullptr) override;
51
55
67 void createProgram(ShaderPtr shader) override;
68
71 void createProgram(const StageMap& stages) override;
72
75 void validateInputs() override;
76
78 void setSize(unsigned int width, unsigned int height) override;
79
87 void render() override;
88
92
94 ImagePtr captureImage(ImagePtr image = nullptr) override;
95
99
103 void setOslCompilerExecutable(const FilePath& executableFilePath)
104 {
105 _oslCompilerExecutable = executableFilePath;
106 }
107
112 {
113 _oslIncludePath = dirPath;
114 }
115
118 void setOslOutputFilePath(const FilePath& dirPath)
119 {
120 _oslOutputFilePath = dirPath;
121 }
122
125 void setShaderParameterOverrides(const StringVec& parameterOverrides)
126 {
127 _oslShaderParameterOverrides = parameterOverrides;
128 }
129
132 void setEnvShaderParameterOverrides(const StringVec& parameterOverrides)
133 {
134 _envOslShaderParameterOverrides = parameterOverrides;
135 }
136
143 void setOslShaderOutput(const string& outputName, const string& outputType)
144 {
145 _oslShaderOutputName = outputName;
146 _oslShaderOutputType = outputType;
147 }
148
152 void setOslTestShadeExecutable(const FilePath& executableFilePath)
153 {
154 _oslTestShadeExecutable = executableFilePath;
155 }
156
160 void setOslTestRenderExecutable(const FilePath& executableFilePath)
161 {
162 _oslTestRenderExecutable = executableFilePath;
163 }
164
170 void setOslTestRenderSceneTemplateFile(const FilePath& templateFilePath)
171 {
172 _oslTestRenderSceneTemplateFile = templateFilePath;
173 }
174
178 void setOslShaderName(const string& shaderName)
179 {
180 _oslShaderName = shaderName;
181 }
182
186 void setOslUtilityOSOPath(const FilePath& dirPath)
187 {
188 _oslUtilityOSOPath = dirPath;
189 }
190 void setDataLibraryOSOPath(const FilePath& dirPath)
191 {
192 _dataLibraryOSOPath = dirPath;
193 }
194
199 {
200 _useTestRender = useTestRender;
201 }
202
204 void useOslCommandString(bool useOslCmdstr)
205 {
206 _useOSLCmdStr = useOslCmdstr;
207 }
208
212 void setAaLit(int aa)
213 {
214 _aaLit = aa;
215 }
216
219 void setAaUnlit(int aa)
220 {
221 _aaUnlit = aa;
222 }
223
225 void setOSLCmdStr(const string& oslCmd)
226 {
227 _oslCmdStr = oslCmd;
228 }
229
232 void compileOSL(const FilePath& oslFilePath);
233
235
236 protected:
242 void shadeOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
243
249 void renderOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
250
254 void renderOSLNetwork(const FilePath& dirPath, const string& shaderName);
255
257 OslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType);
258
259 private:
260 FilePath _oslCompilerExecutable;
261 FileSearchPath _oslIncludePath;
262 FilePath _oslOutputFilePath;
263 FilePath _oslOutputFileName;
264
265 FilePath _oslTestShadeExecutable;
266 FilePath _oslTestRenderExecutable;
267 FilePath _oslTestRenderSceneTemplateFile;
268 string _oslShaderName;
269 StringVec _oslShaderParameterOverrides;
270 StringVec _envOslShaderParameterOverrides;
271 string _oslShaderOutputName;
272 string _oslShaderOutputType;
273 FilePath _oslUtilityOSOPath;
274 FilePath _dataLibraryOSOPath;
275 bool _useTestRender;
276 bool _useOSLCmdStr;
277 int _aaLit;
278 int _aaUnlit;
279 string _oslCmdStr;
280};
281
282MATERIALX_NAMESPACE_END
283
284#endif
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition Image.h:23
Image handler interfaces.
vector< string > StringVec
A vector of strings.
Definition Library.h:61
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition Library.h:33
Macros for declaring imported and exported symbols.
Base class for shader rendering.
void * RenderContextHandle
Render context handle Provides a provision for an application to share any renderer specific settings...
Definition ShaderRenderer.h:23
A generic file path, supporting both syntactic and file system operations.
Definition File.h:27
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition File.h:221
void validateInputs() override
Validate inputs for the compiled OSL program.
void setOslTestRenderSceneTemplateFile(const FilePath &templateFilePath)
Set the XML scene file to use for testrender.
Definition OslRenderer.h:170
void setOslUtilityOSOPath(const FilePath &dirPath)
Set the search path for dependent shaders (.oso files) which are used when rendering with testrender.
Definition OslRenderer.h:186
void setOslCompilerExecutable(const FilePath &executableFilePath)
Set the path to the OSL executable.
Definition OslRenderer.h:103
static OslRendererPtr create(unsigned int width=512, unsigned int height=512, Image::BaseType baseType=Image::BaseType::UINT8)
Create an OSL renderer instance.
virtual ~OslRenderer()
Destructor.
void useOslCommandString(bool useOslCmdstr)
Used to switch between testing oso files and osl command strings.
Definition OslRenderer.h:204
void setOSLCmdStr(const string &oslCmd)
Set the osl command string that is to be tested.
Definition OslRenderer.h:225
void createProgram(ShaderPtr shader) override
Create OSL program based on an input shader.
OslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType)
Constructor.
void compileOSL(const FilePath &oslFilePath)
Compile OSL code stored in a file.
void setOslTestRenderExecutable(const FilePath &executableFilePath)
Set the path to the OSL rendering tester.
Definition OslRenderer.h:160
void setOslShaderOutput(const string &outputName, const string &outputType)
Set the OSL shader output.
Definition OslRenderer.h:143
static string OSL_CLOSURE_COLOR_STRING
Color closure OSL string.
Definition OslRenderer.h:42
void setAaUnlit(int aa)
Set the testrender -aa N value used for unlit (non-closure) outputs.
Definition OslRenderer.h:219
void setShaderParameterOverrides(const StringVec &parameterOverrides)
Set shader parameter strings to be added to the scene XML file.
Definition OslRenderer.h:125
void setOslIncludePath(const FileSearchPath &dirPath)
Set the search locations for OSL include files.
Definition OslRenderer.h:111
void render() override
Render OSL program to disk.
void renderOSLNetwork(const FilePath &dirPath, const string &shaderName)
Render using OSL command string.
void setOslShaderName(const string &shaderName)
Set the name of the shader to be used for the input XML scene file.
Definition OslRenderer.h:178
void renderOSL(const FilePath &dirPath, const string &shaderName, const string &outputName)
Render using OSO input file.
void setEnvShaderParameterOverrides(const StringVec &parameterOverrides)
Set shader parameter strings to be added to the scene XML file.
Definition OslRenderer.h:132
void setAaLit(int aa)
Set the testrender -aa N value used for lit (closure-color) outputs.
Definition OslRenderer.h:212
void useTestRender(bool useTestRender)
Used to toggle to either use testrender or testshade during render validation By default testshade is...
Definition OslRenderer.h:198
void setOslOutputFilePath(const FilePath &dirPath)
Set the location where compiled OSL files will reside.
Definition OslRenderer.h:118
ImagePtr captureImage(ImagePtr image=nullptr) override
Capture the current rendered output as an image.
void setOslTestShadeExecutable(const FilePath &executableFilePath)
Set the path to the OSL shading tester.
Definition OslRenderer.h:152
void createProgram(const StageMap &stages) override
Create OSL program based on shader stage source code.
void initialize(RenderContextHandle renderContextHandle=nullptr) override
Internal initialization required for program validation and rendering.
void setSize(unsigned int width, unsigned int height) override
Set the size for rendered image.
void shadeOSL(const FilePath &dirPath, const string &shaderName, const string &outputName)
Shade using OSO input file.
StringMap StageMap
A map with name and source code for each shader stage.
Definition ShaderRenderer.h:40