Skip to content

Commit

Permalink
Use cornell box in samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sergcpp committed Mar 11, 2024
1 parent 888bf70 commit c098725
Show file tree
Hide file tree
Showing 15 changed files with 677 additions and 221 deletions.
150 changes: 111 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,50 +130,125 @@ int main() {
env_desc.env_col[0] = env_desc.env_col[1] = env_desc.env_col[2] = 0.0f;
scene->SetEnvironment(env_desc);

// Add diffuse material
// Add diffuse materials
Ray::shading_node_desc_t mat_desc1;
mat_desc1.type = Ray::eShadingNode::Diffuse;

mat_desc1.base_color[0] = 0.5f;
mat_desc1.base_color[1] = 0.5f;
mat_desc1.base_color[2] = 0.5f;
const Ray::MaterialHandle mat1 = scene->AddMaterial(mat_desc1);

// Add emissive materials
mat_desc1.base_color[0] = 0.5f;
mat_desc1.base_color[1] = 0.0f;
mat_desc1.base_color[2] = 0.0f;
const Ray::MaterialHandle mat2 = scene->AddMaterial(mat_desc1);

mat_desc1.base_color[0] = 0.0f;
mat_desc1.base_color[1] = 0.5f;
mat_desc1.base_color[2] = 0.0f;
const Ray::MaterialHandle mat3 = scene->AddMaterial(mat_desc1);

// Add emissive material
Ray::shading_node_desc_t mat_desc2;
mat_desc2.type = Ray::eShadingNode::Emissive;
mat_desc2.strength = 4.0f;
mat_desc2.strength = 100.0f;
mat_desc2.base_color[0] = 1.0f;
mat_desc2.base_color[1] = 0.0f;
mat_desc2.base_color[2] = 0.0f;
mat_desc2.multiple_importance = true; // Use NEE for this lightsource

const Ray::MaterialHandle mat2 = scene->AddMaterial(mat_desc2);

mat_desc2.base_color[0] = 0.0f;
mat_desc2.base_color[1] = 1.0f;
const Ray::MaterialHandle mat3 = scene->AddMaterial(mat_desc2);

mat_desc2.base_color[1] = 0.0f;
mat_desc2.base_color[2] = 1.0f;
mat_desc2.multiple_importance = true; // Use NEE for this lightsource
const Ray::MaterialHandle mat4 = scene->AddMaterial(mat_desc2);

// Setup test mesh
// Attribute layout is controlled by Ray::eVertexLayout enums
// Is this example(PxyzNxyzTuv): position(3 floats), normal(3 floats), tex_coord(2 floats)
// position(3 floats), normal(3 floats), tex_coord(2 floats)
// clang-format off
const float attrs[] = { -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,

-1.0f, 0.5f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-0.33f, 0.5f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-0.33f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
0.33f, 0.5f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.33f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 0.5f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f };
const float attrs[] = { // floor
0.0f, 0.0f, -0.5592f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
-0.5528f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.5496f, 0.0f, -0.5592f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
// back wall
0.0f, 0.0f, -0.5592f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-0.5496f, 0.0f, -0.5592f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
-0.556f, 0.5488f, -0.5592f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.5488f, -0.5592f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
// ceiling
-0.556f, 0.5488f, -0.5592f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5488f, -0.5592f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5488f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-0.556f, 0.5488f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
// left wall
-0.5528f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-0.5496f, 0.0f, -0.5592f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-0.556f, 0.5488f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-0.556f, 0.5488f, -0.5592f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
// right wall
0.0f, 0.0f, -0.5592f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5488f, -0.5592f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5488f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
// light
-0.213f, 0.5478f, -0.227f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-0.343f, 0.5478f, -0.227f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-0.343f, 0.5478f, -0.332f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-0.213f, 0.5478f, -0.332f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
// short block
-0.240464f, 0.0f, -0.271646f, 0.285951942f, 0.0f, -0.958243966, 0.0f, 0.0f,
-0.240464f, 0.165f, -0.271646f, 0.285951942f, 0.0f, -0.958243966, 0.0f, 0.0f,
-0.082354f, 0.165f, -0.224464f, 0.285951942f, 0.0f, -0.958243966, 0.0f, 0.0f,
-0.082354f, 0.0f, -0.224464f, 0.285951942f, 0.0f, -0.958243966, 0.0f, 0.0f,
-0.240464f, 0.0, -0.271646f, -0.958243966f, 0.0f, -0.285951942f, 0.0f, 0.0f,
-0.240464f, 0.165f, -0.271646f, -0.958243966f, 0.0f, -0.285951942f, 0.0f, 0.0f,
-0.287646f, 0.165f, -0.113536f, -0.958243966f, 0.0f, -0.285951942f, 0.0f, 0.0f,
-0.287646f, 0.0f, -0.113536f, -0.958243966f, 0.0f, -0.285951942f, 0.0f, 0.0f,
-0.082354f, 0.0f, -0.224464f, 0.958243966f, 0.0f, 0.285951942f, 0.0f, 0.0f,
-0.082354f, 0.165f, -0.224464f, 0.958243966f, 0.0f, 0.285951942f, 0.0f, 0.0f,
-0.129536f, 0.165f, -0.066354f, 0.958243966f, 0.0f, 0.285951942f, 0.0f, 0.0f,
-0.129536f, 0.0f, -0.066354f, 0.958243966f, 0.0f, 0.285951942f, 0.0f, 0.0f,
-0.287646f, 0.0f, -0.113536f, -0.285951942f, 0.0f, 0.958243966, 0.0f, 0.0f,
-0.287646f, 0.165f, -0.113536f, -0.285951942f, 0.0f, 0.958243966, 0.0f, 0.0f,
-0.129536f, 0.165f, -0.066354f, -0.285951942f, 0.0f, 0.958243966, 0.0f, 0.0f,
-0.129536f, 0.0f, -0.066354f, -0.285951942f, 0.0f, 0.958243966, 0.0f, 0.0f,
-0.240464f, 0.165f, -0.271646f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.082354f, 0.165f, -0.224464f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.129536f, 0.165f, -0.066354f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.287646f, 0.165f, -0.113536f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
// tall block
-0.471239f, 0.0f, -0.405353f, -0.296278358f, 0.0f, -0.955101609f, 0.0f, 0.0f,
-0.471239f, 0.33f, -0.405353f, -0.296278358f, 0.0f, -0.955101609f, 0.0f, 0.0f,
-0.313647f, 0.33f, -0.454239f, -0.296278358f, 0.0f, -0.955101609f, 0.0f, 0.0f,
-0.313647f, 0.0f, -0.454239f, -0.296278358f, 0.0f, -0.955101609f, 0.0f, 0.0f,
-0.264761f, 0.0f, -0.296647f, 0.955101609f, 0.0f, -0.296278358f, 0.0f, 0.0f,
-0.264761f, 0.33f, -0.296647f, 0.955101609f, 0.0f, -0.296278358f, 0.0f, 0.0f,
-0.313647f, 0.33f, -0.454239f, 0.955101609f, 0.0f, -0.296278358f, 0.0f, 0.0f,
-0.313647f, 0.0f, -0.454239f, 0.955101609f, 0.0f, -0.296278358f, 0.0f, 0.0f,
-0.471239f, 0.0f, -0.405353f, -0.955101609f, 0.0f, 0.296278358f, 0.0f, 0.0f,
-0.471239f, 0.33f, -0.405353f, -0.955101609f, 0.0f, 0.296278358f, 0.0f, 0.0f,
-0.422353f, 0.33f, -0.247761f, -0.955101609f, 0.0f, 0.296278358f, 0.0f, 0.0f,
-0.422353f, 0.0f, -0.247761f, -0.955101609f, 0.0f, 0.296278358f, 0.0f, 0.0f,
-0.422353f, 0.0f, -0.247761f, 0.296278358f, 0.0f, 0.955101609f, 0.0f, 0.0f,
-0.422353f, 0.33f, -0.247761f, 0.296278358f, 0.0f, 0.955101609f, 0.0f, 0.0f,
-0.264761f, 0.33f, -0.296647f, 0.296278358f, 0.0f, 0.955101609f, 0.0f, 0.0f,
-0.264761f, 0.0f, -0.296647f, 0.296278358f, 0.0f, 0.955101609f, 0.0f, 0.0f,
-0.471239f, 0.33f, -0.405353f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.313647f, 0.33f, -0.454239f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.264761f, 0.33f, -0.296647f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
-0.422353f, 0.33f, -0.247761f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f};
const uint32_t indices[] = { 0, 2, 1, 0, 3, 2,
0, 5, 4, 6, 5, 0,
5, 6, 7, 7, 6, 8,
7, 8, 9, 8, 1, 9 };
4, 6, 5, 4, 7, 6,
8, 9, 10, 8, 10, 11,
12, 13, 14, 13, 15, 14,
16, 17, 18, 18, 17, 19,
20, 21, 22, 20, 22, 23,
24, 25, 26, 24, 26, 27,
28, 30, 29, 28, 31, 30,
32, 33, 34, 32, 34, 35,
36, 38, 37, 36, 39, 38,
40, 42, 41, 40, 43, 42,
44, 45, 46, 44, 46, 47,
48, 50, 49, 48, 51, 50,
52, 54, 53, 52, 55, 54,
56, 58, 57, 56, 59, 58,
60, 62, 61, 60, 63, 62};
// clang-format on

Ray::mesh_desc_t mesh_desc;
Expand All @@ -185,11 +260,7 @@ int main() {

// Setup material groups
const Ray::mat_group_desc_t groups[] = {
{mat1, 0, 6},
{mat2, 6, 6},
{mat3, 12, 6},
{mat4, 18, 6},
};
{mat1, 0, 18}, {mat2, 19, 6}, {mat3, 25, 6}, {mat4, Ray::InvalidMaterialHandle, 31, 6}, {mat1, 37, 60}};
mesh_desc.groups = groups;

Ray::MeshHandle mesh1 = scene->AddMesh(mesh_desc);
Expand All @@ -202,15 +273,14 @@ int main() {
scene->AddMeshInstance(mesh1, xform);

// Add camera
const float view_origin[] = {2.0f, 2.0f, 2.0f};
const float view_dir[] = {-0.577f, -0.577f, -0.577f};
const float view_origin[] = {-0.278f, 0.273f, 0.8f};
const float view_dir[] = {0.0f, 0.0f, -1.0f};

Ray::camera_desc_t cam_desc;
cam_desc.type = Ray::eCamType::Persp;
memcpy(&cam_desc.origin[0], &view_origin[0], 3 * sizeof(float));
memcpy(&cam_desc.fwd[0], &view_dir[0], 3 * sizeof(float));
cam_desc.fov = 45.0f;
cam_desc.gamma = 2.2f;
cam_desc.fov = 39.1463f;

const Ray::CameraHandle cam = scene->AddCamera(cam_desc);
scene->set_current_cam(cam);
Expand Down Expand Up @@ -298,6 +368,8 @@ The image can be denoised either with UNet (slower) or NLM filter (faster).
...
```

![Screenshot](images/img2.jpg)

See [samples](samples) folder for more.
</details>

Expand Down
Binary file modified images/img1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/img2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/00_basic.tga
Binary file not shown.
Loading

0 comments on commit c098725

Please sign in to comment.