-
Notifications
You must be signed in to change notification settings - Fork 414
Expand file tree
/
Copy pathsimplerend.h
More file actions
174 lines (142 loc) · 7.36 KB
/
Copy pathsimplerend.h
File metadata and controls
174 lines (142 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/imageworks/OpenShadingLanguage
#pragma once
#include <map>
#include <memory>
#include <unordered_map>
#include <OpenImageIO/ustring.h>
#include <OpenImageIO/imagebuf.h>
#include <OSL/oslexec.h>
OSL_NAMESPACE_ENTER
void register_closures(OSL::ShadingSystem* shadingsys);
class SimpleRenderer : public RendererServices
{
public:
// Just use 4x4 matrix for transformations
typedef Matrix44 Transformation;
SimpleRenderer ();
~SimpleRenderer () { }
virtual int supports (string_view feature) const;
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform,
float time);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring from, float time);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform);
virtual bool get_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring from);
virtual bool get_inverse_matrix (ShaderGlobals *sg, Matrix44 &result,
ustring to, float time);
void name_transform (const char *name, const Transformation &xform);
virtual bool get_array_attribute (ShaderGlobals *sg, bool derivatives,
ustring object, TypeDesc type, ustring name,
int index, void *val );
virtual bool get_attribute (ShaderGlobals *sg, bool derivatives, ustring object,
TypeDesc type, ustring name, void *val);
virtual bool get_userdata (bool derivatives, ustring name, TypeDesc type,
ShaderGlobals *sg, void *val);
// Set and get renderer attributes/options
void attribute (string_view name, TypeDesc type, const void *value);
void attribute (string_view name, int value) {
attribute (name, TypeDesc::INT, &value);
}
void attribute (string_view name, float value) {
attribute (name, TypeDesc::FLOAT, &value);
}
void attribute (string_view name, string_view value) {
const char *s = value.c_str();
attribute (name, TypeDesc::STRING, &s);
}
OIIO::ParamValue * find_attribute (string_view name,
TypeDesc searchtype=OIIO::TypeUnknown,
bool casesensitive=false);
const OIIO::ParamValue *find_attribute (string_view name,
TypeDesc searchtype=OIIO::TypeUnknown,
bool casesensitive=false) const;
// Super simple camera and display parameters. Many options not
// available, no motion blur, etc.
void camera_params (const Matrix44 &world_to_camera, ustring projection,
float hfov, float hither, float yon,
int xres, int yres);
virtual bool add_output (string_view varname, string_view filename,
TypeDesc datatype = OIIO::TypeFloat,
int nchannels = 3);
OIIO::ImageBuf* outputbuf (int index) {
return index < (int)m_outputbufs.size() ? m_outputbufs[index].get() : nullptr;
}
ustring outputname (int index) const { return m_outputvars[index]; }
size_t noutputs () const { return m_outputbufs.size(); }
virtual void init_shadingsys (ShadingSystem *ss) {
shadingsys = ss;
}
virtual void prepare_render () { }
virtual void warmup () { }
virtual void render (int /*xres*/, int /*yres*/) { }
virtual void clear () { }
// After render, get the pixel data into the output buffers, if
// they aren't already.
virtual void finalize_pixel_buffer () { }
// ShaderGroupRef storage
std::vector<ShaderGroupRef>& shaders() { return m_shaders; }
OIIO::ErrorHandler& errhandler() const { return *m_errhandler; }
ShadingSystem *shadingsys = nullptr;
OIIO::ParamValueList options;
void shutter (float open, float close, int framenumber);
protected:
// Camera parameters
Matrix44 m_world_to_camera;
ustring m_projection {"perspective"};
float m_fov {90}, m_pixelaspect {1.0};
float m_hither {1e-6}, m_yon {1e6};
float m_shutter[2] { 0.0f, 1.0f };
float m_screen_window[4] { -1, 1, -1, 1 };
int m_xres, m_yres;
std::vector<ShaderGroupRef> m_shaders;
std::vector<ustring> m_outputvars;
std::vector<std::shared_ptr<OIIO::ImageBuf>> m_outputbufs;
std::unique_ptr<OIIO::ErrorHandler> m_errhandler { new OIIO::ErrorHandler };
int m_frame = 0;
// Named transforms
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
TransformMap m_named_xforms;
// Attribute and userdata retrieval -- for fast dispatch, use a hash
// table to map attribute names to functions that retrieve them. We
// imagine this to be fairly quick, but for a performance-critical
// renderer, we would encourage benchmarking various methods and
// alternate data structures.
typedef bool (SimpleRenderer::*AttrGetter)(ShaderGlobals *sg, bool derivs,
ustring object, TypeDesc type,
ustring name, void *val);
typedef std::unordered_map<ustring, AttrGetter, ustringHash> AttrGetterMap;
AttrGetterMap m_attr_getters;
// Attribute getters
bool get_osl_version (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_resolution (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_projection (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_fov (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_pixelaspect (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip_near (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_clip_far (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter_open (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_shutter_close (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
bool get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val);
};
OSL_NAMESPACE_EXIT