MaterialX 1.38.10
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
194 void useTestRender(bool useTestRender)
195 {
196 _useTestRender = useTestRender;
197 }
198
200 void setRaysPerPixelLit(int rays)
201 {
202 _raysPerPixelLit = rays;
203 }
204
206 void setRaysPerPixelUnlit(int rays)
207 {
208 _raysPerPixelUnlit = rays;
209 }
210
214 void compileOSL(const FilePath& oslFilePath);
215
217
218 protected:
224 void shadeOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
225
231 void renderOSL(const FilePath& dirPath, const string& shaderName, const string& outputName);
232
234 OslRenderer(unsigned int width, unsigned int height, Image::BaseType baseType);
235
236 private:
237 FilePath _oslCompilerExecutable;
238 FileSearchPath _oslIncludePath;
239 FilePath _oslOutputFilePath;
240 FilePath _oslOutputFileName;
241
242 FilePath _oslTestShadeExecutable;
243 FilePath _oslTestRenderExecutable;
244 FilePath _oslTestRenderSceneTemplateFile;
245 string _oslShaderName;
246 StringVec _oslShaderParameterOverrides;
247 StringVec _envOslShaderParameterOverrides;
248 string _oslShaderOutputName;
249 string _oslShaderOutputType;
250 FilePath _oslUtilityOSOPath;
251 bool _useTestRender;
252 int _raysPerPixelLit;
253 int _raysPerPixelUnlit;
254};
255
256MATERIALX_NAMESPACE_END
257
258#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:57
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.
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:219
Helper class for rendering generated OSL code to produce images.
Definition: OslRenderer.h:33
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
void setRaysPerPixelUnlit(int rays)
Set the number of rays per pixel to be used for unlit surfaces.
Definition: OslRenderer.h:206
void setRaysPerPixelLit(int rays)
Set the number of rays per pixel to be used for lit surfaces.
Definition: OslRenderer.h:200
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 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 setOslShaderName(const string &shaderName)
Set the name of the shader to be used for the input XML scene file.
Definition: OslRenderer.h:178
void setEnvShaderParameterOverrides(const StringVec &parameterOverrides)
Set shader parameter strings to be added to the scene XML file.
Definition: OslRenderer.h:132
void useTestRender(bool useTestRender)
Used to toggle to either use testrender or testshade during render validation By default testshade is...
Definition: OslRenderer.h:194
void setOslOutputFilePath(const FilePath &dirPath)
Set the location where compiled OSL files will reside.
Definition: OslRenderer.h:118
void setOslTestShadeExecutable(const FilePath &executableFilePath)
Set the path to the OSL shading tester.
Definition: OslRenderer.h:152
Base class for renderers that generate shader code to produce images.
Definition: ShaderRenderer.h:31
virtual ImagePtr captureImage(ImagePtr image=nullptr)
Capture the current rendered output as an image.
Definition: ShaderRenderer.h:127
virtual void render()
Render the current program to produce an image.
Definition: ShaderRenderer.h:120
virtual void validateInputs()
Validate inputs for the program.
Definition: ShaderRenderer.h:111
virtual void createProgram(ShaderPtr shader)
Create program based on an input shader.
Definition: ShaderRenderer.cpp:50
virtual void setSize(unsigned int width, unsigned int height)
Set the size of the rendered image.
Definition: ShaderRenderer.cpp:58
StringMap StageMap
A map with name and source code for each shader stage.
Definition: ShaderRenderer.h:40
virtual void initialize(RenderContextHandle=nullptr)
Initialize the renderer.
Definition: ShaderRenderer.h:49