Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jan 31, 2024
1 parent 2e5d673 commit 4b52148
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 52 deletions.
50 changes: 0 additions & 50 deletions libs/yocto/yocto_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename PFunc, typename TFunc>
inline shape_data make_lines(int steps, PFunc&& position, TFunc&& tangent) {
auto shape = shape_data{};
shape.positions = vector<vec3f>(steps + 1);
shape.normals = vector<vec3f>(steps + 1);
shape.texcoords = vector<vec2f>(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<vec2i>(steps);
for (auto idx : range(steps)) shape.lines[idx] = {idx, idx + 1};
return shape;
}
template <typename PFunc, typename NFunc>
inline shape_data make_quads(vec2i steps, PFunc&& position, NFunc&& normal) {
auto shape = shape_data{};
shape.positions = vector<vec3f>((steps.x + 1) * (steps.y + 1));
shape.normals = vector<vec3f>((steps.x + 1) * (steps.y + 1));
shape.texcoords = vector<vec2f>((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<vec4i>(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
// -----------------------------------------------------------------------------
Expand Down
62 changes: 60 additions & 2 deletions libs/yocto/yocto_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ shape_data subdivide_shape(

// Shape displacement
shape_data displace_shape(const shape_data& shape,
const image_t<float>& displacement, float height, float offset);
const image_t<float>& displacement, float height = 1, float offset = 0.5f);
shape_data displace_shape(const shape_data& shape,
const image_t<vec4f>& displacement, float height, float offset);
const image_t<vec4f>& displacement, float height = 1, float offset = 0.5f);

// Shape sampling
vector<float> sample_shape_cdf(const shape_data& shape);
Expand Down Expand Up @@ -748,4 +748,62 @@ scene_data make_cornellbox();

} // namespace yocto

// -----------------------------------------------------------------------------
//
//
// IMPLEMENTATION
//
//
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// SHAPE FUNCTIONS
// -----------------------------------------------------------------------------
namespace yocto {

// Shape creation
template <typename PFunc, typename TFunc>
inline shape_data make_lines(int steps, PFunc&& position, TFunc&& tangent) {
auto shape = shape_data{};
shape.positions = vector<vec3f>(steps + 1);
shape.normals = vector<vec3f>(steps + 1);
shape.texcoords = vector<vec2f>(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<vec2i>(steps);
for (auto idx : range(steps)) shape.lines[idx] = {idx, idx + 1};
return shape;
}
template <typename PFunc, typename NFunc>
inline shape_data make_quads(vec2i steps, PFunc&& position, NFunc&& normal) {
auto shape = shape_data{};
shape.positions = vector<vec3f>((steps.x + 1) * (steps.y + 1));
shape.normals = vector<vec3f>((steps.x + 1) * (steps.y + 1));
shape.texcoords = vector<vec2f>((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<vec4i>(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

0 comments on commit 4b52148

Please sign in to comment.