Skip to content

Commit

Permalink
Fix black fringes by avoiding ff_normal
Browse files Browse the repository at this point in the history
  • Loading branch information
crocdialer committed Dec 7, 2024
1 parent 1f1b021 commit 6eb2aef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
7 changes: 4 additions & 3 deletions shaders/ray/closesthit.rchit
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Vertex interpolate_vertex(Triangle t)
vec4 quat = vec4(entry.transform.rotation_x, entry.transform.rotation_y, entry.transform.rotation_z,
entry.transform.rotation_w);
out_vert.normal = rotate_quat(quat, out_vert.normal);
out_vert.normal = gl_HitKindEXT == gl_HitKindBackFacingTriangleEXT ? -out_vert.normal : out_vert.normal;
out_vert.tangent = rotate_quat(quat, out_vert.tangent);
return out_vert;
}
Expand Down Expand Up @@ -299,7 +300,7 @@ void main()
}

// flip the normal so it points against the ray direction:
payload.ff_normal = faceforward(payload.normal, gl_WorldRayDirectionEXT, payload.normal);
vec3 ff_normal = faceforward(payload.normal, gl_WorldRayDirectionEXT, payload.normal);

// max emission from material/map
if((material.texture_type_flags & TEXTURE_TYPE_EMISSION) != 0)
Expand All @@ -309,7 +310,7 @@ void main()
triangle_lod).rgb);

}
material.emission.rgb *= dot(payload.normal, payload.ff_normal) > 0 ? material.emission.a : 0.0;
material.emission.rgb *= dot(payload.normal, ff_normal) > 0 ? material.emission.a : 0.0;

// add radiance from emission
payload.radiance += payload.beta * material.emission.rgb;
Expand All @@ -334,7 +335,7 @@ void main()
payload.cone = propagate(payload.cone, 0.0, gl_HitTEXT);

// take sample from burley/disney BSDF
bsdf_sample_t bsdf_sample = sample_disney(material, payload.ff_normal, V, eta, rng_state);
bsdf_sample_t bsdf_sample = sample_disney(material, payload.normal, V, eta, rng_state);

// TODO: check wtf/when pdf turns out NaN here
if(bsdf_sample.pdf <= 0.0 || isnan(bsdf_sample.pdf)){ payload.stop = true; return; }
Expand Down
3 changes: 0 additions & 3 deletions shaders/ray/ray_common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ struct payload_t
// worldspace normal
vec3 normal;

// faceforward worldspace normal
vec3 ff_normal;

// accumulated radiance along a path
vec3 radiance;

Expand Down
11 changes: 4 additions & 7 deletions src/imgui/imgui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,13 +837,10 @@ void draw_mesh_ui(const vierkant::Object3DPtr &object, vierkant::mesh_component_

if(ImGui::TreeNodeEx((void *) (mesh_id + entry_idx), 0, "%s", entry_name.c_str()))
{
std::stringstream ss;
ss << "positions: " << std::to_string(e.num_vertices) << "\n";
ss << "faces: " << std::to_string(e.lods.empty() ? 0 : e.lods[0].num_indices / 3);
ss << "lods: " << std::to_string(e.lods.size());
ss << "material_index: " << std::to_string(e.material_index);
ImGui::Text("%s", ss.str().c_str());

auto mesh_info_str =
spdlog::fmt_lib::format("positions: {}\nfaces: {}\nlods: {}\nmaterial_index: {}",
e.num_vertices, e.lods[0].num_indices, e.lods.size(), e.material_index);
ImGui::Text("%s", mesh_info_str.c_str());
ImGui::Separator();

// material ui
Expand Down

0 comments on commit 6eb2aef

Please sign in to comment.