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 5307158 commit b5d3621
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
21 changes: 7 additions & 14 deletions libs/yocto/yocto_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ vector<pair<int, vec2f>> sample_shape(
namespace yocto {

// Interpolate vertex data
vec3f eval_position(const fvshape_data& shape, int element, vec2f uv) {
vec3f fvshape_position(const fvshape_data& shape, int element, vec2f uv) {
if (!shape.quadspos.empty()) {
auto& quad = shape.quadspos[element];
return interpolate_quad(shape.positions[quad.x], shape.positions[quad.y],
Expand All @@ -482,8 +482,8 @@ vec3f eval_position(const fvshape_data& shape, int element, vec2f uv) {
}
}

vec3f eval_normal(const fvshape_data& shape, int element, vec2f uv) {
if (shape.normals.empty()) return eval_element_normal(shape, element);
vec3f fvshape_normal(const fvshape_data& shape, int element, vec2f uv) {
if (shape.normals.empty()) return fvshape_element_normal(shape, element);
if (!shape.quadspos.empty()) {
auto& quad = shape.quadsnorm[element];
return normalize(
Expand All @@ -494,7 +494,7 @@ vec3f eval_normal(const fvshape_data& shape, int element, vec2f uv) {
}
}

vec2f eval_texcoord(const fvshape_data& shape, int element, vec2f uv) {
vec2f fvshape_texcoord(const fvshape_data& shape, int element, vec2f uv) {
if (shape.texcoords.empty()) return uv;
if (!shape.quadspos.empty()) {
auto& quad = shape.quadstexcoord[element];
Expand All @@ -506,7 +506,7 @@ vec2f eval_texcoord(const fvshape_data& shape, int element, vec2f uv) {
}

// Evaluate element normals
vec3f eval_element_normal(const fvshape_data& shape, int element) {
vec3f fvshape_element_normal(const fvshape_data& shape, int element) {
if (!shape.quadspos.empty()) {
auto& quad = shape.quadspos[element];
return quad_normal(shape.positions[quad.x], shape.positions[quad.y],
Expand All @@ -517,20 +517,13 @@ vec3f eval_element_normal(const fvshape_data& shape, int element) {
}

// Compute per-vertex normals/tangents for lines/triangles/quads.
vector<vec3f> compute_normals(const fvshape_data& shape) {
vector<vec3f> fvshape_normals(const fvshape_data& shape) {
if (!shape.quadspos.empty()) {
return quads_normals(shape.quadspos, shape.positions);
} else {
return vector<vec3f>(shape.positions.size(), {0, 0, 1});
}
}
void compute_normals(vector<vec3f>& normals, const fvshape_data& shape) {
if (!shape.quadspos.empty()) {
quads_normals(normals, shape.quadspos, shape.positions);
} else {
normals.assign(shape.positions.size(), {0, 0, 1});
}
}

// Convert face varying data to single primitives. Returns the quads indices
// and filled vectors for pos, norm and texcoord.
Expand Down Expand Up @@ -650,7 +643,7 @@ fvshape_data remove_normals(const fvshape_data& shape) {
fvshape_data add_normals(const fvshape_data& shape) {
auto transformed = shape;
transformed.quadsnorm = transformed.quadspos;
transformed.normals = compute_normals(shape);
transformed.normals = fvshape_normals(shape);
return transformed;
}

Expand Down
11 changes: 5 additions & 6 deletions libs/yocto/yocto_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,15 @@ vector<pair<int, vec2f>> sample_shape(
namespace yocto {

// Interpolate vertex data
vec3f eval_position(const fvshape_data& shape, int element, vec2f uv);
vec3f eval_normal(const fvshape_data& shape, int element, vec2f uv);
vec2f eval_texcoord(const shape_data& shape, int element, vec2f uv);
vec3f fvshape_position(const fvshape_data& shape, int element, vec2f uv);
vec3f fvshape_normal(const fvshape_data& shape, int element, vec2f uv);
vec2f fvshape_texcoord(const shape_data& shape, int element, vec2f uv);

// Evaluate element normals
vec3f eval_element_normal(const fvshape_data& shape, int element);
vec3f fvshape_element_normal(const fvshape_data& shape, int element);

// Compute per-vertex normals/tangents for lines/triangles/quads.
vector<vec3f> compute_normals(const fvshape_data& shape);
void compute_normals(vector<vec3f>& normals, const fvshape_data& shape);
vector<vec3f> fvshape_normals(const fvshape_data& shape);

// Conversions
shape_data fvshape_to_shape(
Expand Down

0 comments on commit b5d3621

Please sign in to comment.