Skip to content

Commit

Permalink
Docs: New conventions for retrieving renderer information
Browse files Browse the repository at this point in the history
Add the following conventions for attributes that retrieve information about
the renderer:

      "renderer:name"
      "renderer:version"
      "renderer:versionstring"

and the following attribute that retrieves an integer frame number:

      "camera:frame"
  • Loading branch information
lgritz committed Dec 6, 2017
1 parent cd6081e commit fc520c7
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/doc/languagespec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -4922,12 +4922,15 @@ \section{Renderer state and message passing}
\apiend

\begin{table}[htbp]
\caption{Names of standard attributes that may be retrieved.}\label{tab:cameraattributes}
\caption{Names of standard attributes that may be retrieved.}\label{tab:standardattributes}
\begin{tabular}{|p{1.8in}|p{0.6in}|p{2.8in}|}
\hline
{\bf Name} & {\bf Type} & {\bf Description} \\
\hline
{\cf "osl:version"} & {\cf int} & Major*10000 + Minor*100 + patch. \\
{\cf "osl:version"} & {\cf int} & Major*10000 + Minor*100 + patch. \\[1ex]
{\cf "renderer:name"} & {\cf string} & Name of the renderer. \\
{\cf "renderer:version"} & {\cf int[4]} & Version of renderer (major, minor, release, patch). \\
{\cf "renderer:versionstring"} & {\cf string} & Version of renderer as a string (e.g. \qkw{1.2.7.0}).\\[1ex]
{\cf "shader:shadername"} & {\cf string} & Name of the shader master. \\
{\cf "shader:layername"} & {\cf string} & Name of the layer instance. \\
{\cf "shader:groupname"} & {\cf string} & Name of the shader group. \\
Expand Down Expand Up @@ -4957,6 +4960,7 @@ \section{Renderer state and message passing}
{\cf "camera:shutter_open"} & {\cf float} & Shutter open time. \\
{\cf "camera:shutter_close"} & {\cf float} & Shutter close time. \\
{\cf "camera:shutter"} & {\cf float[2]} & Shutter open and close times. \\
{\cf "camera:frame"} & {\cf int} & Frame number within the shot. \\
{\cf "camera:screen_window"} & {\cf float[4]} & Screen window (xmin, ymin, xmax, ymax). \\
\hline
\end{tabular}
Expand Down
45 changes: 44 additions & 1 deletion src/testrender/simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static ustring u_s("s"), u_t("t");
static TypeDesc TypeFloatArray2 (TypeDesc::FLOAT, 2);
static TypeDesc TypeFloatArray4 (TypeDesc::FLOAT, 4);
static TypeDesc TypeIntArray2 (TypeDesc::INT, 2);
static TypeDesc TypeIntArray4 (TypeDesc::INT, 4);



Expand All @@ -48,6 +49,7 @@ SimpleRenderer::SimpleRenderer ()
Matrix44 M; M.makeIdentity();
camera_params (M, u_perspective, 90.0f,
0.1f, 1000.0f, 256, 256);
shutter (0.0f, 1.0f/48, 0);

// Set up getters
m_attr_getters[ustring("osl:version")] = &SimpleRenderer::get_osl_version;
Expand All @@ -62,6 +64,7 @@ SimpleRenderer::SimpleRenderer ()
m_attr_getters[ustring("camera:shutter")] = &SimpleRenderer::get_camera_shutter;
m_attr_getters[ustring("camera:shutter_open")] = &SimpleRenderer::get_camera_shutter_open;
m_attr_getters[ustring("camera:shutter_close")] = &SimpleRenderer::get_camera_shutter_close;
m_attr_getters[ustring("camera:frame")] = &SimpleRenderer::get_camera_frame;
}


Expand All @@ -86,7 +89,6 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,
m_pixelaspect = 1.0f; // hard-coded
m_hither = hither;
m_yon = yon;
m_shutter[0] = 0.0f; m_shutter[1] = 1.0f; // hard-coded
float frame_aspect = float(xres)/float(yres) * m_pixelaspect;
m_screen_window[0] = -frame_aspect;
m_screen_window[1] = -1.0f;
Expand All @@ -98,6 +100,16 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,



void
SimpleRenderer::shutter (float open, float close, int framenumber)
{
m_shutter[0] = open;
m_shutter[1] = close;
m_frame = framenumber;
}



bool
SimpleRenderer::get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform,
Expand Down Expand Up @@ -224,6 +236,25 @@ SimpleRenderer::get_array_attribute (ShaderGlobals *sg, bool derivatives, ustrin
TypeDesc type, ustring name,
int index, void *val)
{
if (OIIO::Strutil::starts_with (name, "renderer:")) {
if (name == "renderer:name" && type == OIIO::TypeString) {
*(ustring *)val = ustring("OSL testrender");
return true;
}
if (name == "renderer:version" && type == TypeIntArray4) {
int *ival = (int *)val;
ival[0] = OSL_VERSION_MAJOR;
ival[1] = OSL_VERSION_MINOR;
ival[2] = OSL_VERSION_PATCH;
ival[3] = 0;
return true;
}
if (name == "renderer:versionstring" && type == OIIO::TypeString) {
*(ustring *)val = ustring(OSL_LIBRARY_VERSION_STRING);
return true;
}
}

AttrGetterMap::const_iterator g = m_attr_getters.find (name);
if (g != m_attr_getters.end()) {
AttrGetter getter = g->second;
Expand Down Expand Up @@ -451,6 +482,18 @@ SimpleRenderer::get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustrin
}


bool
SimpleRenderer::get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val)
{
if (type == TypeDesc::TypeInt) {
((int *)val)[0] = m_frame;
return true;
}
return false;
}




OSL_NAMESPACE_EXIT
15 changes: 10 additions & 5 deletions src/testrender/simplerend.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ class SimpleRenderer : public RendererServices
void camera_params (const Matrix44 &world_to_camera, ustring projection,
float hfov, float hither, float yon,
int xres, int yres);

void shutter (float open, float close, int framenumber);

private:
// Camera parameters
Matrix44 m_world_to_camera;
ustring m_projection;
float m_fov, m_pixelaspect, m_hither, m_yon;
float m_shutter[2];
float m_screen_window[4];
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;
int m_frame = 0;

// Named transforms
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
Expand Down Expand Up @@ -123,6 +126,8 @@ class SimpleRenderer : public RendererServices
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);

};

Expand Down
43 changes: 43 additions & 0 deletions src/testshade/simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ static ustring u_s("s"), u_t("t");
static TypeDesc TypeFloatArray2 (TypeDesc::FLOAT, 2);
static TypeDesc TypeFloatArray4 (TypeDesc::FLOAT, 4);
static TypeDesc TypeIntArray2 (TypeDesc::INT, 2);
static TypeDesc TypeIntArray4 (TypeDesc::INT, 4);


void register_closures(OSL::ShadingSystem* shadingsys) {
Expand Down Expand Up @@ -148,6 +149,7 @@ SimpleRenderer::SimpleRenderer ()
Matrix44 M; M.makeIdentity();
camera_params (M, u_perspective, 90.0f,
0.1f, 1000.0f, 256, 256);
shutter (0.0f, 1.0f/48, 0);

// Set up getters
m_attr_getters[ustring("osl:version")] = &SimpleRenderer::get_osl_version;
Expand All @@ -162,6 +164,7 @@ SimpleRenderer::SimpleRenderer ()
m_attr_getters[ustring("camera:shutter")] = &SimpleRenderer::get_camera_shutter;
m_attr_getters[ustring("camera:shutter_open")] = &SimpleRenderer::get_camera_shutter_open;
m_attr_getters[ustring("camera:shutter_close")] = &SimpleRenderer::get_camera_shutter_close;
m_attr_getters[ustring("camera:frame")] = &SimpleRenderer::get_camera_frame;
}


Expand Down Expand Up @@ -198,6 +201,16 @@ SimpleRenderer::camera_params (const Matrix44 &world_to_camera,



void
SimpleRenderer::shutter (float open, float close, int framenumber)
{
m_shutter[0] = open;
m_shutter[1] = close;
m_frame = framenumber;
}



bool
SimpleRenderer::get_matrix (ShaderGlobals *sg, Matrix44 &result,
TransformationPtr xform,
Expand Down Expand Up @@ -324,6 +337,25 @@ SimpleRenderer::get_array_attribute (ShaderGlobals *sg, bool derivatives, ustrin
TypeDesc type, ustring name,
int index, void *val)
{
if (OIIO::Strutil::starts_with (name, "renderer:")) {
if (name == "renderer:name" && type == OIIO::TypeString) {
*(ustring *)val = ustring("OSL testshade");
return true;
}
if (name == "renderer:version" && type == TypeIntArray4) {
int *ival = (int *)val;
ival[0] = OSL_VERSION_MAJOR;
ival[1] = OSL_VERSION_MINOR;
ival[2] = OSL_VERSION_PATCH;
ival[3] = 0;
return true;
}
if (name == "renderer:versionstring" && type == OIIO::TypeString) {
*(ustring *)val = ustring(OSL_LIBRARY_VERSION_STRING);
return true;
}
}

AttrGetterMap::const_iterator g = m_attr_getters.find (name);
if (g != m_attr_getters.end()) {
AttrGetter getter = g->second;
Expand Down Expand Up @@ -560,5 +592,16 @@ SimpleRenderer::get_camera_screen_window (ShaderGlobals *sg, bool derivs, ustrin



bool
SimpleRenderer::get_camera_frame (ShaderGlobals *sg, bool derivs, ustring object,
TypeDesc type, ustring name, void *val)
{
if (type == TypeDesc::TypeInt) {
((int *)val)[0] = m_frame;
return true;
}
return false;
}


OSL_NAMESPACE_EXIT
15 changes: 10 additions & 5 deletions src/testshade/simplerend.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ class SimpleRenderer : public RendererServices
void camera_params (const Matrix44 &world_to_camera, ustring projection,
float hfov, float hither, float yon,
int xres, int yres);

void shutter (float open, float close, int framenumber);

private:
// Camera parameters
Matrix44 m_world_to_camera;
ustring m_projection;
float m_fov, m_pixelaspect, m_hither, m_yon;
float m_shutter[2];
float m_screen_window[4];
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;
int m_frame = 0;

// Named transforms
typedef std::map <ustring, std::shared_ptr<Transformation> > TransformMap;
Expand Down Expand Up @@ -126,6 +129,8 @@ class SimpleRenderer : public RendererServices
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);

};

Expand Down

0 comments on commit fc520c7

Please sign in to comment.