From b070a1ae34af6a3f60eae7c0a632e39a55ca603d Mon Sep 17 00:00:00 2001 From: Fabio Pellacini Date: Wed, 31 Jan 2024 12:46:35 +0100 Subject: [PATCH] updated --- libs/yocto/yocto_raytracing.cpp | 32 +++++++++++----------- libs/yocto/yocto_raytracing.h | 16 +++++------ libs/yocto/yocto_scene.cpp | 47 +++++++++++++++++---------------- libs/yocto/yocto_scene.h | 23 ++++++++-------- libs/yocto/yocto_trace.cpp | 25 +++++++++--------- 5 files changed, 73 insertions(+), 70 deletions(-) diff --git a/libs/yocto/yocto_raytracing.cpp b/libs/yocto/yocto_raytracing.cpp index 832e80bcb..fb59a886a 100644 --- a/libs/yocto/yocto_raytracing.cpp +++ b/libs/yocto/yocto_raytracing.cpp @@ -992,11 +992,11 @@ static vec4f shade_raytrace(const scene_data& scene, const scene_bvh& bvh, // evaluate geometry auto& instance = scene.instances[intersection.instance]; - auto position = eval_position( + auto position = instance_point( scene, instance, intersection.element, intersection.uv); - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); auto outgoing = -ray.d; @@ -1106,11 +1106,11 @@ static vec4f shade_matte(const scene_data& scene, const scene_bvh& bvh, // evaluate geometry auto& instance = scene.instances[intersection.instance]; - auto position = eval_position( + auto position = instance_point( scene, instance, intersection.element, intersection.uv); - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); // evaluate material @@ -1150,11 +1150,11 @@ static vec4f shade_pointlight(const scene_data& scene, const scene_bvh& bvh, // evaluate geometry auto& instance = scene.instances[intersection.instance]; - auto position = eval_position( + auto position = instance_point( scene, instance, intersection.element, intersection.uv); - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); auto outgoing = -ray.d; @@ -1208,11 +1208,11 @@ static vec4f shade_arealight(const scene_data& scene, const scene_bvh& bvh, // evaluate geometry auto& instance = scene.instances[intersection.instance]; - auto position = eval_position( + auto position = instance_point( scene, instance, intersection.element, intersection.uv); - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); // evaluate material @@ -1280,9 +1280,9 @@ static vec4f shade_eyelight(const scene_data& scene, const scene_bvh& bvh, // evaluate geometry auto& instance = scene.instances[intersection.instance]; - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); auto outgoing = -ray.d; @@ -1308,7 +1308,7 @@ static vec4f shade_normal(const scene_data& scene, const scene_bvh& bvh, // prepare shading point auto& instance = scene.instances[intersection.instance]; - auto normal = eval_normal( + auto normal = instance_normal( scene, instance, intersection.element, intersection.uv); auto radiance = normal * 0.5f + 0.5f; @@ -1326,7 +1326,7 @@ static vec4f shade_texcoord(const scene_data& scene, const scene_bvh& bvh, // prepare shading point auto& instance = scene.instances[intersection.instance]; - auto texcoord = eval_texcoord( + auto texcoord = instance_texcoord( scene, instance, intersection.element, intersection.uv); texcoord = {fmod(texcoord.x, 1), fmod(texcoord.y, 1)}; diff --git a/libs/yocto/yocto_raytracing.h b/libs/yocto/yocto_raytracing.h index 3d2909551..309076bb4 100644 --- a/libs/yocto/yocto_raytracing.h +++ b/libs/yocto/yocto_raytracing.h @@ -728,42 +728,42 @@ namespace yocto { // Convenience functions inline vec3f intersection_point( const scene_data& scene, const intersection3f& intersection) { - return eval_position(scene, scene.instances[intersection.instance], + return instance_point(scene, scene.instances[intersection.instance], intersection.element, intersection.uv); } inline vec3f intersection_normal( const scene_data& scene, const intersection3f& intersection) { - return eval_normal(scene, scene.instances[intersection.instance], + return instance_normal(scene, scene.instances[intersection.instance], intersection.element, intersection.uv); } inline vec3f intersection_element_normal( const scene_data& scene, const intersection3f& intersection) { - return eval_element_normal( + return instance_element_normal( scene, scene.instances[intersection.instance], intersection.element); } inline vec3f intersection_shading_point(const scene_data& scene, const intersection3f& intersection, vec3f outgoing) { - return eval_shading_position(scene, scene.instances[intersection.instance], + return instance_shading_point(scene, scene.instances[intersection.instance], intersection.element, intersection.uv, outgoing); } inline vec3f intersection_shading_normal(const scene_data& scene, const intersection3f& intersection, vec3f outgoing) { - return eval_shading_normal(scene, scene.instances[intersection.instance], + return instance_shading_normal(scene, scene.instances[intersection.instance], intersection.element, intersection.uv, outgoing); } inline vec2f intersection_texcoord( const scene_data& scene, const intersection3f& intersection) { - return eval_texcoord(scene, scene.instances[intersection.instance], + return instance_texcoord(scene, scene.instances[intersection.instance], intersection.element, intersection.uv); } inline material_point intersection_material( const scene_data& scene, const intersection3f& intersection) { - return eval_material(scene, scene.instances[intersection.instance], + return instance_material(scene, scene.instances[intersection.instance], intersection.element, intersection.uv); } inline bool is_volumetric_intersection( const scene_data& scene, const intersection3f& intersection) { - return is_volumetric(scene, scene.instances[intersection.instance]); + return is_volumetric_instance(scene, scene.instances[intersection.instance]); } } // namespace yocto diff --git a/libs/yocto/yocto_scene.cpp b/libs/yocto/yocto_scene.cpp index 35a66a368..519a57a2a 100644 --- a/libs/yocto/yocto_scene.cpp +++ b/libs/yocto/yocto_scene.cpp @@ -864,7 +864,7 @@ bool has_volume(const material_point& material) { namespace yocto { // Eval position -vec3f eval_position(const scene_data& scene, const instance_data& instance, +vec3f instance_point(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& shape = scene.shapes[instance.shape]; if (!shape.triangles.empty()) { @@ -890,7 +890,7 @@ vec3f eval_position(const scene_data& scene, const instance_data& instance, } // Shape element normal. -vec3f eval_element_normal( +vec3f instance_element_normal( const scene_data& scene, const instance_data& instance, int element) { auto& shape = scene.shapes[instance.shape]; if (!shape.triangles.empty()) { @@ -915,11 +915,11 @@ vec3f eval_element_normal( } // Eval normal -vec3f eval_normal(const scene_data& scene, const instance_data& instance, +vec3f instance_normal(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& shape = scene.shapes[instance.shape]; if (shape.normals.empty()) - return eval_element_normal(scene, instance, element); + return instance_element_normal(scene, instance, element); if (!shape.triangles.empty()) { auto t = shape.triangles[element]; return transform_normal( @@ -944,7 +944,7 @@ vec3f eval_normal(const scene_data& scene, const instance_data& instance, } // Eval texcoord -vec2f eval_texcoord(const scene_data& scene, const instance_data& instance, +vec2f instance_texcoord(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& shape = scene.shapes[instance.shape]; if (shape.texcoords.empty()) return uv; @@ -999,7 +999,7 @@ static pair eval_tangents( #endif // Shape element normal. -pair eval_element_tangents( +pair instance_element_tangents( const scene_data& scene, const instance_data& instance, int element) { auto& shape = scene.shapes[instance.shape]; if (!shape.triangles.empty() && !shape.texcoords.empty()) { @@ -1022,18 +1022,18 @@ pair eval_element_tangents( } } -vec3f eval_normalmap(const scene_data& scene, const instance_data& instance, +vec3f instance_normalmap(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& shape = scene.shapes[instance.shape]; auto& material = scene.materials[instance.material]; // apply normal mapping - auto normal = eval_normal(scene, instance, element, uv); - auto texcoord = eval_texcoord(scene, instance, element, uv); + auto normal = instance_normal(scene, instance, element, uv); + auto texcoord = instance_texcoord(scene, instance, element, uv); if (material.normal_tex != invalidid && (!shape.triangles.empty() || !shape.quads.empty())) { auto& normal_tex = scene.textures[material.normal_tex]; auto normalmap = -1 + 2 * xyz(eval_texture(normal_tex, texcoord, true)); - auto [tu, tv] = eval_element_tangents(scene, instance, element); + auto [tu, tv] = instance_element_tangents(scene, instance, element); auto frame = frame3f{tu, tv, normal, {0, 0, 0}}; frame.x = orthonormalize(frame.x, frame.z); frame.y = normalize(cross(frame.z, frame.x)); @@ -1045,34 +1045,34 @@ vec3f eval_normalmap(const scene_data& scene, const instance_data& instance, } // Eval shading position -vec3f eval_shading_position(const scene_data& scene, +vec3f instance_shading_point(const scene_data& scene, const instance_data& instance, int element, vec2f uv, vec3f outgoing) { auto& shape = scene.shapes[instance.shape]; if (!shape.triangles.empty() || !shape.quads.empty()) { - return eval_position(scene, instance, element, uv); + return instance_point(scene, instance, element, uv); } else if (!shape.lines.empty()) { - return eval_position(scene, instance, element, uv); + return instance_point(scene, instance, element, uv); } else if (!shape.points.empty()) { - return eval_position(scene, instance, element, uv); + return instance_point(scene, instance, element, uv); } else { return {0, 0, 0}; } } // Eval shading normal -vec3f eval_shading_normal(const scene_data& scene, +vec3f instance_shading_normal(const scene_data& scene, const instance_data& instance, int element, vec2f uv, vec3f outgoing) { auto& shape = scene.shapes[instance.shape]; auto& material = scene.materials[instance.material]; if (!shape.triangles.empty() || !shape.quads.empty()) { - auto normal = eval_normal(scene, instance, element, uv); + auto normal = instance_normal(scene, instance, element, uv); if (material.normal_tex != invalidid) { - normal = eval_normalmap(scene, instance, element, uv); + normal = instance_normalmap(scene, instance, element, uv); } if (material.type == material_type::refractive) return normal; return dot(normal, outgoing) >= 0 ? normal : -normal; } else if (!shape.lines.empty()) { - auto normal = eval_normal(scene, instance, element, uv); + auto normal = instance_normal(scene, instance, element, uv); return orthonormalize(outgoing, normal); } else if (!shape.points.empty()) { return outgoing; @@ -1082,7 +1082,7 @@ vec3f eval_shading_normal(const scene_data& scene, } // Eval color -vec4f eval_color(const scene_data& scene, const instance_data& instance, +vec4f instance_color(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& shape = scene.shapes[instance.shape]; if (shape.colors.empty()) return {1, 1, 1, 1}; @@ -1105,14 +1105,14 @@ vec4f eval_color(const scene_data& scene, const instance_data& instance, } // Evaluate material -material_point eval_material(const scene_data& scene, +material_point instance_material(const scene_data& scene, const instance_data& instance, int element, vec2f uv) { auto& material = scene.materials[instance.material]; - auto texcoord = eval_texcoord(scene, instance, element, uv); + auto texcoord = instance_texcoord(scene, instance, element, uv); // evaluate textures auto emission_tex = eval_texture(scene, material.emission_tex, texcoord); - auto color_shp = eval_color(scene, instance, element, uv); + auto color_shp = instance_color(scene, instance, element, uv); auto color_tex = eval_texture(scene, material.color_tex, texcoord); auto roughness_tex = eval_texture( scene, material.roughness_tex, texcoord, true); @@ -1156,7 +1156,8 @@ material_point eval_material(const scene_data& scene, } // check if an instance is volumetric -bool is_volumetric(const scene_data& scene, const instance_data& instance) { +bool is_volumetric_instance( + const scene_data& scene, const instance_data& instance) { return is_volumetric(scene.materials[instance.material]); } diff --git a/libs/yocto/yocto_scene.h b/libs/yocto/yocto_scene.h index a0333eb30..e1358a96c 100644 --- a/libs/yocto/yocto_scene.h +++ b/libs/yocto/yocto_scene.h @@ -443,30 +443,31 @@ bool is_volumetric(const scene_data& scene, const instance_data& instance); namespace yocto { // Evaluate instance properties -vec3f eval_position(const scene_data& scene, const instance_data& instance, +vec3f instance_point(const scene_data& scene, const instance_data& instance, int element, vec2f uv); -vec3f eval_element_normal( +vec3f instance_element_normal( const scene_data& scene, const instance_data& instance, int element); -vec3f eval_normal(const scene_data& scene, const instance_data& instance, +vec3f instance_normal(const scene_data& scene, const instance_data& instance, int element, vec2f uv); -vec2f eval_texcoord(const scene_data& scene, const instance_data& instance, +vec2f instance_texcoord(const scene_data& scene, const instance_data& instance, int element, vec2f uv); -pair eval_element_tangents( +pair instance_element_tangents( const scene_data& scene, const instance_data& instance, int element); -vec3f eval_normalmap(const scene_data& scene, const instance_data& instance, +vec3f instance_normalmap(const scene_data& scene, const instance_data& instance, int element, vec2f uv); -vec3f eval_shading_position(const scene_data& scene, +vec3f instance_shading_point(const scene_data& scene, const instance_data& instance, int element, vec2f uv, vec3f outgoing); -vec3f eval_shading_normal(const scene_data& scene, +vec3f instance_shading_normal(const scene_data& scene, const instance_data& instance, int element, vec2f uv, vec3f outgoing); -vec4f eval_color(const scene_data& scene, const instance_data& instance, +vec4f instance_color(const scene_data& scene, const instance_data& instance, int element, vec2f uv); // Eval material to obtain emission, brdf and opacity. -material_point eval_material(const scene_data& scene, +material_point instance_material(const scene_data& scene, const instance_data& instance, int element, vec2f uv); // check if a material has a volume -bool is_volumetric(const scene_data& scene, const instance_data& instance); +bool is_volumetric_instance( + const scene_data& scene, const instance_data& instance); } // namespace yocto diff --git a/libs/yocto/yocto_trace.cpp b/libs/yocto/yocto_trace.cpp index 1fc498f67..e09d4ecfc 100644 --- a/libs/yocto/yocto_trace.cpp +++ b/libs/yocto/yocto_trace.cpp @@ -347,7 +347,7 @@ static vec3f sample_lights(const scene_data& scene, const trace_lights& lights, auto& shape = scene.shapes[instance.shape]; auto element = sample_discrete(light.elements_cdf, rel); auto uv = (!shape.triangles.empty()) ? sample_triangle(ruv) : ruv; - auto lposition = eval_position(scene, instance, element, uv); + auto lposition = instance_point(scene, instance, element, uv); return normalize(lposition - position); } else if (light.environment != invalidid) { auto& environment = scene.environments[light.environment]; @@ -384,9 +384,9 @@ static float sample_lights_pdf(const scene_data& scene, const trace_bvh& bvh, bvh, scene, light.instance, {next_position, direction}); if (!intersection.hit) break; // accumulate pdf - auto lposition = eval_position( + auto lposition = instance_point( scene, instance, intersection.element, intersection.uv); - auto lnormal = eval_element_normal( + auto lnormal = instance_element_normal( scene, instance, intersection.element); // prob triangle * area triangle = area triangle mesh auto area = light.elements_cdf.back(); @@ -659,10 +659,10 @@ static trace_result trace_pathdirect(const scene_data& scene, auto emission = !intersection.hit ? environments_emission(scene, incoming) - : eval_emission(eval_material(scene, + : eval_emission(instance_material(scene, scene.instances[intersection.instance], intersection.element, intersection.uv), - eval_shading_normal(scene, + instance_shading_normal(scene, scene.instances[intersection.instance], intersection.element, intersection.uv, -incoming), -incoming); @@ -854,11 +854,11 @@ static trace_result trace_pathmis(const scene_data& scene, const trace_bvh& bvh, if (!intersection.hit) { emission = environments_emission(scene, incoming); } else { - auto material = eval_material(scene, + auto material = instance_material(scene, scene.instances[intersection.instance], intersection.element, intersection.uv); emission = eval_emission(material, - eval_shading_normal(scene, + instance_shading_normal(scene, scene.instances[intersection.instance], intersection.element, intersection.uv, -incoming), -incoming); @@ -1069,10 +1069,10 @@ static trace_result trace_lightsampling(const scene_data& scene, auto emission = !intersection.hit ? environments_emission(scene, incoming) - : eval_emission(eval_material(scene, + : eval_emission(instance_material(scene, scene.instances[intersection.instance], intersection.element, intersection.uv), - eval_shading_normal(scene, + instance_shading_normal(scene, scene.instances[intersection.instance], intersection.element, intersection.uv, -incoming), -incoming); @@ -1296,9 +1296,10 @@ static trace_result trace_furnace(const scene_data& scene, const trace_bvh& bvh, auto& instance = scene.instances[intersection.instance]; auto element = intersection.element; auto uv = intersection.uv; - auto position = eval_position(scene, instance, element, uv); - auto normal = eval_shading_normal(scene, instance, element, uv, outgoing); - auto material = eval_material(scene, instance, element, uv); + auto position = instance_point(scene, instance, element, uv); + auto normal = instance_shading_normal( + scene, instance, element, uv, outgoing); + auto material = instance_material(scene, instance, element, uv); // handle opacity if (material.opacity < 1 && rand1f(rng) >= material.opacity) {