diff --git a/libs/yocto/yocto_scene.cpp b/libs/yocto/yocto_scene.cpp index 06e720037..385e72807 100644 --- a/libs/yocto/yocto_scene.cpp +++ b/libs/yocto/yocto_scene.cpp @@ -106,56 +106,6 @@ ray3f eval_camera(const camera_data& camera, vec2f image_uv, vec2f lens_uv) { } // namespace yocto -// ----------------------------------------------------------------------------- -// SHAPE FUNCTIONS -// ----------------------------------------------------------------------------- -namespace yocto { - -// Shape creation -template -inline shape_data make_lines(int steps, PFunc&& position, TFunc&& tangent) { - auto shape = shape_data{}; - shape.positions = vector(steps + 1); - shape.normals = vector(steps + 1); - shape.texcoords = vector(steps + 1); - for (auto idx : range(steps + 1)) { - auto u = (float)idx / (float)steps; - shape.positions[idx] = position(u); - shape.normals[idx] = tangent(u); - shape.texcoords[idx] = {u, 0}; - } - shape.lines = vector(steps); - for (auto idx : range(steps)) shape.lines[idx] = {idx, idx + 1}; - return shape; -} -template -inline shape_data make_quads(vec2i steps, PFunc&& position, NFunc&& normal) { - auto shape = shape_data{}; - shape.positions = vector((steps.x + 1) * (steps.y + 1)); - shape.normals = vector((steps.x + 1) * (steps.y + 1)); - shape.texcoords = vector((steps.x + 1) * (steps.y + 1)); - for (auto j : range(steps.y + 1)) { - for (auto i : range(steps.x + 1)) { - auto uv = vec2f{i / (float)steps.x, j / (float)steps.y}; - auto idx = j * (steps.x + 1) + i; - shape.positions[idx] = position(uv); - shape.normals[idx] = normal(uv); - shape.texcoords[idx] = uv; - } - } - shape.quads = vector(steps.x * steps.y); - for (auto j : range(steps.y)) { - for (auto i : range(steps.x)) { - auto idx = j * steps.x + i; - shape.quads[idx] = {j * (steps.x + 1) + i, j * (steps.x + 1) + i + 1, - (j + 1) * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i}; - } - } - return shape; -} - -} // namespace yocto - // ----------------------------------------------------------------------------- // IMPLEMENTATION FO SHAPE PROPERTIES // ----------------------------------------------------------------------------- diff --git a/libs/yocto/yocto_scene.h b/libs/yocto/yocto_scene.h index 63b2ccc55..96994d35f 100644 --- a/libs/yocto/yocto_scene.h +++ b/libs/yocto/yocto_scene.h @@ -323,9 +323,9 @@ shape_data subdivide_shape( // Shape displacement shape_data displace_shape(const shape_data& shape, - const image_t& displacement, float height, float offset); + const image_t& displacement, float height = 1, float offset = 0.5f); shape_data displace_shape(const shape_data& shape, - const image_t& displacement, float height, float offset); + const image_t& displacement, float height = 1, float offset = 0.5f); // Shape sampling vector sample_shape_cdf(const shape_data& shape); @@ -748,4 +748,62 @@ scene_data make_cornellbox(); } // namespace yocto +// ----------------------------------------------------------------------------- +// +// +// IMPLEMENTATION +// +// +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// SHAPE FUNCTIONS +// ----------------------------------------------------------------------------- +namespace yocto { + +// Shape creation +template +inline shape_data make_lines(int steps, PFunc&& position, TFunc&& tangent) { + auto shape = shape_data{}; + shape.positions = vector(steps + 1); + shape.normals = vector(steps + 1); + shape.texcoords = vector(steps + 1); + for (auto idx : range(steps + 1)) { + auto u = (float)idx / (float)steps; + shape.positions[idx] = position(u); + shape.normals[idx] = tangent(u); + shape.texcoords[idx] = {u, 0}; + } + shape.lines = vector(steps); + for (auto idx : range(steps)) shape.lines[idx] = {idx, idx + 1}; + return shape; +} +template +inline shape_data make_quads(vec2i steps, PFunc&& position, NFunc&& normal) { + auto shape = shape_data{}; + shape.positions = vector((steps.x + 1) * (steps.y + 1)); + shape.normals = vector((steps.x + 1) * (steps.y + 1)); + shape.texcoords = vector((steps.x + 1) * (steps.y + 1)); + for (auto j : range(steps.y + 1)) { + for (auto i : range(steps.x + 1)) { + auto uv = vec2f{i / (float)steps.x, j / (float)steps.y}; + auto idx = j * (steps.x + 1) + i; + shape.positions[idx] = position(uv); + shape.normals[idx] = normal(uv); + shape.texcoords[idx] = uv; + } + } + shape.quads = vector(steps.x * steps.y); + for (auto j : range(steps.y)) { + for (auto i : range(steps.x)) { + auto idx = j * steps.x + i; + shape.quads[idx] = {j * (steps.x + 1) + i, j * (steps.x + 1) + i + 1, + (j + 1) * (steps.x + 1) + i + 1, (j + 1) * (steps.x + 1) + i}; + } + } + return shape; +} + +} // namespace yocto + #endif