Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/testrender/cuda/optix_raytracer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ __raygen__setglobals()
OSL::pvt::test_str_2 = render_params.test_str_2;
}

OSL::pvt::num_named_xforms = render_params.num_named_xforms;
OSL::pvt::xform_name_buffer = render_params.xform_name_buffer;
OSL::pvt::xform_buffer = render_params.xform_buffer;

if (render_params.bg_id < 0)
return;

Expand Down
22 changes: 22 additions & 0 deletions src/testrender/optixraytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,28 @@ OptixRaytracer::render(int xres OSL_MAYBE_UNUSED, int yres OSL_MAYBE_UNUSED)
params.test_str_1 = test_str_1;
params.test_str_2 = test_str_2;

// Named transforms
int nxforms = m_named_xforms.size();
params.num_named_xforms = nxforms;
params.xform_name_buffer = DEVICE_ALLOC(sizeof(ustringhash) * nxforms);
params.xform_buffer = DEVICE_ALLOC(sizeof(Transformation) * nxforms);

std::vector<ustringhash> names;
std::vector<Transformation> xforms;
names.reserve(nxforms);
xforms.reserve(nxforms);

for (auto& pair : m_named_xforms) {
names.push_back(pair.first);
xforms.push_back(*pair.second);
}

COPY_TO_DEVICE(params.xform_name_buffer, names.data(),
sizeof(ustringhash) * nxforms);
COPY_TO_DEVICE(params.xform_buffer, xforms.data(),
sizeof(Transformation) * nxforms);
CUDA_SYNC_CHECK();

// Mesh data
params.verts = d_vertices;
params.triangles = d_vert_indices;
Expand Down
8 changes: 5 additions & 3 deletions src/testrender/raytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ struct Camera {
{
float k = OIIO::fast_tan(fov * float(M_PI / 360));
Vec3 right = dir.cross(up).normalize();
cx = right * (xres * k / yres);
cy = (cx.cross(dir)).normalize() * k;
// fov is horizontal
cx = right * k;
cy = (cx.cross(dir)).normalize() * k * yres / xres;
}

// Get a ray for the given screen coordinates.
Expand All @@ -147,7 +148,8 @@ struct Camera {
// components with magnitudes slightly greater than 1.0, which can cause
// downstream computations to blow up and produce NaNs. Normalizing the
// vector again avoids this issue.
const Vec3 v = (cx * (x * invw - 0.5f) + cy * (0.5f - y * invh) + dir)
const Vec3 v = (cx * (x * invw - 0.5f) * 2.f
+ cy * (0.5f - y * invh) * 2.f + dir)
#ifndef __CUDACC__
.normalize();
#else
Expand Down
99 changes: 57 additions & 42 deletions src/testrender/simpleraytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ SimpleRaytracer::parse_scene_xml(const std::string& scenefile)
if (fov_attr)
fov = OIIO::Strutil::from_string<float>(fov_attr.value());

m_fov = fov;
camera.lookat(eye, dir, up, fov);
} else if (strcmp(node.name(), "Sphere") == 0) {
// load sphere
Expand Down Expand Up @@ -506,6 +507,62 @@ SimpleRaytracer::parse_scene_xml(const std::string& scenefile)
if (scene.num_prims() == 0)
errhandler().severefmt("No primitives in scene");
camera.finalize();
prepare_camera_spaces();
}



void
SimpleRaytracer::prepare_camera_spaces()
{
Vec3 right = camera.cx.normalized();
Vec3 up = camera.cy.normalized();

Matrix44 camera_to_world = { right.x, right.y, right.z, 0,
up.x, up.y, up.z, 0,
camera.dir.x, camera.dir.y, camera.dir.z, 0,
camera.eye.x, camera.eye.y, camera.eye.z, 1 };

name_transform("camera", camera_to_world);

// Seems never used once moved to named transforms
m_world_to_camera = camera_to_world.inverse();
Matrix44 M = m_world_to_camera;
float depthrange = (double)m_yon - (double)m_hither;
// clang-format off
if (m_projection == RS::Hashes::perspective) {
float tanhalffov = tanf (0.5f * m_fov * M_PI/180.0);
Matrix44 camera_to_screen ( 1/tanhalffov, 0, 0, 0,
0, 1/tanhalffov, 0, 0,
0, 0, m_yon/depthrange, 1,
0, 0, -m_yon*m_hither/depthrange, 0);
M = M * camera_to_screen;
} else {
Matrix44 camera_to_screen ( 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1/depthrange, 0,
0, 0, -m_hither/depthrange, 1);
M = M * camera_to_screen;
}
name_transform("screen", M.inverse());

float aspect = (float)camera.yres / (float)camera.xres;
float screenleft = -1.0, screenwidth = 2.0;
float screenbottom = -1.0 * aspect, screenheight = 2.0 * aspect;
Matrix44 screen_to_ndc (1/screenwidth, 0, 0, 0,
0, 1/screenheight, 0, 0,
0, 0, 1, 0,
-screenleft/screenwidth, -screenbottom/screenheight, 0, 1);
M = M * screen_to_ndc;
name_transform("NDC", M.inverse());

Matrix44 ndc_to_raster (camera.xres, 0, 0, 0,
0, camera.yres, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
M = M * ndc_to_raster;
name_transform("raster", M.inverse());
// clang-format on
}


Expand Down Expand Up @@ -577,48 +634,6 @@ bool
SimpleRaytracer::get_inverse_matrix(ShaderGlobals* /*sg*/, Matrix44& result,
ustringhash to, float /*time*/)
{
if (to == OSL::Hashes::camera || to == OSL::Hashes::screen
|| to == OSL::Hashes::NDC || to == RS::Hashes::raster) {
// clang-format off
Matrix44 M = m_world_to_camera;
if (to == OSL::Hashes::screen || to == OSL::Hashes::NDC || to == RS::Hashes::raster) {
float depthrange = (double)m_yon-(double)m_hither;
if (m_projection == RS::Hashes::perspective) {
float tanhalffov = tanf (0.5f * m_fov * M_PI/180.0);
Matrix44 camera_to_screen (1/tanhalffov, 0, 0, 0,
0, 1/tanhalffov, 0, 0,
0, 0, m_yon/depthrange, 1,
0, 0, -m_yon*m_hither/depthrange, 0);
M = M * camera_to_screen;
} else {
Matrix44 camera_to_screen (1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1/depthrange, 0,
0, 0, -m_hither/depthrange, 1);
M = M * camera_to_screen;
}
if (to == OSL::Hashes::NDC || to == RS::Hashes::raster) {
float screenleft = -1.0, screenwidth = 2.0;
float screenbottom = -1.0, screenheight = 2.0;
Matrix44 screen_to_ndc (1/screenwidth, 0, 0, 0,
0, 1/screenheight, 0, 0,
0, 0, 1, 0,
-screenleft/screenwidth, -screenbottom/screenheight, 0, 1);
M = M * screen_to_ndc;
if (to == RS::Hashes::raster) {
Matrix44 ndc_to_raster (camera.xres, 0, 0, 0,
0, camera.yres, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
M = M * ndc_to_raster;
}
}
}
// clang-format on
result = M;
return true;
}

TransformMap::const_iterator found = m_named_xforms.find(to);
if (found != m_named_xforms.end()) {
result = *(found->second);
Expand Down
12 changes: 7 additions & 5 deletions src/testrender/simpleraytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class SimpleRaytracer : public RendererServices {
float yon, int xres, int yres);

virtual void parse_scene_xml(const std::string& scenefile);
virtual void prepare_camera_spaces();
virtual void prepare_render();
void prepare_lights();
void prepare_geometry();
Expand Down Expand Up @@ -113,14 +114,19 @@ class SimpleRaytracer : public RendererServices {
int getBackgroundShaderID() const { return backgroundShaderID; }
int getBackgroundResolution() const { return backgroundResolution; }

private:
protected:
// Camera parameters
Matrix44 m_world_to_camera;
ustringhash m_projection;
float m_fov, m_pixelaspect, m_hither, m_yon;
float m_shutter[2];
float m_screen_window[4];

// Named transforms
typedef std::map<ustringhash, std::shared_ptr<Transformation>> TransformMap;
TransformMap m_named_xforms;

private:
int backgroundShaderID = -1;
int backgroundResolution = 1024;
int aa = 1;
Expand All @@ -140,10 +146,6 @@ class SimpleRaytracer : public RendererServices {
std::unique_ptr<OIIO::ErrorHandler> m_errhandler;
bool m_had_error = false;

// Named transforms
typedef std::map<ustringhash, 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
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-background/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="50.0468" />

<ShaderGroup>
string filename "../common/textures/kitchen_probe.hdr";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-bumptest/bumptest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="38.5907" />
<Option max_bounces="int 10" />
<ShaderGroup>shader metal layer1;</ShaderGroup>
<Quad corner="-2000,0,0" edge_x="0,0,4000" edge_y="4000,0,0" /> <!-- Botm -->
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-bunny/bunny.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 1.5, 25" dir="0,0,-1" fov="14.5" />
<Camera eye="0, 1.5, 25" dir="0,0,-1" fov="7.27914" />

<ShaderGroup>color Cs 0.35 0.35 0.35; shader matte layer1;</ShaderGroup>
<Model filename="data/bunny.obj" /> <!-- Grey -->
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-cornell/cornell.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="50, 50, 300" dir="0,0,-1" fov="60" />
<Camera eye="50, 50, 300" dir="0,0,-1" fov="32.2042" />

<ShaderGroup>color Cs 0.75 0.25 0.25; shader matte layer1;</ShaderGroup>
<Quad corner="0, 0, 0" edge_x="0,100,0" edge_y="0,0,150" /> <!-- Left -->
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-displacement/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 1.5, 25" dir="0,0,-1" fov="14.5" />
<Camera eye="0, 1.5, 25" dir="0,0,-1" fov="7.27914" />

<ShaderGroup name="main">color Cs 0.35 0.35 0.35; shader matte layer1;</ShaderGroup>
<ShaderGroup name="main" type="displacement">
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-furnace-diffuse/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="50.0468" />

<ShaderGroup>float Kb 0.5; shader furnace layer1;</ShaderGroup>
<Background />
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-microfacet/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="50.0468" />

<ShaderGroup>
string filename "../common/textures/kitchen_probe.hdr";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-anisotropic-vdf/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 1, 80" look_at="0,1,0" fov="14.0" />
<Camera eye="0, 1, 80" look_at="0,1,0" fov="7.02622" />

<!-- Environment light -->
<ShaderGroup is_light="yes">
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-burley-diffuse/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />
<Option max_bounces="int 5" />

<ShaderGroup>
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-conductor/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-dielectric-glass/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-dielectric/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-furnace-burley-diffuse/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="4.2" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="12.5552" />
<Option max_bounces="int 10" />
<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-furnace-oren-nayar/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="4.2" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="12.5552" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-furnace-sheen/scene.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<World>
<Option max_bounces="int 5" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="4.2" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="12.5552" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-generalized-schlick-glass/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-generalized-schlick/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-layer/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-medium-vdf-glass/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="50, 50, 300" dir="0,0,-1" fov="60" />
<Camera eye="50, 50, 300" dir="0,0,-1" fov="32.2042" />

<ShaderGroup>color Cs 0.75 0.25 0.25; shader matte layer1;</ShaderGroup>
<Quad corner="0, 0, 0" edge_x="0,100,0" edge_y="0,0,150" /> <!-- Left -->
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-medium-vdf/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 80" look_at="0,0,0" fov="14.0" />
<Camera eye="0, 0, 80" look_at="0,0,0" fov="7.02622" />

<!-- Environment light -->
<ShaderGroup is_light="yes">
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-mx-sheen/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="30" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20.2562" />

<ShaderGroup>
shader envmap layer1;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-oren-nayar/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="50.0468" />

<ShaderGroup>
param float scale_s 20;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-raytypes/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 0, 10" look_at="0,0,0" fov="20" />
<Camera eye="0, 0, 10" look_at="0,0,0" fov="13.234" />

<ShaderGroup>
string filename "../common/textures/kitchen_probe.hdr";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-spi-thinlayer/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 100, 300" look_at="0,0,0" fov="70" />
<Camera eye="0, 100, 300" look_at="0,0,0" fov="50.0468" />

<ShaderGroup>
string filename "../common/textures/kitchen_probe.hdr";
Expand Down
2 changes: 1 addition & 1 deletion testsuite/render-uv/scene.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<World>
<Camera eye="0, 250, 400" look_at="0,0,0" fov="40" />
<Camera eye="0, 250, 400" look_at="0,0,0" fov="27.2781" />

<ShaderGroup>
shader uv layer1;
Expand Down
Loading
Loading