Skip to content

Commit 7ab79d0

Browse files
authored
Merge pull request #138 from beasterio/rpr
fix RPR get* methods.
2 parents 876cb53 + 383b1eb commit 7ab79d0

11 files changed

+82
-52
lines changed

Rpr/RadeonProRender.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ rpr_int rprShapeSetDisplacementScale(rpr_shape shape, rpr_float minscale, rpr_fl
922922

923923
rpr_int rprShapeSetObjectGroupID(rpr_shape shape, rpr_uint objectGroupID)
924924
{
925-
UNIMLEMENTED_FUNCTION
925+
UNSUPPORTED_FUNCTION
926926
}
927927

928928
rpr_int rprShapeSetDisplacementImage(rpr_shape shape, rpr_image image)
@@ -1048,6 +1048,7 @@ rpr_int rprShapeGetInfo(rpr_shape in_shape, rpr_shape_info in_info, size_t in_si
10481048
case RPR_SHAPE_TRANSFORM:
10491049
{
10501050
RadeonRays::matrix value = shape->GetTransform();
1051+
value = value.transpose();
10511052
size_ret = sizeof(value);
10521053
data.resize(size_ret);
10531054
memcpy(&data[0], &value, size_ret);
@@ -1144,18 +1145,16 @@ rpr_int rprMeshGetInfo(rpr_shape in_mesh, rpr_mesh_info in_mesh_info, size_t in_
11441145
}
11451146
case RPR_MESH_VERTEX_ARRAY:
11461147
{
1147-
const RadeonRays::float3* value = mesh->GetVertexData();
1148-
size_ret = sizeof(RadeonRays::float3) * mesh->GetVertexCount();
1148+
size_ret = sizeof(float) * 3 * mesh->GetVertexCount();
11491149
data.resize(size_ret);
1150-
memcpy(&data[0], &value, size_ret);
1150+
mesh->GetVertexData(reinterpret_cast<float*>(data.data()));
11511151
break;
11521152
}
11531153
case RPR_MESH_NORMAL_ARRAY:
11541154
{
1155-
const RadeonRays::float3* value = mesh->GetNormalData();
1156-
size_ret = sizeof(RadeonRays::float3) * mesh->GetNormalCount();
1155+
size_ret = sizeof(float) * 3 * mesh->GetNormalCount();
11571156
data.resize(size_ret);
1158-
memcpy(&data[0], &value, size_ret);
1157+
mesh->GetNormalData(reinterpret_cast<float*>(data.data()));
11591158
break;
11601159

11611160
}
@@ -1164,26 +1163,26 @@ rpr_int rprMeshGetInfo(rpr_shape in_mesh, rpr_mesh_info in_mesh_info, size_t in_
11641163
const RadeonRays::float2* value = mesh->GetUVData();
11651164
size_ret = sizeof(RadeonRays::float2) * mesh->GetUVCount();
11661165
data.resize(size_ret);
1167-
memcpy(&data[0], &value, size_ret);
1166+
memcpy(&data[0], value, size_ret);
11681167
break;
11691168
}
11701169
case RPR_MESH_VERTEX_INDEX_ARRAY:
11711170
case RPR_MESH_UV_INDEX_ARRAY:
11721171
case RPR_MESH_NORMAL_INDEX_ARRAY:
11731172
{
11741173
const uint32_t* value = mesh->GetIndicesData();
1175-
size_ret = sizeof(uint32_t) * mesh->GetVertexCount();
1174+
size_ret = sizeof(uint32_t) * mesh->GetIndicesCount();
11761175
data.resize(size_ret);
1177-
memcpy(&data[0], &value, size_ret);
1176+
memcpy(&data[0], value, size_ret);
11781177
break;
11791178
}
11801179
case RPR_MESH_NUM_FACE_VERTICES_ARRAY:
11811180
{
11821181
//only triangles used in Baikal mesh
1183-
std::vector<int32_t> value(mesh->GetVertexCount() / 3, 3);
1184-
size_ret = sizeof(value);
1182+
std::vector<int32_t> value(mesh->GetIndicesCount() / 3, 3);
1183+
size_ret = sizeof(int32_t) * value.size();
11851184
data.resize(size_ret);
1186-
memcpy(&data[0], &value, size_ret);
1185+
memcpy(&data[0], value.data(), size_ret);
11871186
break;
11881187
}
11891188
default:
@@ -1493,14 +1492,15 @@ rpr_int rprLightGetInfo(rpr_light in_light, rpr_light_info in_info, size_t in_si
14931492
case RPR_LIGHT_TRANSFORM:
14941493
{
14951494
RadeonRays::matrix value = light->GetTransform();
1495+
value = value.transpose();
14961496
size_ret = sizeof(value);
14971497
data.resize(size_ret);
14981498
memcpy(&data[0], &value, size_ret);
14991499
break;
15001500
}
15011501
case RPR_ENVIRONMENT_LIGHT_IMAGE:
15021502
{
1503-
RadeonRays::matrix value = light->GetTransform();
1503+
MaterialObject* value = light->GetEnvTexture();
15041504
size_ret = sizeof(value);
15051505
data.resize(size_ret);
15061506
memcpy(&data[0], &value, size_ret);
@@ -2036,7 +2036,8 @@ rpr_int rprMaterialNodeGetInputInfo(rpr_material_node in_node, rpr_int in_input_
20362036
}
20372037
case RPR_MATERIAL_NODE_INPUT_VALUE:
20382038
{
2039-
data.resize(sizeof(size_t));
2039+
//sizeof(RadeonRays::float4) should be enough to store any input data
2040+
data.resize(sizeof(RadeonRays::float4));
20402041
mat->GetInput(in_input_idx, data.data(), &size_ret);
20412042
break;
20422043
}

Rpr/WrapObject/CameraObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ THE SOFTWARE.
2121
********************************************************************/
2222

2323
#include "WrapObject/CameraObject.h"
24-
#include "Scene/camera.h"
24+
#include "SceneGraph/camera.h"
2525
#include "radeon_rays.h"
2626

2727
using namespace Baikal;
@@ -75,6 +75,6 @@ void CameraObject::GetLookAt(RadeonRays::float3& eye,
7575
RadeonRays::float3& up)
7676
{
7777
eye = m_cam->GetPosition();
78-
at = m_cam->GetForwardVector();
78+
at = m_cam->GetForwardVector() + eye;
7979
up = m_cam->GetUpVector();
8080
}

Rpr/WrapObject/CameraObject.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ THE SOFTWARE.
2222
#pragma once
2323

2424
#include "WrapObject.h"
25-
#include "Scene/camera.h"
25+
#include "SceneGraph/camera.h"
2626

2727
#include "math/matrix.h"
2828
#include "RadeonProRender.h"
@@ -42,13 +42,13 @@ class CameraObject
4242
//camera data
4343
//Note: some values are converted between meters and mm
4444
void SetFocalLength(rpr_float flen) { m_cam->SetFocalLength(flen / 1000.f); }
45-
rpr_float GetFocalLength() { return m_cam->GetFocalLength(); }
45+
rpr_float GetFocalLength() { return m_cam->GetFocalLength() * 1000.f; }
4646

4747
void SetFocusDistance(rpr_float fdist) { m_cam->SetFocusDistance(fdist); }
4848
rpr_float GetFocusDistance() { return m_cam->GetFocusDistance(); }
4949

50-
void SetSensorSize(RadeonRays::float2 size) { m_cam->SetSensorSize(size * 0.001); }
51-
RadeonRays::float2 GetSensorSize() { return m_cam->GetSensorSize() * 1000; }
50+
void SetSensorSize(RadeonRays::float2 size) { m_cam->SetSensorSize(size * 0.001f); }
51+
RadeonRays::float2 GetSensorSize() { return m_cam->GetSensorSize() * 1000.f; }
5252

5353
void GetLookAt(RadeonRays::float3& eye,
5454
RadeonRays::float3& at,

Rpr/WrapObject/ContextObject.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ THE SOFTWARE.
3030
#include "WrapObject/MaterialObject.h"
3131
#include "WrapObject/Exception.h"
3232

33-
#include "Scene/scene1.h"
34-
#include "Scene/iterator.h"
35-
#include "Scene/material.h"
36-
#include "Scene/light.h"
33+
#include "SceneGraph/scene1.h"
34+
#include "SceneGraph/iterator.h"
35+
#include "SceneGraph/material.h"
36+
#include "SceneGraph/light.h"
3737

3838
namespace
3939
{

Rpr/WrapObject/ContextObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ THE SOFTWARE.
2424
#include "WrapObject/WrapObject.h"
2525
#include "WrapObject/LightObject.h"
2626

27-
#include "App/config_manager.h"
28-
#include "App/PT/ptrenderer.h"
27+
#include "App/Utils/config_manager.h"
28+
#include "App/Renderers/PT/ptrenderer.h"
2929

3030
#include <vector>
3131
#include "RadeonProRender.h"

Rpr/WrapObject/LightObject.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ THE SOFTWARE.
2323
#include "WrapObject/MaterialObject.h"
2424
#include "WrapObject/Exception.h"
2525
#include "radeon_rays.h"
26-
#include "App/Scene/light.h"
26+
#include "App/SceneGraph/light.h"
2727
#include "RadeonProRender.h"
2828

2929
void LightObject::SetTransform(const RadeonRays::matrix& t)
3030
{
31-
m_light->SetPosition(RadeonRays::float3(t.m30, t.m31, t.m32, t.m33));
31+
m_light->SetPosition(RadeonRays::float3(t.m03, t.m13, t.m23, t.m33));
3232
//float3(0, 0, -1) is a default direction vector
3333
m_light->SetDirection(t * RadeonRays::float3(0, 0, -1));
3434
}

Rpr/WrapObject/MaterialObject.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ THE SOFTWARE.
2323
#include <map>
2424

2525
#include "math/int2.h"
26-
#include "App/Scene/texture.h"
27-
#include "App/Scene/material.h"
28-
#include "App/Scene/IO/image_io.h"
29-
#include "App/Scene/iterator.h"
26+
#include "App/SceneGraph/texture.h"
27+
#include "App/SceneGraph/material.h"
28+
#include "App/SceneGraph/IO/image_io.h"
29+
#include "App/SceneGraph/iterator.h"
3030
#include "WrapObject/MaterialObject.h"
3131
#include "WrapObject/Exception.h"
3232

@@ -627,7 +627,7 @@ void MaterialObject::GetInput(int i, void* out, size_t* out_size)
627627
rpr_image_desc MaterialObject::GetTextureDesc() const
628628
{
629629
RadeonRays::int2 size = m_tex->GetSize();
630-
rpr_uint depth = m_tex->GetSizeInBytes() / size.x / size.y;
630+
rpr_uint depth = (rpr_uint)m_tex->GetSizeInBytes() / size.x / size.y;
631631
return {(rpr_uint)size.x, (rpr_uint)size.y, depth, 0, 0};
632632
}
633633
char const* MaterialObject::GetTextureData() const

Rpr/WrapObject/SceneObject.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ THE SOFTWARE.
2424
#include "WrapObject/ShapeObject.h"
2525
#include "WrapObject/LightObject.h"
2626
#include "WrapObject/CameraObject.h"
27-
#include "App/Scene/scene1.h"
28-
#include "App/Scene/light.h"
29-
#include "App/Scene/shape.h"
30-
#include "App/Scene/material.h"
31-
#include "App/Scene/iterator.h"
27+
#include "App/SceneGraph/scene1.h"
28+
#include "App/SceneGraph/light.h"
29+
#include "App/SceneGraph/shape.h"
30+
#include "App/SceneGraph/material.h"
31+
#include "App/SceneGraph/iterator.h"
3232

3333
#include <assert.h>
3434

Rpr/WrapObject/SceneObject.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ THE SOFTWARE.
2222
#pragma once
2323

2424
#include "WrapObject/WrapObject.h"
25-
#include "Scene/scene1.h"
26-
#include "Scene/shape.h"
27-
#include "Scene/light.h"
25+
#include "SceneGraph/scene1.h"
26+
#include "SceneGraph/shape.h"
27+
#include "SceneGraph/light.h"
2828

2929
#include <vector>
3030

Rpr/WrapObject/ShapeObject.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ THE SOFTWARE.
2525

2626
#include "WrapObject/ShapeObject.h"
2727
#include "WrapObject/Exception.h"
28-
#include "App/Scene/shape.h"
28+
#include "App/SceneGraph/shape.h"
2929

3030

3131
using namespace Baikal;
@@ -46,7 +46,7 @@ namespace
4646
count +=in_num_face_vertices[i];
4747
}
4848
result.resize(count * size);
49-
std::fill(result.begin(), result.end(), 0);
49+
std::fill(result.begin(), result.end(), 0.f);
5050

5151
return result;
5252
}
@@ -191,14 +191,23 @@ uint64_t ShapeObject::GetVertexCount()
191191
return mesh->GetNumVertices();
192192
}
193193

194-
const RadeonRays::float3* ShapeObject::GetVertexData() const
194+
void ShapeObject::GetVertexData(float* out) const
195195
{
196196
Baikal::Mesh* mesh = dynamic_cast<Baikal::Mesh*>(m_shape);
197197
if (!mesh)
198198
{
199199
throw Exception(RPR_ERROR_INTERNAL_ERROR, "ShapeObject: mesh is nullptr.");
200200
}
201-
return mesh->GetVertices();
201+
202+
//need to copy data, because RadeonRays::float3 contains 4 float,
203+
//but we need only 3
204+
const RadeonRays::float3 * data = mesh->GetVertices();
205+
for (int i = 0; i < mesh->GetNumVertices(); ++i)
206+
{
207+
out[3 * i] = data[i].x;
208+
out[3 * i + 1] = data[i].y;
209+
out[3 * i + 2] = data[i].z;
210+
}
202211
}
203212

204213

@@ -211,14 +220,23 @@ uint64_t ShapeObject::GetNormalCount()
211220
}
212221
return mesh->GetNumNormals();
213222
}
214-
const RadeonRays::float3* ShapeObject::GetNormalData() const
223+
void ShapeObject::GetNormalData(float* out) const
215224
{
216225
Baikal::Mesh* mesh = dynamic_cast<Baikal::Mesh*>(m_shape);
217226
if (!mesh)
218227
{
219228
throw Exception(RPR_ERROR_INTERNAL_ERROR, "ShapeObject: mesh is nullptr.");
220229
}
221-
return mesh->GetNormals();
230+
231+
//need to copy data, because RadeonRays::float3 contains 4 float,
232+
//but we need only 3
233+
const RadeonRays::float3 * data = mesh->GetNormals();
234+
for (int i = 0; i < mesh->GetNumNormals(); ++i)
235+
{
236+
out[3 * i] = data[i].x;
237+
out[3 * i + 1] = data[i].y;
238+
out[3 * i + 2] = data[i].z;
239+
}
222240
}
223241

224242

@@ -249,3 +267,13 @@ const uint32_t* ShapeObject::GetIndicesData() const
249267
}
250268
return mesh->GetIndices();
251269
}
270+
271+
uint64_t ShapeObject::GetIndicesCount() const
272+
{
273+
Baikal::Mesh* mesh = dynamic_cast<Baikal::Mesh*>(m_shape);
274+
if (!mesh)
275+
{
276+
throw Exception(RPR_ERROR_INTERNAL_ERROR, "ShapeObject: mesh is nullptr.");
277+
}
278+
return mesh->GetNumIndices();
279+
}

0 commit comments

Comments
 (0)