Skip to content

Commit

Permalink
Add two-sided material test
Browse files Browse the repository at this point in the history
 + workaround for AMD
  • Loading branch information
sergcpp committed Mar 27, 2024
1 parent fc5ef8d commit 43da032
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 65 deletions.
14 changes: 8 additions & 6 deletions internal/SceneCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,32 +439,34 @@ Ray::MeshHandle Ray::Cpu::Scene::AddMesh(const mesh_desc_t &_m) {
material_stack[0] = grp.front_mat._index;
uint32_t material_count = 1;

while (material_count) {
while (material_count && is_front_solid) {
const material_t &mat = materials_[material_stack[--material_count]];

if (mat.type == eShadingNode::Mix) {
material_stack[material_count++] = mat.textures[MIX_MAT1];
material_stack[material_count++] = mat.textures[MIX_MAT2];
} else if (mat.type == eShadingNode::Transparent) {
is_front_solid = false;
break;
}
}

if (grp.back_mat != InvalidMaterialHandle) {
material_stack[0] = grp.back_mat._index;
material_count = 1;
if (grp.back_mat != grp.front_mat) {
material_stack[0] = grp.back_mat._index;
material_count = 1;
} else {
is_back_solid = is_front_solid;
}
}

while (material_count) {
while (material_count && is_back_solid) {
const material_t &mat = materials_[material_stack[--material_count]];

if (mat.type == eShadingNode::Mix) {
material_stack[material_count++] = mat.textures[MIX_MAT1];
material_stack[material_count++] = mat.textures[MIX_MAT2];
} else if (mat.type == eShadingNode::Transparent) {
is_back_solid = false;
break;
}
}

Expand Down
14 changes: 8 additions & 6 deletions internal/SceneGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,32 +950,34 @@ inline Ray::MeshHandle Ray::NS::Scene::AddMesh(const mesh_desc_t &_m) {
material_stack[0] = grp.front_mat._index;
uint32_t material_count = 1;

while (material_count) {
while (material_count && is_front_solid) {
const material_t &mat = materials_[material_stack[--material_count]];

if (mat.type == eShadingNode::Mix) {
material_stack[material_count++] = mat.textures[MIX_MAT1];
material_stack[material_count++] = mat.textures[MIX_MAT2];
} else if (mat.type == eShadingNode::Transparent) {
is_front_solid = false;
break;
}
}

if (grp.back_mat != InvalidMaterialHandle) {
material_stack[0] = grp.back_mat._index;
material_count = 1;
if (grp.back_mat != grp.front_mat) {
material_stack[0] = grp.back_mat._index;
material_count = 1;
} else {
is_back_solid = is_front_solid;
}
}

while (material_count) {
while (material_count && is_back_solid) {
const material_t &mat = materials_[material_stack[--material_count]];

if (mat.type == eShadingNode::Mix) {
material_stack[material_count++] = mat.textures[MIX_MAT1];
material_stack[material_count++] = mat.textures[MIX_MAT2];
} else if (mat.type == eShadingNode::Transparent) {
is_back_solid = false;
break;
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/shaders/intersect_scene_shadow.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ vec3 IntersectSceneShadow(shadow_ray_t r) {
const uint back_mi = (g_tri_materials[tri_index] >> 16u) & 0xffff;

const bool is_backfacing = !rayQueryGetIntersectionFrontFaceEXT(rq, true);
const bool solid_hit = (!is_backfacing && (front_mi & MATERIAL_SOLID_BIT) != 0) ||
(is_backfacing && (back_mi & MATERIAL_SOLID_BIT) != 0);
bool solid_hit = !is_backfacing && (front_mi & MATERIAL_SOLID_BIT) != 0;
if (is_backfacing) {
solid_hit = solid_hit || (back_mi & MATERIAL_SOLID_BIT) != 0;
}
if (solid_hit || depth > g_params.max_transp_depth) {
return vec3(0.0);
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void test_tex_storage();

void test_aux_channels(const char *arch_list[], const char *preferred_device);
void test_ray_flags(const char *arch_list[], const char *preferred_device);
void test_two_sided_mat(const char *arch_list[], const char *preferred_device);
void test_oren_mat0(const char *arch_list[], const char *preferred_device);
void test_oren_mat1(const char *arch_list[], const char *preferred_device);
void test_oren_mat2(const char *arch_list[], const char *preferred_device);
Expand Down Expand Up @@ -248,6 +249,7 @@ int main(int argc, char *argv[]) {

futures.push_back(mt_run_pool.Enqueue(test_aux_channels, arch_list, device_name));
futures.push_back(mt_run_pool.Enqueue(test_ray_flags, arch_list, device_name));
futures.push_back(mt_run_pool.Enqueue(test_two_sided_mat, arch_list, device_name));
futures.push_back(mt_run_pool.Enqueue(test_complex_mat0, arch_list, device_name));
futures.push_back(mt_run_pool.Enqueue(test_complex_mat1, arch_list, device_name));
futures.push_back(mt_run_pool.Enqueue(test_complex_mat2, arch_list, device_name));
Expand Down
Binary file added tests/test_data/meshes/mat_test/two_sided.bin
Binary file not shown.
Binary file added tests/test_data/two_sided_mat/ref.tga
Binary file not shown.
35 changes: 18 additions & 17 deletions tests/test_materials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,24 @@ void test_alpha_mat4(const char *arch_list[], const char *preferred_device) {
// Complex material tests
//

void test_two_sided_mat(const char *arch_list[], const char *preferred_device) {
const int SampleCount = 12;
const int PixThres = 788;

Ray::principled_mat_desc_t front_mat_desc;
front_mat_desc.base_color[0] = 0.5f;
front_mat_desc.base_color[1] = 0.0f;
front_mat_desc.base_color[2] = 0.0f;
front_mat_desc.metallic = 1.0f;
front_mat_desc.roughness = 0.0f;
front_mat_desc.alpha_texture = Ray::TextureHandle{0};

const char *textures[] = {"test_data/textures/Fence007A_2K_Opacity.dds"};

run_material_test(arch_list, preferred_device, "two_sided_mat", front_mat_desc, SampleCount, FastMinPSNR, PixThres,
eDenoiseMethod::None, false, textures, eTestScene::Two_Sided);
}

void test_complex_mat0(const char *arch_list[], const char *preferred_device) {
const int SampleCount = 11;
const int PixThres = 759;
Expand Down Expand Up @@ -1299,7 +1317,6 @@ void test_complex_mat2(const char *arch_list[], const char *preferred_device) {

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1320,7 +1337,6 @@ void test_complex_mat3(const char *arch_list[], const char *preferred_device) {

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1342,7 +1358,6 @@ void test_complex_mat4(const char *arch_list[], const char *preferred_device) {

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1365,7 +1380,6 @@ void test_complex_mat5(const char *arch_list[], const char *preferred_device) {

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1386,7 +1400,6 @@ void test_complex_mat5_clipped(const char *arch_list[], const char *preferred_de

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1409,7 +1422,6 @@ void test_complex_mat5_adaptive(const char *arch_list[], const char *preferred_d

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1430,7 +1442,6 @@ void test_complex_mat5_regions(const char *arch_list[], const char *preferred_de

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1451,7 +1462,6 @@ void test_complex_mat5_nlm_filter(const char *arch_list[], const char *preferred

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1472,7 +1482,6 @@ void test_complex_mat5_unet_filter(const char *arch_list[], const char *preferre

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1494,7 +1503,6 @@ void test_complex_mat5_dof(const char *arch_list[], const char *preferred_device

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1515,7 +1523,6 @@ void test_complex_mat5_mesh_lights(const char *arch_list[], const char *preferre

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1538,7 +1545,6 @@ void test_complex_mat5_sphere_light(const char *arch_list[], const char *preferr

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1559,7 +1565,6 @@ void test_complex_mat5_spot_light(const char *arch_list[], const char *preferred

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1581,7 +1586,6 @@ void test_complex_mat5_dir_light(const char *arch_list[], const char *preferred_

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1603,7 +1607,6 @@ void test_complex_mat5_sun_light(const char *arch_list[], const char *preferred_

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1625,7 +1628,6 @@ void test_complex_mat5_moon_light(const char *arch_list[], const char *preferred

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand All @@ -1647,7 +1649,6 @@ void test_complex_mat5_hdri_light(const char *arch_list[], const char *preferred

Ray::principled_mat_desc_t metal_mat_desc;
metal_mat_desc.base_texture = Ray::TextureHandle{0};
metal_mat_desc.metallic = 1.0f;
metal_mat_desc.roughness = 1.0f;
metal_mat_desc.roughness_texture = Ray::TextureHandle{2};
metal_mat_desc.metallic = 1.0f;
Expand Down
Loading

0 comments on commit 43da032

Please sign in to comment.