diff --git a/libs/yocto/yocto_animation.h b/libs/yocto/yocto_animation.h index 9a36fa9ab..7222ea4ac 100644 --- a/libs/yocto/yocto_animation.h +++ b/libs/yocto/yocto_animation.h @@ -428,8 +428,7 @@ inline quat4f log_map(const quat4f& q) { // Linear interpolation of translation, scaling and rotations. // Rotations are interpolated using the exponential map. -inline frame3f interpolate_translation( - vec3f a, vec3f b, float t) { +inline frame3f interpolate_translation(vec3f a, vec3f b, float t) { return translation_frame(lerp(a, b, t)); } inline frame3f interpolate_scaling(vec3f a, vec3f b, float t) { diff --git a/libs/yocto/yocto_bvh.cpp b/libs/yocto/yocto_bvh.cpp index 8ad39ae62..8b68dbd91 100644 --- a/libs/yocto/yocto_bvh.cpp +++ b/libs/yocto/yocto_bvh.cpp @@ -659,8 +659,7 @@ namespace yocto { // Intersect ray with a bvh. shape_intersection overlap_shape_bvh(const shape_bvh& sbvh, - const shape_data& shape, vec3f pos, float max_distance, - bool find_any) { + const shape_data& shape, vec3f pos, float max_distance, bool find_any) { // get bvh tree auto& bvh = sbvh.bvh; @@ -748,8 +747,7 @@ shape_intersection overlap_shape_bvh(const shape_bvh& sbvh, // Intersect ray with a bvh. scene_intersection overlap_scene_bvh(const scene_bvh& sbvh, - const scene_data& scene, vec3f pos, float max_distance, - bool find_any) { + const scene_data& scene, vec3f pos, float max_distance, bool find_any) { // get instances bvh auto& bvh = sbvh.bvh; diff --git a/libs/yocto/yocto_color.h b/libs/yocto/yocto_color.h index 8852cdd53..bbb2c6c32 100644 --- a/libs/yocto/yocto_color.h +++ b/libs/yocto/yocto_color.h @@ -253,15 +253,11 @@ inline vec4f srgb_to_rgb(vec4f srgb) { inline vec3f rgb_to_srgb(vec3f rgb) { return {rgb_to_srgb(rgb.x), rgb_to_srgb(rgb.y), rgb_to_srgb(rgb.z)}; } -inline vec4f rgb_to_srgb(vec4f rgb) { - return {rgb_to_srgb(xyz(rgb)), rgb.w}; -} +inline vec4f rgb_to_srgb(vec4f rgb) { return {rgb_to_srgb(xyz(rgb)), rgb.w}; } inline vec4f srgbb_to_rgb(vec4b srgb) { return srgb_to_rgb(byte_to_float(srgb)); } -inline vec4b rgb_to_srgbb(vec4f rgb) { - return float_to_byte(rgb_to_srgb(rgb)); -} +inline vec4b rgb_to_srgbb(vec4f rgb) { return float_to_byte(rgb_to_srgb(rgb)); } // Conversion between number of channels. inline vec4f rgb_to_rgba(vec3f rgb) { return {rgb, 1}; } @@ -293,13 +289,11 @@ inline vec4f contrast(vec4f rgb, float contrast) { return {yocto::contrast(xyz(rgb), contrast), rgb.w}; } // Apply saturation. -inline vec3f saturate( - vec3f rgb, float saturation, vec3f weights) { +inline vec3f saturate(vec3f rgb, float saturation, vec3f weights) { auto grey = dot(weights, rgb); return max({0, 0, 0}, grey + (rgb - grey) * (saturation * 2)); } -inline vec4f saturate( - vec4f rgb, float saturation, vec3f weights) { +inline vec4f saturate(vec4f rgb, float saturation, vec3f weights) { return {saturate(xyz(rgb), saturation, weights), rgb.w}; } @@ -638,8 +632,7 @@ struct color_space_params { // Input: red, green, blue, white (x,y) chromoticities // Algorithm from: SMPTE Recommended Practice RP 177-1993 // http://car.france3.mars.free.fr/HD/INA-%2026%20jan%2006/SMPTE%20normes%20et%20confs/rp177.pdf -inline mat3f rgb_to_xyz_mat( - vec2f rc, vec2f gc, vec2f bc, vec2f wc) { +inline mat3f rgb_to_xyz_mat(vec2f rc, vec2f gc, vec2f bc, vec2f wc) { auto rgb = mat3f{ {rc.x, rc.y, 1 - rc.x - rc.y}, {gc.x, gc.y, 1 - gc.x - gc.y}, @@ -652,28 +645,26 @@ inline mat3f rgb_to_xyz_mat( // Construct an RGB color space. Predefined color spaces below inline color_space_params get_color_scape_params(color_space space) { - static auto make_linear_rgb_space = [](vec2f red, vec2f green, - vec2f blue, + static auto make_linear_rgb_space = [](vec2f red, vec2f green, vec2f blue, vec2f white) { return color_space_params{red, green, blue, white, rgb_to_xyz_mat(red, green, blue, white), inverse(rgb_to_xyz_mat(red, green, blue, white)), color_space_params::curve_t::linear}; }; - static auto make_gamma_rgb_space = - [](vec2f red, vec2f green, vec2f blue, - vec2f white, float gamma, - vec4f curve_abcd = vec4f{0, 0, 0, 0}) { - return color_space_params{red, green, blue, white, - rgb_to_xyz_mat(red, green, blue, white), - inverse(rgb_to_xyz_mat(red, green, blue, white)), - curve_abcd == vec4f{0, 0, 0, 0} - ? color_space_params::curve_t::gamma - : color_space_params::curve_t::linear_gamma}; - }; + static auto make_gamma_rgb_space = [](vec2f red, vec2f green, vec2f blue, + vec2f white, float gamma, + vec4f curve_abcd = vec4f{0, 0, 0, 0}) { + return color_space_params{red, green, blue, white, + rgb_to_xyz_mat(red, green, blue, white), + inverse(rgb_to_xyz_mat(red, green, blue, white)), + curve_abcd == vec4f{0, 0, 0, 0} + ? color_space_params::curve_t::gamma + : color_space_params::curve_t::linear_gamma}; + }; static auto make_other_rgb_space = - [](vec2f red, vec2f green, vec2f blue, - vec2f white, color_space_params::curve_t curve_type) { + [](vec2f red, vec2f green, vec2f blue, vec2f white, + color_space_params::curve_t curve_type) { return color_space_params{red, green, blue, white, rgb_to_xyz_mat(red, green, blue, white), inverse(rgb_to_xyz_mat(red, green, blue, white)), curve_type}; diff --git a/libs/yocto/yocto_diagram.cpp b/libs/yocto/yocto_diagram.cpp index b11df2500..537b3aade 100644 --- a/libs/yocto/yocto_diagram.cpp +++ b/libs/yocto/yocto_diagram.cpp @@ -81,8 +81,7 @@ static void merge_dshape_inplace(shape_data& shape, const shape_data& merge) { } // Make a tesselated rectangle. Useful in other subdivisions. -static shape_data make_dquads( - vec2i steps, vec2f scale, vec2f uvscale) { +static shape_data make_dquads(vec2i steps, vec2f scale, vec2f uvscale) { auto shape = shape_data{}; shape.positions.resize((steps.x + 1) * (steps.y + 1)); @@ -111,8 +110,7 @@ static shape_data make_dquads( } // Make a rect -static shape_data make_drect( - vec2i steps, vec2f scale, vec2f uvscale = {1, 1}) { +static shape_data make_drect(vec2i steps, vec2f scale, vec2f uvscale = {1, 1}) { return make_dquads(steps, scale, uvscale); } @@ -420,8 +418,8 @@ static void update_offsets(diagram_data& diagram) { } // Scene -diagram_scene& add_scene(diagram_data& diagram, const string& title, - vec2f size, const frame3f& frame, vec2f margin) { +diagram_scene& add_scene(diagram_data& diagram, const string& title, vec2f size, + const frame3f& frame, vec2f margin) { return add_scenews(diagram, title, "", size, frame, margin); } diagram_scene& add_scene(diagram_data& diagram, const string& title, @@ -429,8 +427,7 @@ diagram_scene& add_scene(diagram_data& diagram, const string& title, return add_scenews(diagram, title, "", {2, 2}, frame, margin); } diagram_scene& add_scenews(diagram_data& diagram, const string& title, - const string& subtitle, vec2f size, const frame3f& frame, - vec2f margin) { + const string& subtitle, vec2f size, const frame3f& frame, vec2f margin) { auto& scene = diagram.scenes.emplace_back(); scene.size = size; scene.margin = margin; @@ -877,8 +874,7 @@ diagram_shape dhalfdisk(int steps) { } // Add arc -diagram_shape darc( - vec3f from, vec3f to, vec3f center, int steps) { +diagram_shape darc(vec3f from, vec3f to, vec3f center, int steps) { // refence frame auto x = normalize(from - center); auto y = normalize(to - center); @@ -1206,8 +1202,7 @@ diagram_shape dudiskgrid(vec2i steps, int dsteps) { } // Add affine grid -diagram_shape daffinegrid( - vec3f axes_a, vec3f axes_b, vec2i steps) { +diagram_shape daffinegrid(vec3f axes_a, vec3f axes_b, vec2i steps) { auto ratio = (float)steps.x / (float)steps.y; auto shape_ = make_drect({steps.x, steps.y}, {ratio, 1}); auto positions_ = shape_.positions; @@ -1430,8 +1425,8 @@ diagram_shape drandomlines(drandomlines_type type, int num, bool stratified) { } // Add plot -diagram_scene& add_plot(diagram_data& diagram, const string& title, - vec2f size, const frame3f& frame, vec2f margin) { +diagram_scene& add_plot(diagram_data& diagram, const string& title, vec2f size, + const frame3f& frame, vec2f margin) { return add_scene(diagram, title, size, frame, margin); } @@ -1546,8 +1541,8 @@ vector dplotcurve(const vector& curve, vec2f range) { } // Add plot -diagram_scene& add_plot3(diagram_data& diagram, const string& title, - vec2f size, const frame3f& frame, vec2f margin) { +diagram_scene& add_plot3(diagram_data& diagram, const string& title, vec2f size, + const frame3f& frame, vec2f margin) { return add_scene(diagram, title, size, frame, margin); } @@ -1612,9 +1607,8 @@ diagram_scene& add_plotaxes3(diagram_scene& diagram, const bbox3f& bounds, } // Plot surface -diagram_shape dplotsurface(const function& func, - vec2f xrange, vec2f yrange, vec2i steps, - bool isolines) { +diagram_shape dplotsurface(const function& func, vec2f xrange, + vec2f yrange, vec2i steps, bool isolines) { auto shape = diagram_shape{}; // steps @@ -2171,8 +2165,8 @@ image_t render_diagram(const diagram_data& diagram, int resolution, auto render = render_image(yscene, resolution, samples, false); // helpers - auto draw_quad = [](image_t& composite, vec2i center, - vec2i size, vec4f color) { + auto draw_quad = [](image_t& composite, vec2i center, vec2i size, + vec4f color) { auto extents = composite.size(); for (auto i : range(-size.x / 2, +size.x / 2)) { composite[clamp( @@ -2188,8 +2182,7 @@ image_t render_diagram(const diagram_data& diagram, int resolution, } }; auto copy_quad = [](image_t& composite, const image_t& source, - vec2i icenter, vec2i scenter, - vec2i size) { + vec2i icenter, vec2i scenter, vec2i size) { auto csize = composite.size(); auto ssize = source.size(); for (auto j : range(-size.y / 2, +size.y / 2)) { diff --git a/libs/yocto/yocto_diagram.h b/libs/yocto/yocto_diagram.h index 60e9c6866..42c2e7665 100644 --- a/libs/yocto/yocto_diagram.h +++ b/libs/yocto/yocto_diagram.h @@ -313,15 +313,13 @@ inline frame3f dscale(float scale) { inline frame3f dframez(vec3f z, vec3f pos = {0, 0, 0}) { return frame_fromz(pos, z); } -inline frame3f dlookat(vec3f from, vec3f to = {0, 0, 0}, - vec3f up = {0, 1, 0}) { +inline frame3f dlookat(vec3f from, vec3f to = {0, 0, 0}, vec3f up = {0, 1, 0}) { return lookat_frame(from, to, up, true); } inline frame3f dtransform(vec3f translation, vec3f rotation) { return dtranslation(translation) * drotation(rotation); } -inline frame3f dgtransform( - vec3f translation, vec3f rotation, vec3f scaling) { +inline frame3f dgtransform(vec3f translation, vec3f rotation, vec3f scaling) { return dtranslation(translation) * drotation(rotation) * dscaling(scaling); } inline frame3f dreflectx() { @@ -355,30 +353,27 @@ inline diagram_shape transform_shape( } // Styles -inline diagram_style dstroke(vec4f stroke = dcolors::black, - float thickness = dthickness::default_) { +inline diagram_style dstroke( + vec4f stroke = dcolors::black, float thickness = dthickness::default_) { return { .stroke = stroke, .fill = dcolors::transparent, .thickness = thickness}; } inline diagram_style dfill(vec4f fill = dcolors::fill1) { return {.stroke = dcolors::transparent, .fill = fill}; } -inline diagram_style dfilled(vec4f fill = dcolors::fill1, - vec4f stroke = dcolors::black, - float thickness = dthickness::default_) { +inline diagram_style dfilled(vec4f fill = dcolors::fill1, + vec4f stroke = dcolors::black, float thickness = dthickness::default_) { return {.stroke = stroke, .fill = fill, .thickness = thickness}; } inline diagram_style dtextured(const image_t& texture, - vec4f stroke = dcolors::black, - float thickness = dthickness::default_) { + vec4f stroke = dcolors::black, float thickness = dthickness::default_) { return {.stroke = stroke, .fill = {1, 1, 1, 1}, .thickness = thickness, .texture = texture}; } inline diagram_style dtextured(const image_t& texture, bool interpolate, - vec4f stroke = dcolors::black, - float thickness = dthickness::default_) { + vec4f stroke = dcolors::black, float thickness = dthickness::default_) { return {.stroke = stroke, .fill = {1, 1, 1, 1}, .thickness = thickness, @@ -387,7 +382,7 @@ inline diagram_style dtextured(const image_t& texture, bool interpolate, } inline diagram_style dimtextured(const image_t& texture, vec4f stroke = dcolors::transparent, - float thickness = dthickness::default_) { + float thickness = dthickness::default_) { return { .stroke = stroke, .fill = {1, 1, 1, 1}, @@ -424,9 +419,8 @@ namespace yocto { // Add scene diagram_scene& add_scene(diagram_data& diagram, const string& title, const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0}); -diagram_scene& add_scene(diagram_data& diagram, const string& title, - vec2f size, const frame3f& frame = identity3x4f, - vec2f margin = {0.2, 1.0}); +diagram_scene& add_scene(diagram_data& diagram, const string& title, vec2f size, + const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0}); diagram_scene& add_scenews(diagram_data& diagram, const string& title, const string& subtitle, vec2f size = {2, 2}, const frame3f& frame = identity3x4f, vec2f margin = {0.2, 1.0}); @@ -531,8 +525,8 @@ diagram_shape ddisk(int steps = 64); diagram_shape dhalfdisk(int steps = 32); // Arc -diagram_shape darc(vec3f from, vec3f to, - vec3f center = {0, 0, 0}, int steps = 16); +diagram_shape darc( + vec3f from, vec3f to, vec3f center = {0, 0, 0}, int steps = 16); // Qbezier diagram_shape dqbeziers(const vector& positions, int steps = 32); @@ -577,8 +571,8 @@ diagram_shape ddiskgrid(vec2i steps = {4, 4}, int dstep = 32); diagram_shape dudiskgrid(vec2i steps = {4, 4}, int dstep = 32); // Affine grid -diagram_shape daffinegrid(vec3f axes_a = {1, 0, 0}, - vec3f axes_b = {0, 1, 0}, vec2i steps = {4, 4}); +diagram_shape daffinegrid( + vec3f axes_a = {1, 0, 0}, vec3f axes_b = {0, 1, 0}, vec2i steps = {4, 4}); // Image diagram_shape dimagerect(vec2i size); @@ -666,25 +660,24 @@ diagram_scene& add_plot3(diagram_data& diagram, vec2f size = {4, 3}, drotation({270, 0, 0}) * drotation({0, 0, 180}), vec2f margin = {0.8, 1.0}); diagram_scene& add_plot3(diagram_data& diagram, const string& title, - vec2f size = {4, 3}, + vec2f size = {4, 3}, const frame3f& frame = drotation({25, 0, 0}) * drotation({0, 45, 0}) * drotation({270, 0, 0}) * drotation({0, 0, 180}), vec2f margin = {0.8, 1.0}); // Add plot axes diagram_scene& add_plotaxes3(diagram_scene& diagram, - const bbox3f& bounds = {{0, 0, 0}, {1, 1, 1}}, - vec3f size = {1, 1, 1}, - const vector>& xticks = {}, - const vector>& yticks = {}, - const vector>& zticks = {}, - const diagram_style& style = dstroke(), - const diagram_style& lstyle = dstroke(dcolors::transparent)); + const bbox3f& bounds = {{0, 0, 0}, {1, 1, 1}}, vec3f size = {1, 1, 1}, + const vector>& xticks = {}, + const vector>& yticks = {}, + const vector>& zticks = {}, + const diagram_style& style = dstroke(), + const diagram_style& lstyle = dstroke(dcolors::transparent)); // Plot surface diagram_shape dplotsurface(const function& func, - vec2f xrange = {0, 1}, vec2f yrange = {0, 1}, - vec2i steps = {64, 64}, bool wireframe = true); + vec2f xrange = {0, 1}, vec2f yrange = {0, 1}, vec2i steps = {64, 64}, + bool wireframe = true); // Helpers to clip lines diagram_shape clip_lines(const diagram_shape& shape, const bbox3f& bbox); diff --git a/libs/yocto/yocto_geometry.h b/libs/yocto/yocto_geometry.h index 0f4134c5b..bde3bd63f 100644 --- a/libs/yocto/yocto_geometry.h +++ b/libs/yocto/yocto_geometry.h @@ -73,7 +73,7 @@ struct bbox2f { constexpr bbox2f(vec2f min, vec2f max) : min{min}, max{max} {} inline vec2f& operator[](int i); - inline vec2f operator[](int i) const; + inline const vec2f& operator[](int i) const; }; // Axis aligned bounding box represented as a min/max vector pairs. @@ -86,7 +86,7 @@ struct bbox3f { constexpr bbox3f(vec3f min, vec3f max) : min{min}, max{max} {} inline vec3f& operator[](int i); - inline vec3f operator[](int i) const; + inline const vec3f& operator[](int i) const; }; // Empty bbox constant. @@ -146,8 +146,8 @@ struct ray2f { float tmax = flt_max; constexpr ray2f() : o{0, 0}, d{0, 1}, tmin{ray_eps}, tmax{flt_max} {} - constexpr ray2f(vec2f o_, vec2f d_, float tmin_ = ray_eps, - float tmax_ = flt_max) + constexpr ray2f( + vec2f o_, vec2f d_, float tmin_ = ray_eps, float tmax_ = flt_max) : o{o_}, d{d_}, tmin{tmin_}, tmax{tmax_} {} }; @@ -159,8 +159,8 @@ struct ray3f { float tmax = flt_max; constexpr ray3f() : o{0, 0, 0}, d{0, 0, 1}, tmin{ray_eps}, tmax{flt_max} {} - constexpr ray3f(vec3f o_, vec3f d_, float tmin_ = ray_eps, - float tmax_ = flt_max) + constexpr ray3f( + vec3f o_, vec3f d_, float tmin_ = ray_eps, float tmax_ = flt_max) : o{o_}, d{d_}, tmin{tmin_}, tmax{tmax_} {} }; @@ -195,13 +195,10 @@ inline bbox3f point_bounds(vec3f p); inline bbox3f point_bounds(vec3f p, float r); inline bbox3f line_bounds(vec3f p0, vec3f p1); inline bbox3f line_bounds(vec3f p0, vec3f p1, float r0, float r1); -inline bbox3f triangle_bounds( - vec3f p0, vec3f p1, vec3f p2); -inline bbox3f quad_bounds( - vec3f p0, vec3f p1, vec3f p2, vec3f p3); +inline bbox3f triangle_bounds(vec3f p0, vec3f p1, vec3f p2); +inline bbox3f quad_bounds(vec3f p0, vec3f p1, vec3f p2, vec3f p3); inline bbox3f sphere_bounds(vec3f p, float r); -inline bbox3f capsule_bounds( - vec3f p0, vec3f p1, float r0, float r1); +inline bbox3f capsule_bounds(vec3f p0, vec3f p1, float r0, float r1); } // namespace yocto @@ -219,10 +216,8 @@ inline vec3f triangle_normal(vec3f p0, vec3f p1, vec3f p2); inline float triangle_area(vec3f p0, vec3f p1, vec3f p2); // Quad properties. -inline vec3f quad_normal( - vec3f p0, vec3f p1, vec3f p2, vec3f p3); -inline float quad_area( - vec3f p0, vec3f p1, vec3f p2, vec3f p3); +inline vec3f quad_normal(vec3f p0, vec3f p1, vec3f p2, vec3f p3); +inline float quad_area(vec3f p0, vec3f p1, vec3f p2, vec3f p3); // Interpolates values over a line parameterized from a to b by u. Same as lerp. template @@ -231,8 +226,7 @@ inline T interpolate_line(const T& p0, const T& p1, float u); // Interpolates values over a triangle parameterized by u and v along the // (p1-p0) and (p2-p0) directions. Same as barycentric interpolation. template -inline T interpolate_triangle( - const T& p0, const T& p1, const T& p2, vec2f uv); +inline T interpolate_triangle(const T& p0, const T& p1, const T& p2, vec2f uv); // Interpolates values over a quad parameterized by u and v along the // (p1-p0) and (p2-p1) directions. Same as bilinear interpolation. @@ -255,32 +249,26 @@ inline vec3f line_point(vec3f p0, vec3f p1, float u); inline vec3f line_tangent(vec3f t0, vec3f t1, float u); // Interpolated triangle properties. -inline vec3f triangle_point( - vec3f p0, vec3f p1, vec3f p2, vec2f uv); -inline vec3f triangle_normal( - vec3f n0, vec3f n1, vec3f n2, vec2f uv); +inline vec3f triangle_point(vec3f p0, vec3f p1, vec3f p2, vec2f uv); +inline vec3f triangle_normal(vec3f n0, vec3f n1, vec3f n2, vec2f uv); // Interpolated quad properties. -inline vec3f quad_point( - vec3f p0, vec3f p1, vec3f p2, vec2f uv); -inline vec3f quad_normal(vec3f n0, vec3f n1, vec3f n2, - vec3f n3, vec2f uv); +inline vec3f quad_point(vec3f p0, vec3f p1, vec3f p2, vec2f uv); +inline vec3f quad_normal(vec3f n0, vec3f n1, vec3f n2, vec3f n3, vec2f uv); // Interpolated sphere properties. inline vec3f sphere_point(const vec3f p, float r, vec2f uv); inline vec3f sphere_normal(const vec3f p, float r, vec2f uv); // Triangle tangent and bitangent from uv -inline pair triangle_tangents_fromuv(vec3f p0, - vec3f p1, vec3f p2, vec2f uv0, vec2f uv1, - vec2f uv2); +inline pair triangle_tangents_fromuv( + vec3f p0, vec3f p1, vec3f p2, vec2f uv0, vec2f uv1, vec2f uv2); // Quad tangent and bitangent from uv. Note that we pass a current_uv since // internally we may want to split the quad in two and we need to known where // to do it. If not interested in the split, just pass vec2f{0,0} here. -inline pair quad_tangents_fromuv(vec3f p0, vec3f p1, - vec3f p2, vec3f p3, vec2f uv0, vec2f uv1, - vec2f uv2, vec2f uv3, vec2f current_uv); +inline pair quad_tangents_fromuv(vec3f p0, vec3f p1, vec3f p2, + vec3f p3, vec2f uv0, vec2f uv1, vec2f uv2, vec2f uv3, vec2f current_uv); } // namespace yocto @@ -294,8 +282,8 @@ inline ray3f camera_ray( const frame3f& frame, float lens, vec2f film, vec2f image_uv); // Generate a ray from a camera -inline ray3f camera_ray(const frame3f& frame, float lens, float aspect, - float film, vec2f image_uv); +inline ray3f camera_ray( + const frame3f& frame, float lens, float aspect, float film, vec2f image_uv); } // namespace yocto @@ -312,8 +300,7 @@ struct prim_intersection { }; // Intersect a ray with a point (approximate) -inline prim_intersection intersect_point( - const ray3f& ray, vec3f p, float r); +inline prim_intersection intersect_point(const ray3f& ray, vec3f p, float r); // Intersect a ray with a line inline prim_intersection intersect_line( @@ -324,12 +311,11 @@ inline prim_intersection intersect_triangle( const ray3f& ray, vec3f p0, vec3f p1, vec3f p2); // Intersect a ray with a quad. -inline prim_intersection intersect_quad(const ray3f& ray, vec3f p0, - vec3f p1, vec3f p2, vec3f p3); +inline prim_intersection intersect_quad( + const ray3f& ray, vec3f p0, vec3f p1, vec3f p2, vec3f p3); // Intersect a ray with a sphere -inline prim_intersection intersect_sphere( - const ray3f& ray, vec3f p, float r); +inline prim_intersection intersect_sphere(const ray3f& ray, vec3f p, float r); // Intersect a ray with a axis-aligned bounding box inline bool intersect_bbox(const ray3f& ray, const bbox3f& bbox); @@ -353,23 +339,20 @@ inline prim_intersection overlap_point( inline float closestuv_line(vec3f pos, vec3f p0, vec3f p1); // Check if a line overlaps a position pos withint a maximum distance dist_max. -inline prim_intersection overlap_line(vec3f pos, float dist_max, - vec3f p0, vec3f p1, float r0, float r1); +inline prim_intersection overlap_line( + vec3f pos, float dist_max, vec3f p0, vec3f p1, float r0, float r1); // Compute the closest triangle uv to a give position pos. -inline vec2f closestuv_triangle( - vec3f pos, vec3f p0, vec3f p1, vec3f p2); +inline vec2f closestuv_triangle(vec3f pos, vec3f p0, vec3f p1, vec3f p2); // Check if a triangle overlaps a position pos withint a maximum distance // dist_max. -inline prim_intersection overlap_triangle(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, float r0, float r1, - float r2); +inline prim_intersection overlap_triangle(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, float r0, float r1, float r2); // Check if a quad overlaps a position pos withint a maximum distance dist_max. -inline prim_intersection overlap_quad(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, vec3f p3, - float r0, float r1, float r2, float r3); +inline prim_intersection overlap_quad(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, vec3f p3, float r0, float r1, float r2, float r3); // Check if a bbox overlaps a position pos withint a maximum distance dist_max. inline bool overlap_bbox(vec3f pos, float dist_max, const bbox3f& bbox); @@ -394,11 +377,11 @@ namespace yocto { // Axis aligned bounding box represented as a min/max vector pairs. inline vec2f& bbox2f::operator[](int i) { return (&min)[i]; } -inline vec2f bbox2f::operator[](int i) const { return (&min)[i]; } +inline const vec2f& bbox2f::operator[](int i) const { return (&min)[i]; } // Axis aligned bounding box represented as a min/max vector pairs. inline vec3f& bbox3f::operator[](int i) { return (&min)[i]; } -inline vec3f bbox3f::operator[](int i) const { return (&min)[i]; } +inline const vec3f& bbox3f::operator[](int i) const { return (&min)[i]; } // Bounding box properties inline vec2f center(const bbox2f& a) { return (a.min + a.max) / 2; } @@ -524,21 +507,17 @@ inline bbox3f point_bounds(vec3f p, float r) { inline bbox3f line_bounds(vec3f p0, vec3f p1) { return {min(p0, p1), max(p0, p1)}; } -inline bbox3f line_bounds( - vec3f p0, vec3f p1, float r0, float r1) { +inline bbox3f line_bounds(vec3f p0, vec3f p1, float r0, float r1) { return {min(p0 - r0, p1 - r1), max(p0 + r0, p1 + r1)}; } -inline bbox3f triangle_bounds( - vec3f p0, vec3f p1, vec3f p2) { +inline bbox3f triangle_bounds(vec3f p0, vec3f p1, vec3f p2) { return {min(p0, min(p1, p2)), max(p0, max(p1, p2))}; } -inline bbox3f quad_bounds( - vec3f p0, vec3f p1, vec3f p2, vec3f p3) { +inline bbox3f quad_bounds(vec3f p0, vec3f p1, vec3f p2, vec3f p3) { return {min(p0, min(p1, min(p2, p3))), max(p0, max(p1, max(p2, p3)))}; } inline bbox3f sphere_bounds(vec3f p, float r) { return {p - r, p + r}; } -inline bbox3f capsule_bounds( - vec3f p0, vec3f p1, float r0, float r1) { +inline bbox3f capsule_bounds(vec3f p0, vec3f p1, float r0, float r1) { return {min(p0 - r0, p1 - r1), max(p0 + r0, p1 + r1)}; } @@ -550,16 +529,11 @@ inline bbox3f capsule_bounds( namespace yocto { // Line properties. -inline vec3f line_tangent(vec3f p0, vec3f p1) { - return normalize(p1 - p0); -} -inline float line_length(vec3f p0, vec3f p1) { - return length(p1 - p0); -} +inline vec3f line_tangent(vec3f p0, vec3f p1) { return normalize(p1 - p0); } +inline float line_length(vec3f p0, vec3f p1) { return length(p1 - p0); } // Triangle properties. -inline vec3f triangle_normal( - vec3f p0, vec3f p1, vec3f p2) { +inline vec3f triangle_normal(vec3f p0, vec3f p1, vec3f p2) { return normalize(cross(p1 - p0, p2 - p0)); } inline float triangle_area(vec3f p0, vec3f p1, vec3f p2) { @@ -567,12 +541,10 @@ inline float triangle_area(vec3f p0, vec3f p1, vec3f p2) { } // Quad propeties. -inline vec3f quad_normal( - vec3f p0, vec3f p1, vec3f p2, vec3f p3) { +inline vec3f quad_normal(vec3f p0, vec3f p1, vec3f p2, vec3f p3) { return normalize(triangle_normal(p0, p1, p3) + triangle_normal(p2, p3, p1)); } -inline float quad_area( - vec3f p0, vec3f p1, vec3f p2, vec3f p3) { +inline float quad_area(vec3f p0, vec3f p1, vec3f p2, vec3f p3) { return triangle_area(p0, p1, p3) + triangle_area(p2, p3, p1); } @@ -585,8 +557,7 @@ inline T interpolate_line(const T& p0, const T& p1, float u) { // Interpolates values over a triangle parameterized by u and v along the // (p1-p0) and (p2-p0) directions. Same as barycentric interpolation. template -inline T interpolate_triangle( - const T& p0, const T& p1, const T& p2, vec2f uv) { +inline T interpolate_triangle(const T& p0, const T& p1, const T& p2, vec2f uv) { return p0 * (1 - uv.x - uv.y) + p1 * uv.x + p2 * uv.y; } @@ -626,26 +597,22 @@ inline vec3f line_tangent(vec3f t0, vec3f t1, float u) { } // Interpolated triangle properties. -inline vec3f triangle_point( - vec3f p0, vec3f p1, vec3f p2, vec2f uv) { +inline vec3f triangle_point(vec3f p0, vec3f p1, vec3f p2, vec2f uv) { return p0 * (1 - uv.x - uv.y) + p1 * uv.x + p2 * uv.y; } -inline vec3f triangle_normal( - vec3f n0, vec3f n1, vec3f n2, vec2f uv) { +inline vec3f triangle_normal(vec3f n0, vec3f n1, vec3f n2, vec2f uv) { return normalize(n0 * (1 - uv.x - uv.y) + n1 * uv.x + n2 * uv.y); } // Interpolated quad properties. -inline vec3f quad_point(vec3f p0, vec3f p1, vec3f p2, - vec3f p3, vec2f uv) { +inline vec3f quad_point(vec3f p0, vec3f p1, vec3f p2, vec3f p3, vec2f uv) { if (uv.x + uv.y <= 1) { return triangle_point(p0, p1, p3, uv); } else { return triangle_point(p2, p3, p1, 1 - uv); } } -inline vec3f quad_normal(vec3f n0, vec3f n1, vec3f n2, - vec3f n3, vec2f uv) { +inline vec3f quad_normal(vec3f n0, vec3f n1, vec3f n2, vec3f n3, vec2f uv) { if (uv.x + uv.y <= 1) { return triangle_normal(n0, n1, n3, uv); } else { @@ -664,9 +631,8 @@ inline vec3f sphere_normal(const vec3f p, float r, vec2f uv) { } // Triangle tangent and bitangent from uv -inline pair triangle_tangents_fromuv(vec3f p0, - vec3f p1, vec3f p2, vec2f uv0, vec2f uv1, - vec2f uv2) { +inline pair triangle_tangents_fromuv( + vec3f p0, vec3f p1, vec3f p2, vec2f uv0, vec2f uv1, vec2f uv2) { // Follows the definition in http://www.terathon.com/code/tangent.html and // https://gist.github.com/aras-p/2843984 // normal points up from texture space @@ -690,9 +656,8 @@ inline pair triangle_tangents_fromuv(vec3f p0, } // Quad tangent and bitangent from uv. -inline pair quad_tangents_fromuv(vec3f p0, vec3f p1, - vec3f p2, vec3f p3, vec2f uv0, vec2f uv1, - vec2f uv2, vec2f uv3, vec2f current_uv) { +inline pair quad_tangents_fromuv(vec3f p0, vec3f p1, vec3f p2, + vec3f p3, vec2f uv0, vec2f uv1, vec2f uv2, vec2f uv3, vec2f current_uv) { if (current_uv.x + current_uv.y <= 1) { return triangle_tangents_fromuv(p0, p1, p3, uv0, uv1, uv3); } else { @@ -708,8 +673,8 @@ inline pair quad_tangents_fromuv(vec3f p0, vec3f p1, namespace yocto { // Generate a ray from a camera -inline ray3f camera_ray(const frame3f& frame, float lens, vec2f film, - vec2f image_uv) { +inline ray3f camera_ray( + const frame3f& frame, float lens, vec2f film, vec2f image_uv) { auto e = vec3f{0, 0, 0}; auto q = vec3f{ film.x * (0.5f - image_uv.x), film.y * (image_uv.y - 0.5f), lens}; @@ -741,8 +706,7 @@ inline ray3f camera_ray(const frame3f& frame, float lens, float aspect, namespace yocto { // Intersect a ray with a point (approximate) -inline prim_intersection intersect_point( - const ray3f& ray, vec3f p, float r) { +inline prim_intersection intersect_point(const ray3f& ray, vec3f p, float r) { // find parameter for line-point minimum distance auto w = p - ray.o; auto t = dot(w, ray.d) / dot(ray.d, ray.d); @@ -838,8 +802,8 @@ inline prim_intersection intersect_triangle( } // Intersect a ray with a quad. -inline prim_intersection intersect_quad(const ray3f& ray, vec3f p0, - vec3f p1, vec3f p2, vec3f p3) { +inline prim_intersection intersect_quad( + const ray3f& ray, vec3f p0, vec3f p1, vec3f p2, vec3f p3) { if (p2 == p3) return intersect_triangle(ray, p0, p1, p3); auto isec1 = intersect_triangle(ray, p0, p1, p3); auto isec2 = intersect_triangle(ray, p2, p3, p1); @@ -848,8 +812,7 @@ inline prim_intersection intersect_quad(const ray3f& ray, vec3f p0, } // Intersect a ray with a sphere -inline prim_intersection intersect_sphere( - const ray3f& ray, vec3f p, float r) { +inline prim_intersection intersect_sphere(const ray3f& ray, vec3f p, float r) { // compute parameters auto a = dot(ray.d, ray.d); auto b = 2 * dot(ray.o - p, ray.d); @@ -923,8 +886,7 @@ inline prim_intersection overlap_point( } // Compute the closest line uv to a give position pos. -inline float closestuv_line( - vec3f pos, vec3f p0, vec3f p1) { +inline float closestuv_line(vec3f pos, vec3f p0, vec3f p1) { auto ab = p1 - p0; auto d = dot(ab, ab); // Project c onto ab, computing parameterized position d(t) = a + t*(b – @@ -935,8 +897,8 @@ inline float closestuv_line( } // Check if a line overlaps a position pos withint a maximum distance dist_max. -inline prim_intersection overlap_line(vec3f pos, float dist_max, - vec3f p0, vec3f p1, float r0, float r1) { +inline prim_intersection overlap_line( + vec3f pos, float dist_max, vec3f p0, vec3f p1, float r0, float r1) { auto u = closestuv_line(pos, p0, p1); // Compute projected position from the clamped t d = a + t * ab; auto p = p0 + (p1 - p0) * u; @@ -949,8 +911,7 @@ inline prim_intersection overlap_line(vec3f pos, float dist_max, } // Compute the closest triangle uv to a give position pos. -inline vec2f closestuv_triangle( - vec3f pos, vec3f p0, vec3f p1, vec3f p2) { +inline vec2f closestuv_triangle(vec3f pos, vec3f p0, vec3f p1, vec3f p2) { // this is a complicated test -> I probably "--"+prefix to use a sequence of // test (triangle body, and 3 edges) auto ab = p1 - p0; @@ -994,9 +955,8 @@ inline vec2f closestuv_triangle( // Check if a triangle overlaps a position pos withint a maximum distance // dist_max. -inline prim_intersection overlap_triangle(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, float r0, float r1, - float r2) { +inline prim_intersection overlap_triangle(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, float r0, float r1, float r2) { auto cuv = closestuv_triangle(pos, p0, p1, p2); auto p = p0 * (1 - cuv.x - cuv.y) + p1 * cuv.x + p2 * cuv.y; auto r = r0 * (1 - cuv.x - cuv.y) + r1 * cuv.x + r2 * cuv.y; @@ -1006,9 +966,8 @@ inline prim_intersection overlap_triangle(vec3f pos, float dist_max, } // Check if a quad overlaps a position pos withint a maximum distance dist_max. -inline prim_intersection overlap_quad(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, vec3f p3, - float r0, float r1, float r2, float r3) { +inline prim_intersection overlap_quad(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, vec3f p3, float r0, float r1, float r2, float r3) { if (p2 == p3) return overlap_triangle(pos, dist_max, p0, p1, p3, r0, r1, r2); auto isec1 = overlap_triangle(pos, dist_max, p0, p1, p3, r0, r1, r2); auto isec2 = overlap_triangle(pos, dist_max, p2, p3, p1, r2, r3, r1); @@ -1059,8 +1018,8 @@ namespace yocto { } // Intersect a ray with a line -[[deprecated]] inline bool intersect_line(const ray3f& ray, vec3f p0, - vec3f p1, float r0, float r1, vec2f& uv, float& dist) { +[[deprecated]] inline bool intersect_line(const ray3f& ray, vec3f p0, vec3f p1, + float r0, float r1, vec2f& uv, float& dist) { auto intersection = intersect_line(ray, p0, p1, r0, r1); if (!intersection.hit) return false; uv = intersection.uv; @@ -1079,8 +1038,8 @@ namespace yocto { } // Intersect a ray with a triangle -[[deprecated]] inline bool intersect_triangle(const ray3f& ray, vec3f p0, - vec3f p1, vec3f p2, vec2f& uv, float& dist) { +[[deprecated]] inline bool intersect_triangle( + const ray3f& ray, vec3f p0, vec3f p1, vec3f p2, vec2f& uv, float& dist) { auto intersection = intersect_triangle(ray, p0, p1, p2); if (!intersection.hit) return false; uv = intersection.uv; @@ -1089,8 +1048,8 @@ namespace yocto { } // Intersect a ray with a quad. -[[deprecated]] inline bool intersect_quad(const ray3f& ray, vec3f p0, - vec3f p1, vec3f p2, vec3f p3, vec2f& uv, float& dist) { +[[deprecated]] inline bool intersect_quad(const ray3f& ray, vec3f p0, vec3f p1, + vec3f p2, vec3f p3, vec2f& uv, float& dist) { auto intersection = intersect_quad(ray, p0, p1, p2, p3); if (!intersection.hit) return false; uv = intersection.uv; @@ -1099,8 +1058,8 @@ namespace yocto { } // Check if a point overlaps a position pos withint a maximum distance dist_max. -[[deprecated]] inline bool overlap_point(vec3f pos, float dist_max, - vec3f p, float r, vec2f& uv, float& dist) { +[[deprecated]] inline bool overlap_point( + vec3f pos, float dist_max, vec3f p, float r, vec2f& uv, float& dist) { auto intersection = overlap_point(pos, dist_max, p, r); if (!intersection.hit) return false; uv = intersection.uv; @@ -1109,9 +1068,8 @@ namespace yocto { } // Check if a line overlaps a position pos withint a maximum distance dist_max. -[[deprecated]] inline bool overlap_line(vec3f pos, float dist_max, - vec3f p0, vec3f p1, float r0, float r1, vec2f& uv, - float& dist) { +[[deprecated]] inline bool overlap_line(vec3f pos, float dist_max, vec3f p0, + vec3f p1, float r0, float r1, vec2f& uv, float& dist) { auto intersection = overlap_line(pos, dist_max, p0, p1, r0, r1); if (!intersection.hit) return false; uv = intersection.uv; @@ -1121,9 +1079,8 @@ namespace yocto { // Check if a triangle overlaps a position pos withint a maximum distance // dist_max. -[[deprecated]] inline bool overlap_triangle(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, float r0, float r1, - float r2, vec2f& uv, float& dist) { +[[deprecated]] inline bool overlap_triangle(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, float r0, float r1, float r2, vec2f& uv, float& dist) { auto intersection = overlap_triangle(pos, dist_max, p0, p1, p2, r0, r1, r2); if (!intersection.hit) return false; uv = intersection.uv; @@ -1132,9 +1089,9 @@ namespace yocto { } // Check if a quad overlaps a position pos withint a maximum distance dist_max. -[[deprecated]] inline bool overlap_quad(vec3f pos, float dist_max, - vec3f p0, vec3f p1, vec3f p2, vec3f p3, - float r0, float r1, float r2, float r3, vec2f& uv, float& dist) { +[[deprecated]] inline bool overlap_quad(vec3f pos, float dist_max, vec3f p0, + vec3f p1, vec3f p2, vec3f p3, float r0, float r1, float r2, float r3, + vec2f& uv, float& dist) { auto intersection = overlap_quad( pos, dist_max, p0, p1, p2, p3, r0, r1, r2, r3); if (!intersection.hit) return false; diff --git a/libs/yocto/yocto_gui.cpp b/libs/yocto/yocto_gui.cpp index 876e8d33e..71c5e57f0 100644 --- a/libs/yocto/yocto_gui.cpp +++ b/libs/yocto/yocto_gui.cpp @@ -2549,26 +2549,22 @@ struct glwidgets_param { , valuef{0, 0, 0, 0} , minmaxf{0, 0} , readonly{true} {} - glwidgets_param( - float value, vec2f minmax = {0, 0}, bool readonly = false) + glwidgets_param(float value, vec2f minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value1f} , valuef{value, 0, 0, 0} , minmaxf{minmax} , readonly{readonly} {} - glwidgets_param( - vec2f value, vec2f minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec2f value, vec2f minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value2f} , valuef{value.x, value.y, 0, 0} , minmaxf{minmax} , readonly{readonly} {} - glwidgets_param( - vec3f value, vec2f minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec3f value, vec2f minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value3f} , valuef{value.x, value.y, value.z, 0} , minmaxf{minmax} , readonly{readonly} {} - glwidgets_param( - vec4f value, vec2f minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec4f value, vec2f minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value4f} , valuef{value.x, value.y, value.z, value.w} , minmaxf{minmax} @@ -2583,26 +2579,22 @@ struct glwidgets_param { , valuef{value.x, value.y, value.z, value.w} , color{color} , readonly{readonly} {} - glwidgets_param( - int value, vec2i minmax = {0, 0}, bool readonly = false) + glwidgets_param(int value, vec2i minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value1i} , valuei{value, 0, 0, 0} , minmaxi{minmax} , readonly{readonly} {} - glwidgets_param( - vec2i value, vec2i minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec2i value, vec2i minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value2i} , valuei{value.x, value.y, 0, 0} , minmaxi{minmax} , readonly{readonly} {} - glwidgets_param( - vec3i value, vec2i minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec3i value, vec2i minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value3i} , valuei{value.x, value.y, value.z, 0} , minmaxi{minmax} , readonly{readonly} {} - glwidgets_param( - vec4i value, vec2i minmax = {0, 0}, bool readonly = false) + glwidgets_param(vec4i value, vec2i minmax = {0, 0}, bool readonly = false) : type{glwidgets_param_type::value4i} , valuei{value.x, value.y, value.z, value.w} , minmaxi{minmax} diff --git a/libs/yocto/yocto_image.cpp b/libs/yocto/yocto_image.cpp index c8c71a0cc..f8b6660bc 100644 --- a/libs/yocto/yocto_image.cpp +++ b/libs/yocto/yocto_image.cpp @@ -100,15 +100,13 @@ void tonemap_image(image_t& ldr, const image_t& hdr, // Apply exposure and filmic tone mapping image_t colorgrade_image( const image_t& img, bool linear, const colorgrade_params& params) { - return transform_image(img, [linear, params](vec4f a) { - return colorgrade(a, linear, params); - }); + return transform_image( + img, [linear, params](vec4f a) { return colorgrade(a, linear, params); }); } void colorgrade_image(image_t& graded, const image_t& img, bool linear, const colorgrade_params& params) { - return transform_image(graded, img, [linear, params](vec4f a) { - return colorgrade(a, linear, params); - }); + return transform_image(graded, img, + [linear, params](vec4f a) { return colorgrade(a, linear, params); }); } // compute white balance @@ -122,15 +120,13 @@ vec3f compute_white_balance(const image_t& img) { // image compositing image_t composite_image( const image_t& foreground, const image_t& background) { - return transform_images(foreground, background, - [](vec4f a, vec4f b) { return composite(a, b); }); + return transform_images( + foreground, background, [](vec4f a, vec4f b) { return composite(a, b); }); } // removes alpha image_t remove_alpha(const image_t& img) { - return transform_image(img, [](vec4f a) -> vec4f { - return {xyz(a), 1}; - }); + return transform_image(img, [](vec4f a) -> vec4f { return {xyz(a), 1}; }); } // turns alpha into a gray scale image @@ -143,16 +139,15 @@ image_t alpha_to_gray(const image_t& img) { image_t image_difference( const image_t& a, const image_t& b, bool display) { - return transform_images( - a, b, [display](vec4f a, vec4f b) -> vec4f { - auto diff = abs(a - b); - if (display) { - auto d = max(diff); - return {d, d, d, 1}; - } else { - return diff; - } - }); + return transform_images(a, b, [display](vec4f a, vec4f b) -> vec4f { + auto diff = abs(a - b); + if (display) { + auto d = max(diff); + return {d, d, d, 1}; + } else { + return diff; + } + }); } image_t resize_image(const image_t& img, vec2i resize) { @@ -232,8 +227,7 @@ static image_t make_proc_image(vec2i size, Shader&& shader) { } // Make an image -image_t make_grid( - vec2i size, float scale, vec4f color0, vec4f color1) { +image_t make_grid(vec2i size, float scale, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= 4 * scale; uv -= vec2f{(float)(int)uv.x, (float)(int)uv.y}; @@ -256,8 +250,7 @@ image_t make_checker( }); } -image_t make_bumps( - vec2i size, float scale, vec4f color0, vec4f color1) { +image_t make_bumps(vec2i size, float scale, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= 4 * scale; uv -= vec2f{(float)(int)uv.x, (float)(int)uv.y}; @@ -273,8 +266,7 @@ image_t make_bumps( }); } -image_t make_ramp( - vec2i size, float scale, vec4f color0, vec4f color1) { +image_t make_ramp(vec2i size, float scale, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= scale; uv -= vec2f{(float)(int)uv.x, (float)(int)uv.y}; @@ -361,8 +353,8 @@ image_t make_noisemap( }); } -image_t make_fbmmap(vec2i size, float scale, vec4f noise, - vec4f color0, vec4f color1) { +image_t make_fbmmap( + vec2i size, float scale, vec4f noise, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= 8 * scale; auto v = perlin_fbm({uv.x, uv.y, 0}, noise.x, noise.y, (int)noise.z); @@ -371,8 +363,8 @@ image_t make_fbmmap(vec2i size, float scale, vec4f noise, }); } -image_t make_turbulencemap(vec2i size, float scale, vec4f noise, - vec4f color0, vec4f color1) { +image_t make_turbulencemap( + vec2i size, float scale, vec4f noise, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= 8 * scale; auto v = perlin_turbulence({uv.x, uv.y, 0}, noise.x, noise.y, (int)noise.z); @@ -381,8 +373,8 @@ image_t make_turbulencemap(vec2i size, float scale, vec4f noise, }); } -image_t make_ridgemap(vec2i size, float scale, vec4f noise, - vec4f color0, vec4f color1) { +image_t make_ridgemap( + vec2i size, float scale, vec4f noise, vec4f color0, vec4f color1) { return make_proc_image(size, [=](vec2f uv) { uv *= 8 * scale; auto v = perlin_ridge( @@ -409,8 +401,7 @@ image_t add_border( // Implementation of sunsky modified heavily from pbrt image_t make_sunsky(vec2i size, float theta_sun, float turbidity, - bool has_sun, float sun_intensity, float sun_radius, - vec3f ground_albedo) { + bool has_sun, float sun_intensity, float sun_radius, vec3f ground_albedo) { auto zenith_xyY = vec3f{ (+0.00165f * pow(theta_sun, 3.f) - 0.00374f * pow(theta_sun, 2.f) + 0.00208f * theta_sun + 0.00000f) * @@ -543,8 +534,8 @@ image_t make_sunsky(vec2i size, float theta_sun, float turbidity, } // Make an image of multiple lights. -image_t make_lights(vec2i size, vec3f le, int nlights, - float langle, float lwidth, float lheight) { +image_t make_lights(vec2i size, vec3f le, int nlights, float langle, + float lwidth, float lheight) { auto img = image_t{size}; for (auto j = 0; j < size.y / 2; j++) { auto theta = pif * ((j + 0.5f) / size.y); diff --git a/libs/yocto/yocto_modeling.h b/libs/yocto/yocto_modeling.h index 79b1ed9b7..c320cb3cd 100644 --- a/libs/yocto/yocto_modeling.h +++ b/libs/yocto/yocto_modeling.h @@ -347,14 +347,11 @@ namespace yocto { // https://iquilezles.org/articles/distfunctions/ // Sphere SDF -inline float sdf_sphere( - vec3f position, vec3f center, float radius); +inline float sdf_sphere(vec3f position, vec3f center, float radius); // Box SDF -inline float sdf_box( - vec3f position, vec3f center, vec3f size); +inline float sdf_box(vec3f position, vec3f center, vec3f size); // Capsule SDF -inline float sdf_capsule( - vec3f position, vec3f a, vec3f b, float radius); +inline float sdf_capsule(vec3f position, vec3f a, vec3f b, float radius); // Union SDF inline float sdf_union(float sdf1, float sdf2); @@ -398,12 +395,10 @@ inline float voronoi_noise(vec3f position); // Fractal noise template -inline float fractal_noise( - Noise&& base_noise, vec2f position, int num = 8); +inline float fractal_noise(Noise&& base_noise, vec2f position, int num = 8); // Turbulence noise template -inline float turbulence_noise( - Noise&& base_noise, vec2f position, int num = 8); +inline float turbulence_noise(Noise&& base_noise, vec2f position, int num = 8); } // namespace yocto @@ -2057,19 +2052,16 @@ inline shape_data displace_shape(const shape_data& shape, namespace yocto { // Sphere SDF -inline float sdf_sphere( - vec3f position, vec3f center, float radius) { +inline float sdf_sphere(vec3f position, vec3f center, float radius) { return length(position - center) - radius; } // Box SDF -inline float sdf_box( - vec3f position, vec3f center, vec3f size) { +inline float sdf_box(vec3f position, vec3f center, vec3f size) { auto q = abs(position - center) - size; return length(max(q, 0.0f)) + min(max(q), 0.0f); } // Capsule SDF -inline float sdf_capsule( - vec3f position, vec3f a, vec3f b, float radius) { +inline float sdf_capsule(vec3f position, vec3f a, vec3f b, float radius) { auto pos_a = position - a, axis = b - a; float height = clamp(dot(pos_a, axis) / dot(axis, axis), 0.0f, 1.0f); return length(pos_a - axis * height) - radius; @@ -2296,8 +2288,7 @@ inline float fractal_noise(Noise&& base_noise, vec2f position, int num) { // Turbulence noise template -inline float turbulence_noise( - Noise&& base_noise, vec2f position, int num) { +inline float turbulence_noise(Noise&& base_noise, vec2f position, int num) { auto noise = 0.0f; for (auto index : range(num)) { noise += abs(2 * base_noise(position * pow(2, index)) - 1) / pow(2, index); diff --git a/libs/yocto/yocto_noise.h b/libs/yocto/yocto_noise.h index ab7840498..a1bd4104e 100644 --- a/libs/yocto/yocto_noise.h +++ b/libs/yocto/yocto_noise.h @@ -71,13 +71,12 @@ inline float perlin_noise(vec4f p, vec4i wrap = {0, 0, 0, 0}); // lacunarity=~2.0 (spacing between successive octaves: 2.0 for warpping), // gain=0.5 (relative weighting applied to each successive octave), // offset=1.0 (used to invert the ridges). -inline float perlin_ridge(vec3f p, float lacunarity = 2, - float gain = 0.5, int octaves = 6, float offset = 1, - vec3i wrap = {0, 0, 0}); +inline float perlin_ridge(vec3f p, float lacunarity = 2, float gain = 0.5, + int octaves = 6, float offset = 1, vec3i wrap = {0, 0, 0}); inline float perlin_fbm(vec3f p, float lacunarity = 2, float gain = 0.5, int octaves = 6, vec3i wrap = {0, 0, 0}); -inline float perlin_turbulence(vec3f p, float lacunarity = 2, - float gain = 0.5, int octaves = 6, vec3i wrap = {0, 0, 0}); +inline float perlin_turbulence(vec3f p, float lacunarity = 2, float gain = 0.5, + int octaves = 6, vec3i wrap = {0, 0, 0}); } // namespace yocto @@ -330,8 +329,8 @@ inline float perlin_noise(vec4f p, vec4i w) { } // ridge -inline float perlin_ridge(vec3f p, float lacunarity, float gain, - int octaves, float offset, vec3i wrap) { +inline float perlin_ridge(vec3f p, float lacunarity, float gain, int octaves, + float offset, vec3i wrap) { auto frequency = 1.0f; auto prev = 1.0f; auto amplitude = 0.5f; @@ -348,8 +347,8 @@ inline float perlin_ridge(vec3f p, float lacunarity, float gain, } // fmb -inline float perlin_fbm(vec3f p, float lacunarity, float gain, - int octaves, vec3i wrap) { +inline float perlin_fbm( + vec3f p, float lacunarity, float gain, int octaves, vec3i wrap) { auto frequency = 1.0f; auto amplitude = 1.0f; auto sum = 0.0f; @@ -362,8 +361,8 @@ inline float perlin_fbm(vec3f p, float lacunarity, float gain, } // turbulence -inline float perlin_turbulence(vec3f p, float lacunarity, float gain, - int octaves, vec3i wrap) { +inline float perlin_turbulence( + vec3f p, float lacunarity, float gain, int octaves, vec3i wrap) { auto frequency = 1.0f; auto amplitude = 1.0f; auto sum = 0.0f; diff --git a/libs/yocto/yocto_sampling.h b/libs/yocto/yocto_sampling.h index a0676a7f8..f9a3566bd 100644 --- a/libs/yocto/yocto_sampling.h +++ b/libs/yocto/yocto_sampling.h @@ -125,13 +125,11 @@ inline float sample_hemisphere_cos_pdf(vec3f direction); // Sample an hemispherical direction with cosine distribution. inline vec3f sample_hemisphere_cos(vec3f normal, vec2f ruv); -inline float sample_hemisphere_cos_pdf( - vec3f normal, vec3f direction); +inline float sample_hemisphere_cos_pdf(vec3f normal, vec3f direction); // Sample an hemispherical direction with cosine power distribution. inline vec3f sample_hemisphere_cospower(float exponent, vec2f ruv); -inline float sample_hemisphere_cospower_pdf( - float exponent, vec3f direction); +inline float sample_hemisphere_cospower_pdf(float exponent, vec3f direction); // Sample an hemispherical direction with cosine power distribution. inline vec3f sample_hemisphere_cospower( @@ -151,11 +149,9 @@ inline float sample_cylinder_pdf(vec3f point); inline vec2f sample_triangle(vec2f ruv); // Sample a point uniformly on a triangle. -inline vec3f sample_triangle( - vec3f p0, vec3f p1, vec3f p2, vec2f ruv); +inline vec3f sample_triangle(vec3f p0, vec3f p1, vec3f p2, vec2f ruv); // Pdf for uniform triangle sampling, i.e. triangle area. -inline float sample_triangle_pdf( - vec3f p0, vec3f p1, vec3f p2); +inline float sample_triangle_pdf(vec3f p0, vec3f p1, vec3f p2); // Sample an index with uniform distribution. inline int sample_uniform(int size, float r); @@ -281,8 +277,7 @@ inline vec3f sample_hemisphere(vec3f normal, vec2f ruv) { auto local_direction = vec3f{r * cos(phi), r * sin(phi), z}; return transform_direction(basis_fromz(normal), local_direction); } -inline float sample_hemisphere_pdf( - vec3f normal, vec3f direction) { +inline float sample_hemisphere_pdf(vec3f normal, vec3f direction) { return (dot(normal, direction) <= 0) ? 0 : 1 / (2 * pif); } @@ -314,8 +309,7 @@ inline vec3f sample_hemisphere_cos(vec3f normal, vec2f ruv) { auto local_direction = vec3f{r * cos(phi), r * sin(phi), z}; return transform_direction(basis_fromz(normal), local_direction); } -inline float sample_hemisphere_cos_pdf( - vec3f normal, vec3f direction) { +inline float sample_hemisphere_cos_pdf(vec3f normal, vec3f direction) { auto cosw = dot(normal, direction); return (cosw <= 0) ? 0 : cosw / pif; } @@ -327,8 +321,7 @@ inline vec3f sample_hemisphere_cospower(float exponent, vec2f ruv) { auto phi = 2 * pif * ruv.x; return {r * cos(phi), r * sin(phi), z}; } -inline float sample_hemisphere_cospower_pdf( - float exponent, vec3f direction) { +inline float sample_hemisphere_cospower_pdf(float exponent, vec3f direction) { return (direction.z <= 0) ? 0 : pow(direction.z, exponent) * (exponent + 1) / (2 * pif); @@ -370,14 +363,12 @@ inline vec2f sample_triangle(vec2f ruv) { } // Sample a point uniformly on a triangle. -inline vec3f sample_triangle( - vec3f p0, vec3f p1, vec3f p2, vec2f ruv) { +inline vec3f sample_triangle(vec3f p0, vec3f p1, vec3f p2, vec2f ruv) { auto uv = sample_triangle(ruv); return p0 * (1 - uv.x - uv.y) + p1 * uv.x + p2 * uv.y; } // Pdf for uniform triangle sampling, i.e. triangle area. -inline float sample_triangle_pdf( - vec3f p0, vec3f p1, vec3f p2) { +inline float sample_triangle_pdf(vec3f p0, vec3f p1, vec3f p2) { return 2 / length(cross(p1 - p0, p2 - p0)); } diff --git a/libs/yocto/yocto_scene.cpp b/libs/yocto/yocto_scene.cpp index 42321a2f4..e241be99f 100644 --- a/libs/yocto/yocto_scene.cpp +++ b/libs/yocto/yocto_scene.cpp @@ -71,8 +71,7 @@ vec2i camera_resolution(const camera_data& camera, int resolution) { // Generates a ray from a camera for yimg::image plane coordinate uv and // the lens coordinates luv. -ray3f eval_camera( - const camera_data& camera, vec2f image_uv, vec2f lens_uv) { +ray3f eval_camera(const camera_data& camera, vec2f image_uv, vec2f lens_uv) { auto film = camera.aspect >= 1 ? vec2f{camera.film, camera.film / camera.aspect} : vec2f{camera.film * camera.aspect, camera.film}; @@ -128,8 +127,8 @@ vec4f lookup_texture( } // Evaluates an image at a point `uv`. -vec4f eval_texture(const texture_data& texture, vec2f uv, - bool ldr_as_linear, bool no_flipv) { +vec4f eval_texture( + const texture_data& texture, vec2f uv, bool ldr_as_linear, bool no_flipv) { if (texture.pixelsf.empty() && texture.pixelsb.empty()) return {0, 0, 0, 0}; // get texture width/height @@ -186,8 +185,7 @@ static const auto min_roughness = 0.03f * 0.03f; // Evaluate material material_point eval_material(const scene_data& scene, - const material_data& material, vec2f texcoord, - vec4f color_shp) { + const material_data& material, vec2f texcoord, vec4f color_shp) { // evaluate textures auto emission_tex = eval_texture(scene, material.emission_tex, texcoord); auto color_tex = eval_texture(scene, material.color_tex, texcoord); @@ -450,8 +448,7 @@ vec3f eval_normalmap(const scene_data& scene, const instance_data& instance, // Eval shading position vec3f eval_shading_position(const scene_data& scene, - const instance_data& instance, int element, vec2f uv, - vec3f outgoing) { + 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); @@ -466,8 +463,7 @@ vec3f eval_shading_position(const scene_data& scene, // Eval shading normal vec3f eval_shading_normal(const scene_data& scene, - const instance_data& instance, int element, vec2f uv, - vec3f outgoing) { + 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()) { @@ -750,9 +746,8 @@ int add_environment(scene_data& scene, const string& name, return (int)scene.environments.size() - 1; } -int add_camera(scene_data& scene, const string& name, vec3f from, - vec3f to, float lens, float aspect, float aperture, - float focus_offset) { +int add_camera(scene_data& scene, const string& name, vec3f from, vec3f to, + float lens, float aspect, float aperture, float focus_offset) { return add_camera(scene, name, {.frame = lookat_frame(from, to, {0, 1, 0}), .lens = lens, @@ -800,9 +795,9 @@ int add_material(scene_data& scene, const string& name, material_type type, // Scene creation helpers int add_material(scene_data& scene, const string& name, material_type type, - vec3f color, float roughness, vec3f scattering, - float scanisotropy, float trdepth, int color_tex, int roughness_tex, - int scattering_tex, int normal_tex) { + vec3f color, float roughness, vec3f scattering, float scanisotropy, + float trdepth, int color_tex, int roughness_tex, int scattering_tex, + int normal_tex) { return add_material(scene, name, {.type = type, .color = color, diff --git a/libs/yocto/yocto_scene.h b/libs/yocto/yocto_scene.h index c5200238a..e21c3c74a 100644 --- a/libs/yocto/yocto_scene.h +++ b/libs/yocto/yocto_scene.h @@ -233,8 +233,7 @@ namespace yocto { vec2i camera_resolution(const camera_data& camera, int resolution); // Generates a ray from a camera. -ray3f eval_camera( - const camera_data& camera, vec2f image_uv, vec2f lens_uv); +ray3f eval_camera(const camera_data& camera, vec2f image_uv, vec2f lens_uv); } // namespace yocto @@ -313,11 +312,9 @@ pair eval_element_tangents( vec3f eval_normalmap(const scene_data& scene, const instance_data& instance, int element, vec2f uv); vec3f eval_shading_position(const scene_data& scene, - const instance_data& instance, int element, vec2f uv, - vec3f outgoing); + const instance_data& instance, int element, vec2f uv, vec3f outgoing); vec3f eval_shading_normal(const scene_data& scene, - const instance_data& instance, int element, vec2f uv, - vec3f outgoing); + const instance_data& instance, int element, vec2f uv, vec3f outgoing); vec4f eval_color(const scene_data& scene, const instance_data& instance, int element, vec2f uv); @@ -380,9 +377,9 @@ int add_environment( scene_data& scene, const string& name, const environment_data& environment); // Scene creation helpers -int add_camera(scene_data& scene, const string& name, vec3f from, - vec3f to, float lens = 0.1f, float aspect = 16.0f / 9.0f, - float aperture = 0, float focus_offset = 0); +int add_camera(scene_data& scene, const string& name, vec3f from, vec3f to, + float lens = 0.1f, float aspect = 16.0f / 9.0f, float aperture = 0, + float focus_offset = 0); int add_camera(scene_data& scene, const string& name, const frame3f& frame, float lens = 0.1f, float aspect = 16.0f / 9.0f, float aperture = 0, float focus = 1); @@ -394,8 +391,8 @@ int add_material(scene_data& scene, const string& name, material_type type, vec3f color, float roughness = 0, int color_tex = invalidid, int roughness_tex = invalidid, int normal_tex = invalidid); int add_material(scene_data& scene, const string& name, material_type type, - vec3f color, float roughness, vec3f scattering, - float scanisotropy = 0, float trdepth = 0.01f, int color_tex = invalidid, + vec3f color, float roughness, vec3f scattering, float scanisotropy = 0, + float trdepth = 0.01f, int color_tex = invalidid, int roughness_tex = invalidid, int scattering_tex = invalidid, int normal_tex = invalidid); int add_instance(scene_data& scene, const string& name, const frame3f& frame, diff --git a/libs/yocto/yocto_sceneio.cpp b/libs/yocto/yocto_sceneio.cpp index f0d0bb336..6906d8e3c 100644 --- a/libs/yocto/yocto_sceneio.cpp +++ b/libs/yocto/yocto_sceneio.cpp @@ -426,9 +426,7 @@ static frame3f to_math(const array& value) { return (frame3f&)value; } -static array to_array(vec3f value) { - return (array&)value; -} +static array to_array(vec3f value) { return (array&)value; } static array to_array(const frame3f& value) { return (array&)value; } diff --git a/libs/yocto/yocto_shading.h b/libs/yocto/yocto_shading.h index 0414b1554..fcbcc9192 100644 --- a/libs/yocto/yocto_shading.h +++ b/libs/yocto/yocto_shading.h @@ -69,18 +69,15 @@ using std::vector; namespace yocto { // Check if on the same side of the hemisphere -inline bool same_hemisphere( - vec3f normal, vec3f outgoing, vec3f incoming); +inline bool same_hemisphere(vec3f normal, vec3f outgoing, vec3f incoming); // Schlick approximation of the Fresnel term. -inline vec3f fresnel_schlick( - vec3f specular, vec3f normal, vec3f outgoing); +inline vec3f fresnel_schlick(vec3f specular, vec3f normal, vec3f outgoing); // Compute the fresnel term for dielectrics. -inline float fresnel_dielectric( - float eta, vec3f normal, vec3f outgoing); +inline float fresnel_dielectric(float eta, vec3f normal, vec3f outgoing); // Compute the fresnel term for metals. -inline vec3f fresnel_conductor(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing); +inline vec3f fresnel_conductor( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing); // Convert eta to reflectivity inline vec3f eta_to_reflectivity(vec3f eta); @@ -91,55 +88,52 @@ inline vec3f eta_to_reflectivity(vec3f eta, vec3f etak); // Convert eta to edge tint parametrization. inline pair eta_to_edgetint(vec3f eta, vec3f etak); // Convert reflectivity and edge tint to eta. -inline pair edgetint_to_eta( - vec3f reflectivity, vec3f edgetint); +inline pair edgetint_to_eta(vec3f reflectivity, vec3f edgetint); // Get tabulated ior for conductors inline pair conductor_eta(const string& name); // Evaluates the microfacet distribution. -inline float microfacet_distribution(float roughness, vec3f normal, - vec3f halfway, bool ggx = true); +inline float microfacet_distribution( + float roughness, vec3f normal, vec3f halfway, bool ggx = true); // Evaluates the microfacet shadowing. -inline float microfacet_shadowing(float roughness, vec3f normal, - vec3f halfway, vec3f outgoing, vec3f incoming, - bool ggx = true); +inline float microfacet_shadowing(float roughness, vec3f normal, vec3f halfway, + vec3f outgoing, vec3f incoming, bool ggx = true); // Samples a microfacet distribution. inline vec3f sample_microfacet( float roughness, vec3f normal, vec2f rn, bool ggx = true); // Pdf for microfacet distribution sampling. -inline float sample_microfacet_pdf(float roughness, vec3f normal, - vec3f halfway, bool ggx = true); +inline float sample_microfacet_pdf( + float roughness, vec3f normal, vec3f halfway, bool ggx = true); // Samples a microfacet distribution with the distribution of visible normals. -inline vec3f sample_microfacet(float roughness, vec3f normal, - vec3f outgoing, vec2f rn, bool ggx = true); +inline vec3f sample_microfacet( + float roughness, vec3f normal, vec3f outgoing, vec2f rn, bool ggx = true); // Pdf for microfacet distribution sampling with the distribution of visible // normals. -inline float sample_microfacet_pdf(float roughness, vec3f normal, - vec3f halfway, vec3f outgoing, bool ggx = true); +inline float sample_microfacet_pdf(float roughness, vec3f normal, vec3f halfway, + vec3f outgoing, bool ggx = true); // Microfacet energy compensation (E(cos(w))) inline float microfacet_cosintegral( float roughness, vec3f normal, vec3f outgoing); // Approximate microfacet compensation for metals with Schlick's Fresnel -inline vec3f microfacet_compensation(vec3f color, float roughness, - vec3f normal, vec3f outgoing); +inline vec3f microfacet_compensation( + vec3f color, float roughness, vec3f normal, vec3f outgoing); // Evaluates a diffuse BRDF lobe. -inline vec3f eval_matte(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline vec3f eval_matte( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a diffuse BRDF lobe. -inline vec3f sample_matte(vec3f color, vec3f normal, - vec3f outgoing, vec2f rn); +inline vec3f sample_matte(vec3f color, vec3f normal, vec3f outgoing, vec2f rn); // Pdf for diffuse BRDF lobe sampling. -inline float sample_matte_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline float sample_matte_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluates a specular BRDF lobe. -inline vec3f eval_glossy(vec3f color, float ior, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming); +inline vec3f eval_glossy(vec3f color, float ior, float roughness, vec3f normal, + vec3f outgoing, vec3f incoming); // Sample a specular BRDF lobe. inline vec3f sample_glossy(vec3f color, float ior, float roughness, vec3f normal, vec3f outgoing, vec2f rn); @@ -148,57 +142,53 @@ inline float sample_glossy_pdf(vec3f color, float ior, float roughness, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluates a metal BRDF lobe. -inline vec3f eval_reflective(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming); +inline vec3f eval_reflective( + vec3f color, float roughness, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a metal BRDF lobe. -inline vec3f sample_reflective(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec2f rn); +inline vec3f sample_reflective( + vec3f color, float roughness, vec3f normal, vec3f outgoing, vec2f rn); // Pdf for metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming); +inline float sample_reflective_pdf( + vec3f color, float roughness, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a delta metal BRDF lobe. -inline vec3f eval_reflective(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline vec3f eval_reflective( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a delta metal BRDF lobe. -inline vec3f sample_reflective( - vec3f color, vec3f normal, vec3f outgoing); +inline vec3f sample_reflective(vec3f color, vec3f normal, vec3f outgoing); // Pdf for delta metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline float sample_reflective_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a delta metal BRDF lobe. -inline vec3f eval_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming); +inline vec3f eval_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a delta metal BRDF lobe. -inline vec3f sample_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing); +inline vec3f sample_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing); // Pdf for delta metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming); +inline float sample_reflective_pdf( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a delta metal BRDF lobe. -inline vec3f eval_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming); +inline vec3f eval_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a delta metal BRDF lobe. -inline vec3f sample_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing); +inline vec3f sample_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing); // Pdf for delta metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming); +inline float sample_reflective_pdf( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluates a specular BRDF lobe. inline vec3f eval_gltfpbr(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, - vec3f incoming); + float metallic, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a specular BRDF lobe. inline vec3f sample_gltfpbr(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, float rnl, - vec2f rn); + float metallic, vec3f normal, vec3f outgoing, float rnl, vec2f rn); // Pdf for specular BRDF lobe sampling. inline float sample_gltfpbr_pdf(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, - vec3f incoming); + float metallic, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluates a transmission BRDF lobe. inline vec3f eval_transparent(vec3f color, float ior, float roughness, @@ -207,19 +197,18 @@ inline vec3f eval_transparent(vec3f color, float ior, float roughness, inline vec3f sample_transparent(float ior, float roughness, vec3f normal, vec3f outgoing, float rnl, vec2f rn); // Pdf for transmission BRDF lobe sampling. -inline float sample_tranparent_pdf(vec3f color, float ior, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming); +inline float sample_tranparent_pdf(vec3f color, float ior, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a delta transmission BRDF lobe. -inline vec3f eval_transparent(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming); +inline vec3f eval_transparent( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a delta transmission BRDF lobe. -inline vec3f sample_transparent(vec3f color, float ior, - vec3f normal, vec3f outgoing, float rnl); +inline vec3f sample_transparent( + vec3f color, float ior, vec3f normal, vec3f outgoing, float rnl); // Pdf for delta transmission BRDF lobe sampling. -inline float sample_tranparent_pdf(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming); +inline float sample_tranparent_pdf( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluates a refraction BRDF lobe. inline vec3f eval_refractive(vec3f color, float ior, float roughness, @@ -228,39 +217,37 @@ inline vec3f eval_refractive(vec3f color, float ior, float roughness, inline vec3f sample_refractive(float ior, float roughness, vec3f normal, vec3f outgoing, float rnl, vec2f rn); // Pdf for refraction BRDF lobe sampling. -inline float sample_refractive_pdf(vec3f color, float ior, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming); +inline float sample_refractive_pdf(vec3f color, float ior, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a delta refraction BRDF lobe. -inline vec3f eval_refractive(vec3f color, float ior, vec3f normal, - vec3f outgoing, vec3f incoming); +inline vec3f eval_refractive( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a delta refraction BRDF lobe. -inline vec3f sample_refractive(vec3f color, float ior, - vec3f normal, vec3f outgoing, float rnl); +inline vec3f sample_refractive( + vec3f color, float ior, vec3f normal, vec3f outgoing, float rnl); // Pdf for delta refraction BRDF lobe sampling. -inline float sample_refractive_pdf(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming); +inline float sample_refractive_pdf( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming); // Evaluate a translucent BRDF lobe. -inline vec3f eval_translucent(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline vec3f eval_translucent( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Pdf for translucency BRDF lobe sampling. -inline float sample_translucent_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline float sample_translucent_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a translucency BRDF lobe. -inline vec3f sample_translucent(vec3f color, vec3f normal, - vec3f outgoing, vec2f rn); +inline vec3f sample_translucent( + vec3f color, vec3f normal, vec3f outgoing, vec2f rn); // Evaluate a passthrough BRDF lobe. -inline vec3f eval_passthrough(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline vec3f eval_passthrough( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Sample a passthrough BRDF lobe. -inline vec3f sample_passthrough( - vec3f color, vec3f normal, vec3f outgoing); +inline vec3f sample_passthrough(vec3f color, vec3f normal, vec3f outgoing); // Pdf for passthrough BRDF lobe sampling. -inline float sample_passthrough_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming); +inline float sample_passthrough_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming); // Convert mean-free-path to transmission inline vec3f mfp_to_transmission(vec3f mfp, float depth); @@ -278,8 +265,7 @@ inline float sample_transmittance_pdf( inline float eval_phasefunction( float anisotropy, vec3f outgoing, vec3f incoming); // Sample phase function -inline vec3f sample_phasefunction( - float anisotropy, vec3f outgoing, vec2f rn); +inline vec3f sample_phasefunction(float anisotropy, vec3f outgoing, vec2f rn); // Pdf for phase function sampling inline float sample_phasefunction_pdf( float anisotropy, vec3f outgoing, vec3f incoming); @@ -300,14 +286,12 @@ inline float sample_phasefunction_pdf( namespace yocto { // Check if on the same side of the hemisphere -inline bool same_hemisphere( - vec3f normal, vec3f outgoing, vec3f incoming) { +inline bool same_hemisphere(vec3f normal, vec3f outgoing, vec3f incoming) { return dot(normal, outgoing) * dot(normal, incoming) >= 0; } // Schlick approximation of the Fresnel term -inline vec3f fresnel_schlick( - vec3f specular, vec3f normal, vec3f outgoing) { +inline vec3f fresnel_schlick(vec3f specular, vec3f normal, vec3f outgoing) { if (specular == vec3f{0, 0, 0}) return {0, 0, 0}; auto cosine = dot(normal, outgoing); return specular + @@ -315,8 +299,7 @@ inline vec3f fresnel_schlick( } // Compute the fresnel term for dielectrics. -inline float fresnel_dielectric( - float eta, vec3f normal, vec3f outgoing) { +inline float fresnel_dielectric(float eta, vec3f normal, vec3f outgoing) { // Implementation from // https://seblagarde.wordpress.com/2013/04/29/memo-on-fresnel-equations/ auto cosw = abs(dot(normal, outgoing)); @@ -338,8 +321,8 @@ inline float fresnel_dielectric( } // Compute the fresnel term for metals. -inline vec3f fresnel_conductor(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing) { +inline vec3f fresnel_conductor( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing) { // Implementation from // https://seblagarde.wordpress.com/2013/04/29/memo-on-fresnel-equations/ auto cosw = dot(normal, outgoing); @@ -389,8 +372,7 @@ inline pair eta_to_edgetint(vec3f eta, vec3f etak) { return {reflectivity, edgetint}; } // Convert reflectivity and edge tint to eta. -inline pair edgetint_to_eta( - vec3f reflectivity, vec3f edgetint) { +inline pair edgetint_to_eta(vec3f reflectivity, vec3f edgetint) { auto r = clamp(reflectivity, 0.0f, 0.99f); auto g = edgetint; @@ -424,8 +406,8 @@ inline float microfacet_distribution( } // Evaluate the microfacet shadowing1 -inline float microfacet_shadowing1(float roughness, vec3f normal, - vec3f halfway, vec3f direction, bool ggx) { +inline float microfacet_shadowing1( + float roughness, vec3f normal, vec3f halfway, vec3f direction, bool ggx) { // https://google.github.io/filament/Filament.html#materialsystem/specularbrdf // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#appendix-b-brdf-implementation @@ -446,9 +428,8 @@ inline float microfacet_shadowing1(float roughness, vec3f normal, } // Evaluate microfacet shadowing -inline float microfacet_shadowing(float roughness, vec3f normal, - vec3f halfway, vec3f outgoing, vec3f incoming, - bool ggx) { +inline float microfacet_shadowing(float roughness, vec3f normal, vec3f halfway, + vec3f outgoing, vec3f incoming, bool ggx) { return microfacet_shadowing1(roughness, normal, halfway, outgoing, ggx) * microfacet_shadowing1(roughness, normal, halfway, incoming, ggx); } @@ -478,8 +459,8 @@ inline float sample_microfacet_pdf( } // Sample a microfacet distribution with the distribution of visible normals. -inline vec3f sample_microfacet(float roughness, vec3f normal, - vec3f outgoing, vec2f rn, bool ggx) { +inline vec3f sample_microfacet( + float roughness, vec3f normal, vec3f outgoing, vec2f rn, bool ggx) { // http://jcgt.org/published/0007/04/01/ if (ggx) { // move to local coordinate system @@ -518,8 +499,8 @@ inline vec3f sample_microfacet(float roughness, vec3f normal, // Pdf for microfacet distribution sampling with the distribution of visible // normals. -inline float sample_microfacet_pdf(float roughness, vec3f normal, - vec3f halfway, vec3f outgoing, bool ggx) { +inline float sample_microfacet_pdf( + float roughness, vec3f normal, vec3f halfway, vec3f outgoing, bool ggx) { // http://jcgt.org/published/0007/04/01/ if (dot(normal, halfway) < 0) return 0; if (dot(halfway, outgoing) < 0) return 0; @@ -543,38 +524,37 @@ inline float microfacet_cosintegral( return 1 - pow(s, 6.0f) * pow(m, 3.0f / 4.0f) / (pow(t, 6.0f) + pow(m, 2.0f)); } // Approximate microfacet compensation for metals with Schlick's Fresnel -inline vec3f microfacet_compensation(vec3f color, float roughness, - vec3f normal, vec3f outgoing) { +inline vec3f microfacet_compensation( + vec3f color, float roughness, vec3f normal, vec3f outgoing) { // https://blog.selfshadow.com/publications/turquin/ms_comp_final.pdf auto E = microfacet_cosintegral(sqrt(roughness), normal, outgoing); return 1 + color * (1 - E) / E; } // Evaluate a diffuse BRDF lobe. -inline vec3f eval_matte(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline vec3f eval_matte( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; return color / pif * abs(dot(normal, incoming)); } // Sample a diffuse BRDF lobe. -inline vec3f sample_matte(vec3f color, vec3f normal, - vec3f outgoing, vec2f rn) { +inline vec3f sample_matte(vec3f color, vec3f normal, vec3f outgoing, vec2f rn) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return sample_hemisphere_cos(up_normal, rn); } // Pdf for diffuse BRDF lobe sampling. -inline float sample_matte_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline float sample_matte_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return sample_hemisphere_cos_pdf(up_normal, incoming); } // Evaluate a specular BRDF lobe. -inline vec3f eval_glossy(vec3f color, float ior, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline vec3f eval_glossy(vec3f color, float ior, float roughness, vec3f normal, + vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto F1 = fresnel_dielectric(ior, up_normal, outgoing); @@ -616,8 +596,8 @@ inline float sample_glossy_pdf(vec3f color, float ior, float roughness, } // Evaluate a metal BRDF lobe. -inline vec3f eval_reflective(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline vec3f eval_reflective(vec3f color, float roughness, vec3f normal, + vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = normalize(incoming + outgoing); @@ -631,8 +611,8 @@ inline vec3f eval_reflective(vec3f color, float roughness, } // Sample a metal BRDF lobe. -inline vec3f sample_reflective(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec2f rn) { +inline vec3f sample_reflective( + vec3f color, float roughness, vec3f normal, vec3f outgoing, vec2f rn) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = sample_microfacet(roughness, up_normal, rn); auto incoming = reflect(outgoing, halfway); @@ -641,8 +621,8 @@ inline vec3f sample_reflective(vec3f color, float roughness, } // Pdf for metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline float sample_reflective_pdf(vec3f color, float roughness, vec3f normal, + vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = normalize(outgoing + incoming); @@ -651,9 +631,8 @@ inline float sample_reflective_pdf(vec3f color, float roughness, } // Evaluate a metal BRDF lobe. -inline vec3f eval_reflective(vec3f eta, vec3f etak, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming) { +inline vec3f eval_reflective(vec3f eta, vec3f etak, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = normalize(incoming + outgoing); @@ -666,18 +645,16 @@ inline vec3f eval_reflective(vec3f eta, vec3f etak, } // Sample a metal BRDF lobe. -inline vec3f sample_reflective(vec3f eta, vec3f etak, - float roughness, vec3f normal, vec3f outgoing, - vec2f rn) { +inline vec3f sample_reflective(vec3f eta, vec3f etak, float roughness, + vec3f normal, vec3f outgoing, vec2f rn) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = sample_microfacet(roughness, up_normal, rn); return reflect(outgoing, halfway); } // Pdf for metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f eta, vec3f etak, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming) { +inline float sample_reflective_pdf(vec3f eta, vec3f etak, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = normalize(outgoing + incoming); @@ -686,8 +663,8 @@ inline float sample_reflective_pdf(vec3f eta, vec3f etak, } // Evaluate a delta metal BRDF lobe. -inline vec3f eval_reflective(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline vec3f eval_reflective( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return fresnel_conductor( @@ -695,45 +672,43 @@ inline vec3f eval_reflective(vec3f color, vec3f normal, } // Sample a delta metal BRDF lobe. -inline vec3f sample_reflective( - vec3f color, vec3f normal, vec3f outgoing) { +inline vec3f sample_reflective(vec3f color, vec3f normal, vec3f outgoing) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return reflect(outgoing, up_normal); } // Pdf for delta metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline float sample_reflective_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; return 1; } // Evaluate a delta metal BRDF lobe. -inline vec3f eval_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline vec3f eval_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return fresnel_conductor(eta, etak, up_normal, outgoing); } // Sample a delta metal BRDF lobe. -inline vec3f sample_reflective(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing) { +inline vec3f sample_reflective( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return reflect(outgoing, up_normal); } // Pdf for delta metal BRDF lobe sampling. -inline float sample_reflective_pdf(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline float sample_reflective_pdf( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; return 1; } // Evaluate a specular BRDF lobe. inline vec3f eval_gltfpbr(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, - vec3f incoming) { + float metallic, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return {0, 0, 0}; auto reflectivity = lerp( eta_to_reflectivity(vec3f{ior, ior, ior}), color, metallic); @@ -752,8 +727,7 @@ inline vec3f eval_gltfpbr(vec3f color, float ior, float roughness, // Sample a specular BRDF lobe. inline vec3f sample_gltfpbr(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, float rnl, - vec2f rn) { + float metallic, vec3f normal, vec3f outgoing, float rnl, vec2f rn) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto reflectivity = lerp( eta_to_reflectivity(vec3f{ior, ior, ior}), color, metallic); @@ -769,8 +743,7 @@ inline vec3f sample_gltfpbr(vec3f color, float ior, float roughness, // Pdf for specular BRDF lobe sampling. inline float sample_gltfpbr_pdf(vec3f color, float ior, float roughness, - float metallic, vec3f normal, vec3f outgoing, - vec3f incoming) { + float metallic, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) <= 0) return 0; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; auto halfway = normalize(outgoing + incoming); @@ -826,9 +799,8 @@ inline vec3f sample_transparent(vec3f color, float ior, float roughness, } // Pdf for transmission BRDF lobe sampling. -inline float sample_tranparent_pdf(vec3f color, float ior, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming) { +inline float sample_tranparent_pdf(vec3f color, float ior, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; if (dot(normal, incoming) * dot(normal, outgoing) >= 0) { auto halfway = normalize(incoming + outgoing); @@ -845,8 +817,8 @@ inline float sample_tranparent_pdf(vec3f color, float ior, } // Evaluate a delta transmission BRDF lobe. -inline vec3f eval_transparent(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline vec3f eval_transparent( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; if (dot(normal, incoming) * dot(normal, outgoing) >= 0) { return vec3f{1, 1, 1} * fresnel_dielectric(ior, up_normal, outgoing); @@ -856,8 +828,8 @@ inline vec3f eval_transparent(vec3f color, float ior, } // Sample a delta transmission BRDF lobe. -inline vec3f sample_transparent(vec3f color, float ior, - vec3f normal, vec3f outgoing, float rnl) { +inline vec3f sample_transparent( + vec3f color, float ior, vec3f normal, vec3f outgoing, float rnl) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; if (rnl < fresnel_dielectric(ior, up_normal, outgoing)) { return reflect(outgoing, up_normal); @@ -867,8 +839,8 @@ inline vec3f sample_transparent(vec3f color, float ior, } // Pdf for delta transmission BRDF lobe sampling. -inline float sample_tranparent_pdf(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline float sample_tranparent_pdf( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; if (dot(normal, incoming) * dot(normal, outgoing) >= 0) { return fresnel_dielectric(ior, up_normal, outgoing); @@ -929,9 +901,8 @@ inline vec3f sample_refractive(vec3f color, float ior, float roughness, } // Pdf for refraction BRDF lobe sampling. -inline float sample_refractive_pdf(vec3f color, float ior, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming) { +inline float sample_refractive_pdf(vec3f color, float ior, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming) { auto entering = dot(normal, outgoing) >= 0; auto up_normal = entering ? normal : -normal; auto rel_ior = entering ? ior : (1 / ior); @@ -954,8 +925,8 @@ inline float sample_refractive_pdf(vec3f color, float ior, } // Evaluate a delta refraction BRDF lobe. -inline vec3f eval_refractive(vec3f color, float ior, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline vec3f eval_refractive( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming) { if (abs(ior - 1) < 1e-3) return dot(normal, incoming) * dot(normal, outgoing) <= 0 ? vec3f{1, 1, 1} : vec3f{0, 0, 0}; @@ -971,8 +942,8 @@ inline vec3f eval_refractive(vec3f color, float ior, vec3f normal, } // Sample a delta refraction BRDF lobe. -inline vec3f sample_refractive(vec3f color, float ior, - vec3f normal, vec3f outgoing, float rnl) { +inline vec3f sample_refractive( + vec3f color, float ior, vec3f normal, vec3f outgoing, float rnl) { if (abs(ior - 1) < 1e-3) return -outgoing; auto entering = dot(normal, outgoing) >= 0; auto up_normal = entering ? normal : -normal; @@ -985,8 +956,8 @@ inline vec3f sample_refractive(vec3f color, float ior, } // Pdf for delta refraction BRDF lobe sampling. -inline float sample_refractive_pdf(vec3f color, float ior, - vec3f normal, vec3f outgoing, vec3f incoming) { +inline float sample_refractive_pdf( + vec3f color, float ior, vec3f normal, vec3f outgoing, vec3f incoming) { if (abs(ior - 1) < 1e-3) return dot(normal, incoming) * dot(normal, outgoing) < 0 ? 1.0f : 0.0f; auto entering = dot(normal, outgoing) >= 0; @@ -1000,30 +971,30 @@ inline float sample_refractive_pdf(vec3f color, float ior, } // Evaluate a translucent BRDF lobe. -inline vec3f eval_translucent(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline vec3f eval_translucent( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) >= 0) return {0, 0, 0}; return color / pif * abs(dot(normal, incoming)); } // Sample a translucency BRDF lobe. -inline vec3f sample_translucent(vec3f color, vec3f normal, - vec3f outgoing, vec2f rn) { +inline vec3f sample_translucent( + vec3f color, vec3f normal, vec3f outgoing, vec2f rn) { auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return sample_hemisphere_cos(-up_normal, rn); } // Pdf for translucency BRDF lobe sampling. -inline float sample_translucent_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline float sample_translucent_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) >= 0) return 0; auto up_normal = dot(normal, outgoing) <= 0 ? -normal : normal; return sample_hemisphere_cos_pdf(-up_normal, incoming); } // Evaluate a passthrough BRDF lobe. -inline vec3f eval_passthrough(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline vec3f eval_passthrough( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) >= 0) { return vec3f{0, 0, 0}; } else { @@ -1032,14 +1003,13 @@ inline vec3f eval_passthrough(vec3f color, vec3f normal, } // Sample a passthrough BRDF lobe. -inline vec3f sample_passthrough( - vec3f color, vec3f normal, vec3f outgoing) { +inline vec3f sample_passthrough(vec3f color, vec3f normal, vec3f outgoing) { return -outgoing; } // Pdf for passthrough BRDF lobe sampling. -inline float sample_passthrough_pdf(vec3f color, vec3f normal, - vec3f outgoing, vec3f incoming) { +inline float sample_passthrough_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { if (dot(normal, incoming) * dot(normal, outgoing) >= 0) { return 0; } else { @@ -1085,8 +1055,7 @@ inline float eval_phasefunction( } // Sample phase function -inline vec3f sample_phasefunction( - float anisotropy, vec3f outgoing, vec2f rn) { +inline vec3f sample_phasefunction(float anisotropy, vec3f outgoing, vec2f rn) { auto cos_theta = 0.0f; if (abs(anisotropy) < 1e-3f) { cos_theta = 1 - 2 * rn.y; @@ -1217,20 +1186,19 @@ namespace yocto { return eval_reflective(color, roughness, normal, outgoing, incoming); } // Sample a metal BRDF lobe. -[[deprecated]] inline vec3f sample_metallic(vec3f color, float roughness, - vec3f normal, vec3f outgoing, vec2f rn) { +[[deprecated]] inline vec3f sample_metallic( + vec3f color, float roughness, vec3f normal, vec3f outgoing, vec2f rn) { return sample_reflective(color, roughness, normal, outgoing, rn); } // Pdf for metal BRDF lobe sampling. -[[deprecated]] inline float sample_metallic_pdf(vec3f color, - float roughness, vec3f normal, vec3f outgoing, - vec3f incoming) { +[[deprecated]] inline float sample_metallic_pdf(vec3f color, float roughness, + vec3f normal, vec3f outgoing, vec3f incoming) { return sample_reflective_pdf(color, roughness, normal, outgoing, incoming); } // Evaluate a delta metal BRDF lobe. -[[deprecated]] inline vec3f eval_metallic(vec3f color, - vec3f normal, vec3f outgoing, vec3f incoming) { +[[deprecated]] inline vec3f eval_metallic( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { return eval_reflective(color, normal, outgoing, incoming); } // Sample a delta metal BRDF lobe. @@ -1239,25 +1207,24 @@ namespace yocto { return sample_reflective(color, normal, outgoing); } // Pdf for delta metal BRDF lobe sampling. -[[deprecated]] inline float sample_metallic_pdf(vec3f color, - vec3f normal, vec3f outgoing, vec3f incoming) { +[[deprecated]] inline float sample_metallic_pdf( + vec3f color, vec3f normal, vec3f outgoing, vec3f incoming) { return sample_reflective_pdf(color, normal, outgoing, incoming); } // Evaluate a delta metal BRDF lobe. -[[deprecated]] inline vec3f eval_metallic(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing, vec3f incoming) { +[[deprecated]] inline vec3f eval_metallic( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming) { return eval_reflective(eta, etak, normal, outgoing, incoming); } // Sample a delta metal BRDF lobe. -[[deprecated]] inline vec3f sample_metallic(vec3f eta, vec3f etak, - vec3f normal, vec3f outgoing) { +[[deprecated]] inline vec3f sample_metallic( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing) { return sample_reflective(eta, etak, normal, outgoing); } // Pdf for delta metal BRDF lobe sampling. -[[deprecated]] inline float sample_metallic_pdf(vec3f eta, - vec3f etak, vec3f normal, vec3f outgoing, - vec3f incoming) { +[[deprecated]] inline float sample_metallic_pdf( + vec3f eta, vec3f etak, vec3f normal, vec3f outgoing, vec3f incoming) { return sample_reflective_pdf(eta, etak, normal, outgoing, incoming); } diff --git a/libs/yocto/yocto_shape.cpp b/libs/yocto/yocto_shape.cpp index 3c8f726ad..81707e680 100644 --- a/libs/yocto/yocto_shape.cpp +++ b/libs/yocto/yocto_shape.cpp @@ -250,8 +250,8 @@ void sample_shape_cdf(vector& cdf, const shape_data& shape) { } } -shape_point sample_shape(const shape_data& shape, const vector& cdf, - float rn, vec2f ruv) { +shape_point sample_shape( + const shape_data& shape, const vector& cdf, float rn, vec2f ruv) { if (!shape.points.empty()) { auto element = sample_points(cdf, rn); return {element, {0, 0}}; @@ -671,8 +671,7 @@ vector fvshape_stats(const fvshape_data& shape, bool verbose) { namespace yocto { // Make a tesselated rectangle. Useful in other subdivisions. -static shape_data make_quads( - vec2i steps, vec2f scale, vec2f uvscale) { +static shape_data make_quads(vec2i steps, vec2f scale, vec2f uvscale) { auto shape = shape_data{}; shape.positions.resize((steps.x + 1) * (steps.y + 1)); @@ -724,12 +723,11 @@ void merge_shape_inplace(shape_data& shape, const shape_data& merge) { } // Make a plane. -shape_data make_rect( - vec2i steps, vec2f scale, vec2f uvscale) { +shape_data make_rect(vec2i steps, vec2f scale, vec2f uvscale) { return make_quads(steps, scale, uvscale); } -shape_data make_bulged_rect(vec2i steps, vec2f scale, - vec2f uvscale, float height) { +shape_data make_bulged_rect( + vec2i steps, vec2f scale, vec2f uvscale, float height) { auto shape = make_rect(steps, scale, uvscale); if (height != 0) { height = min(height, min(scale)); @@ -745,16 +743,15 @@ shape_data make_bulged_rect(vec2i steps, vec2f scale, } // Make a plane in the xz plane. -shape_data make_recty( - vec2i steps, vec2f scale, vec2f uvscale) { +shape_data make_recty(vec2i steps, vec2f scale, vec2f uvscale) { auto shape = make_rect(steps, scale, uvscale); for (auto& position : shape.positions) position = {position.x, position.z, -position.y}; for (auto& normal : shape.normals) normal = {normal.x, normal.z, normal.y}; return shape; } -shape_data make_bulged_recty(vec2i steps, vec2f scale, - vec2f uvscale, float height) { +shape_data make_bulged_recty( + vec2i steps, vec2f scale, vec2f uvscale, float height) { auto shape = make_bulged_rect(steps, scale, uvscale, height); for (auto& position : shape.positions) position = {position.x, position.z, -position.y}; @@ -763,8 +760,7 @@ shape_data make_bulged_recty(vec2i steps, vec2f scale, } // Make a box. -shape_data make_box( - vec3i steps, vec3f scale, vec3f uvscale) { +shape_data make_box(vec3i steps, vec3f scale, vec3f uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; // + z @@ -811,8 +807,8 @@ shape_data make_box( merge_shape_inplace(shape, qshape); return shape; } -shape_data make_rounded_box(vec3i steps, vec3f scale, - vec3f uvscale, float radius) { +shape_data make_rounded_box( + vec3i steps, vec3f scale, vec3f uvscale, float radius) { auto shape = make_box(steps, scale, uvscale); if (radius != 0) { radius = min(radius, min(scale)); @@ -850,8 +846,7 @@ shape_data make_rounded_box(vec3i steps, vec3f scale, } // Make a quad stack -shape_data make_rect_stack( - vec3i steps, vec3f scale, vec2f uvscale) { +shape_data make_rect_stack(vec3i steps, vec3f scale, vec2f uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; for (auto i : range(steps.z + 1)) { @@ -864,16 +859,15 @@ shape_data make_rect_stack( } // Make a floor. -shape_data make_floor( - vec2i steps, vec2f scale, vec2f uvscale) { +shape_data make_floor(vec2i steps, vec2f scale, vec2f uvscale) { auto shape = make_rect(steps, scale, uvscale); for (auto& position : shape.positions) position = {position.x, position.z, -position.y}; for (auto& normal : shape.normals) normal = {normal.x, normal.z, normal.y}; return shape; } -shape_data make_bent_floor(vec2i steps, vec2f scale, - vec2f uvscale, float radius) { +shape_data make_bent_floor( + vec2i steps, vec2f scale, vec2f uvscale, float radius) { auto shape = make_floor(steps, scale, uvscale); if (radius != 0) { radius = min(radius, scale.y); @@ -908,8 +902,7 @@ shape_data make_sphere(int steps, float scale, float uvscale) { } // Make a sphere. -shape_data make_uvsphere( - vec2i steps, float scale, vec2f uvscale) { +shape_data make_uvsphere(vec2i steps, float scale, vec2f uvscale) { auto shape = make_rect(steps, {1, 1}); for (auto i : range(shape.positions.size())) { auto uv = shape.texcoords[i]; @@ -923,8 +916,7 @@ shape_data make_uvsphere( } // Make a sphere. -shape_data make_uvspherey( - vec2i steps, float scale, vec2f uvscale) { +shape_data make_uvspherey(vec2i steps, float scale, vec2f uvscale) { auto shape = make_uvsphere(steps, scale, uvscale); for (auto& position : shape.positions) position = {position.x, position.z, position.y}; @@ -1014,8 +1006,7 @@ shape_data make_uvdisk(vec2i steps, float scale, vec2f uvscale) { } // Make a uv cylinder -shape_data make_uvcylinder( - vec3i steps, vec2f scale, vec3f uvscale) { +shape_data make_uvcylinder(vec3i steps, vec2f scale, vec3f uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; // side @@ -1060,8 +1051,8 @@ shape_data make_uvcylinder( } // Make a rounded uv cylinder -shape_data make_rounded_uvcylinder(vec3i steps, vec2f scale, - vec3f uvscale, float radius) { +shape_data make_rounded_uvcylinder( + vec3i steps, vec2f scale, vec3f uvscale, float radius) { auto shape = make_uvcylinder(steps, scale, uvscale); if (radius != 0) { radius = min(radius, min(scale)); @@ -1086,8 +1077,7 @@ shape_data make_rounded_uvcylinder(vec3i steps, vec2f scale, } // Make a uv capsule -shape_data make_uvcapsule( - vec3i steps, vec2f scale, vec3f uvscale) { +shape_data make_uvcapsule(vec3i steps, vec2f scale, vec3f uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; // side @@ -1132,8 +1122,7 @@ shape_data make_uvcapsule( } // Make a uv cone -shape_data make_uvcone( - vec3i steps, vec2f scale, vec3f uvscale) { +shape_data make_uvcone(vec3i steps, vec2f scale, vec3f uvscale) { auto shape = shape_data{}; auto qshape = shape_data{}; // side @@ -1166,8 +1155,8 @@ shape_data make_uvcone( } // Generate lines set along a quad. Returns lines, pos, norm, texcoord, radius. -shape_data make_lines(int num, int steps, vec2f scale, - vec2f uvscale, vec2f rad) { +shape_data make_lines( + int num, int steps, vec2f scale, vec2f uvscale, vec2f rad) { auto shape = shape_data{}; shape.positions.resize((steps + 1) * num); shape.normals.resize((steps + 1) * num); @@ -1231,8 +1220,7 @@ shape_data make_points(int num, float uvscale, float radius) { return shape; } -shape_data make_points(vec2i steps, vec2f size, - vec2f uvscale, vec2f radius) { +shape_data make_points(vec2i steps, vec2f size, vec2f uvscale, vec2f radius) { auto shape = make_rect(steps, size, uvscale); shape.quads = {}; shape.points.resize(shape.positions.size()); @@ -1256,8 +1244,7 @@ shape_data make_random_points( } // Make a facevarying rect -fvshape_data make_fvrect( - vec2i steps, vec2f scale, vec2f uvscale) { +fvshape_data make_fvrect(vec2i steps, vec2f scale, vec2f uvscale) { auto rect = make_rect(steps, scale, uvscale); auto shape = fvshape_data{}; shape.positions = rect.positions; @@ -1270,8 +1257,7 @@ fvshape_data make_fvrect( } // Make a facevarying box -fvshape_data make_fvbox( - vec3i steps, vec3f scale, vec3f uvscale) { +fvshape_data make_fvbox(vec3i steps, vec3f scale, vec3f uvscale) { auto shape = fvshape_data{}; make_fvbox(shape.quadspos, shape.quadsnorm, shape.quadstexcoord, shape.positions, shape.normals, shape.texcoords, steps, scale, uvscale); @@ -1468,9 +1454,8 @@ shape_data make_geosphere(int subdivisions, float scale) { } // Make a hair ball around a shape -shape_data make_hair(const shape_data& base, vec2i steps, - vec2f len, vec2f rad, vec2f noise, vec2f clump, - vec2f rotation, int seed) { +shape_data make_hair(const shape_data& base, vec2i steps, vec2f len, vec2f rad, + vec2f noise, vec2f clump, vec2f rotation, int seed) { auto points = sample_shape(base, steps.y, seed); auto bpos = vector{}; auto bnorm = vector{}; @@ -1556,8 +1541,7 @@ shape_data make_random_points( // Grow hairs around a shape shape_data make_random_hairs(const shape_data& shape, int num, int steps, - vec2f len, vec2f radius, float noise, float gravity, - uint64_t seed) { + vec2f len, vec2f radius, float noise, float gravity, uint64_t seed) { auto samples = sample_shape(shape, num, seed); auto hairs = make_lines(num, steps, {1, 1}, {1, 1}, radius); auto rng = make_rng(seed); @@ -1583,9 +1567,8 @@ shape_data make_random_hairs(const shape_data& shape, int num, int steps, } // Grow hairs around a shape -shape_data make_hair2(const shape_data& base, vec2i steps, - vec2f len, vec2f radius, float noise, float gravity, - int seed) { +shape_data make_hair2(const shape_data& base, vec2i steps, vec2f len, + vec2f radius, float noise, float gravity, int seed) { auto points = sample_shape(base, steps.y, seed); auto bpositions = vector{}; auto bnormals = vector{}; @@ -1875,8 +1858,7 @@ vector flip_quads(const vector& quads) { } // Align vertex positions. Alignment is 0: none, 1: min, 2: max, 3: center. -vector align_vertices( - const vector& positions, vec3i alignment) { +vector align_vertices(const vector& positions, vec3i alignment) { auto bounds = invalidb3f; for (auto& p : positions) bounds = merge(bounds, p); auto offset = vec3f{0, 0, 0}; @@ -2512,8 +2494,7 @@ shape_intersection intersect_quads_bvh(const bvh_tree& bvh, // Intersect ray with a bvh. template static shape_intersection overlap_elements_bvh(const bvh_tree& bvh, - Overlap&& overlap_element, vec3f pos, float max_distance, - bool find_any) { + Overlap&& overlap_element, vec3f pos, float max_distance, bool find_any) { // check if empty if (bvh.nodes.empty()) return {}; @@ -2563,12 +2544,10 @@ static shape_intersection overlap_elements_bvh(const bvh_tree& bvh, // index and the element barycentric coordinates. shape_intersection overlap_points_bvh(const bvh_tree& bvh, const vector& points, const vector& positions, - const vector& radius, vec3f pos, float max_distance, - bool find_any) { + const vector& radius, vec3f pos, float max_distance, bool find_any) { return overlap_elements_bvh( bvh, - [&points, &positions, &radius]( - int idx, vec3f pos, float max_distance) { + [&points, &positions, &radius](int idx, vec3f pos, float max_distance) { auto& p = points[idx]; return overlap_point(pos, max_distance, positions[p], radius[p]); }, @@ -2576,12 +2555,10 @@ shape_intersection overlap_points_bvh(const bvh_tree& bvh, } shape_intersection overlap_lines_bvh(const bvh_tree& bvh, const vector& lines, const vector& positions, - const vector& radius, vec3f pos, float max_distance, - bool find_any) { + const vector& radius, vec3f pos, float max_distance, bool find_any) { return overlap_elements_bvh( bvh, - [&lines, &positions, &radius]( - int idx, vec3f pos, float max_distance) { + [&lines, &positions, &radius](int idx, vec3f pos, float max_distance) { auto& l = lines[idx]; return overlap_line(pos, max_distance, positions[l.x], positions[l.y], radius[l.x], radius[l.y]); @@ -2590,8 +2567,7 @@ shape_intersection overlap_lines_bvh(const bvh_tree& bvh, } shape_intersection overlap_triangles_bvh(const bvh_tree& bvh, const vector& triangles, const vector& positions, - const vector& radius, vec3f pos, float max_distance, - bool find_any) { + const vector& radius, vec3f pos, float max_distance, bool find_any) { return overlap_elements_bvh( bvh, [&triangles, &positions, &radius]( @@ -2605,12 +2581,10 @@ shape_intersection overlap_triangles_bvh(const bvh_tree& bvh, } shape_intersection overlap_quads_bvh(const bvh_tree& bvh, const vector& quads, const vector& positions, - const vector& radius, vec3f pos, float max_distance, - bool find_any) { + const vector& radius, vec3f pos, float max_distance, bool find_any) { return overlap_elements_bvh( bvh, - [&quads, &positions, &radius]( - int idx, vec3f pos, float max_distance) { + [&quads, &positions, &radius](int idx, vec3f pos, float max_distance) { auto& q = quads[idx]; return overlap_quad(pos, max_distance, positions[q.x], positions[q.y], positions[q.z], positions[q.w], radius[q.x], radius[q.y], @@ -2958,12 +2932,11 @@ void sample_triangles_cdf(vector& cdf, const vector& triangles, } // Pick a point on a quad mesh uniformly. -pair sample_quads( - const vector& cdf, float re, vec2f ruv) { +pair sample_quads(const vector& cdf, float re, vec2f ruv) { return {sample_discrete(cdf, re), ruv}; } -pair sample_quads(const vector& quads, - const vector& cdf, float re, vec2f ruv) { +pair sample_quads( + const vector& quads, const vector& cdf, float re, vec2f ruv) { auto element = sample_discrete(cdf, re); if (quads[element].z == quads[element].w) { return {element, sample_triangle(ruv)}; @@ -3071,8 +3044,8 @@ namespace yocto { // Make a quad. void make_rect(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale) { positions.resize((steps.x + 1) * (steps.y + 1)); normals.resize((steps.x + 1) * (steps.y + 1)); texcoords.resize((steps.x + 1) * (steps.y + 1)); @@ -3097,8 +3070,8 @@ void make_rect(vector& quads, vector& positions, } void make_bulged_rect(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float height) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float height) { make_rect(quads, positions, normals, texcoords, steps, scale, uvscale); if (height != 0) { height = min(height, min(scale)); @@ -3114,8 +3087,8 @@ void make_bulged_rect(vector& quads, vector& positions, // Make a quad. void make_recty(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale) { make_rect(quads, positions, normals, texcoords, steps, scale, uvscale); for (auto& position : positions) position = {position.x, position.z, -position.y}; @@ -3123,8 +3096,8 @@ void make_recty(vector& quads, vector& positions, } void make_bulged_recty(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float height) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float height) { make_bulged_rect( quads, positions, normals, texcoords, steps, scale, uvscale, height); for (auto& position : positions) @@ -3134,8 +3107,8 @@ void make_bulged_recty(vector& quads, vector& positions, // Make a cube. void make_box(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec3f uvscale) { + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec3f uvscale) { quads.clear(); positions.clear(); normals.clear(); @@ -3193,8 +3166,8 @@ void make_box(vector& quads, vector& positions, } void make_rounded_box(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec3f uvscale, float radius) { + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec3f uvscale, float radius) { make_box(quads, positions, normals, texcoords, steps, scale, uvscale); if (radius != 0) { radius = min(radius, min(scale)); @@ -3230,8 +3203,8 @@ void make_rounded_box(vector& quads, vector& positions, } void make_rect_stack(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec2f uvscale) { auto qquads = vector{}; auto qpositions = vector{}; auto qnormals = vector{}; @@ -3246,8 +3219,8 @@ void make_rect_stack(vector& quads, vector& positions, } void make_floor(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale) { make_rect(quads, positions, normals, texcoords, steps, scale, uvscale); for (auto& position : positions) position = {position.x, position.z, -position.y}; @@ -3255,8 +3228,8 @@ void make_floor(vector& quads, vector& positions, } void make_bent_floor(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float radius) { + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float radius) { make_floor(quads, positions, normals, texcoords, steps, scale, uvscale); if (radius != 0) { radius = min(radius, scale.y); @@ -3290,8 +3263,8 @@ void make_sphere(vector& quads, vector& positions, // Generate a uvsphere void make_uvsphere(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale) { make_rect(quads, positions, normals, texcoords, steps, {1, 1}, {1, 1}); for (auto i : range(positions.size())) { auto uv = texcoords[i]; @@ -3304,8 +3277,8 @@ void make_uvsphere(vector& quads, vector& positions, } void make_capped_uvsphere(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale, float cap) { + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale, float cap) { make_uvsphere(quads, positions, normals, texcoords, steps, scale, uvscale); if (cap != 0) { cap = min(cap, scale / 2); @@ -3326,8 +3299,8 @@ void make_capped_uvsphere(vector& quads, vector& positions, // Generate a uvsphere void make_uvspherey(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale) { make_uvsphere(quads, positions, normals, texcoords, steps, scale, uvscale); for (auto& position : positions) position = {position.x, position.z, position.y}; @@ -3337,8 +3310,8 @@ void make_uvspherey(vector& quads, vector& positions, } void make_capped_uvspherey(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale, float cap) { + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale, float cap) { make_capped_uvsphere( quads, positions, normals, texcoords, steps, scale, uvscale, cap); for (auto& position : positions) @@ -3382,8 +3355,8 @@ void make_bulged_disk(vector& quads, vector& positions, // Generate a uvdisk void make_uvdisk(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale) { make_rect(quads, positions, normals, texcoords, steps, {1, 1}, {1, 1}); for (auto i : range(positions.size())) { auto uv = texcoords[i]; @@ -3396,8 +3369,8 @@ void make_uvdisk(vector& quads, vector& positions, // Generate a uvcylinder void make_uvcylinder(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec2f scale, vec3f uvscale) { + vector& normals, vector& texcoords, vec3i steps, vec2f scale, + vec3f uvscale) { auto qquads = vector{}; auto qpositions = vector{}; auto qnormals = vector{}; @@ -3448,8 +3421,8 @@ void make_uvcylinder(vector& quads, vector& positions, // Generate a uvcylinder void make_rounded_uvcylinder(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec2f scale, vec3f uvscale, float radius) { + vector& normals, vector& texcoords, vec3i steps, vec2f scale, + vec3f uvscale, float radius) { make_uvcylinder(quads, positions, normals, texcoords, steps, scale, uvscale); if (radius != 0) { radius = min(radius, min(scale)); @@ -3475,8 +3448,7 @@ void make_rounded_uvcylinder(vector& quads, vector& positions, // Generate lines set along a quad. void make_lines(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, - vec2i steps, vec2f size, vec2f uvscale, - vec2f rad) { + vec2i steps, vec2f size, vec2f uvscale, vec2f rad) { positions.resize((steps.x + 1) * steps.y); normals.resize((steps.x + 1) * steps.y); texcoords.resize((steps.x + 1) * steps.y); @@ -3540,8 +3512,7 @@ void make_points(vector& points, vector& positions, // Generate a point set along a quad. void make_points(vector& points, vector& positions, vector& normals, vector& texcoords, vector& radius, - vec2i steps, vec2f size, vec2f uvscale, - vec2f rad) { + vec2i steps, vec2f size, vec2f uvscale, vec2f rad) { auto quads = vector{}; make_rect(quads, positions, normals, texcoords, steps, size, uvscale); points.resize(positions.size()); @@ -3554,8 +3525,7 @@ void make_points(vector& points, vector& positions, // Generate a point set. void make_random_points(vector& points, vector& positions, vector& normals, vector& texcoords, vector& radius, - int num, vec3f size, float uvscale, float point_radius, - uint64_t seed) { + int num, vec3f size, float uvscale, float point_radius, uint64_t seed) { make_points(points, positions, normals, texcoords, radius, num, uvscale, point_radius); auto rng = make_rng(seed); @@ -3581,16 +3551,16 @@ void make_bezier_circle( // Make fvquad void make_fvrect(vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f size, vec2f uvscale) { + vector& normals, vector& texcoords, vec2i steps, vec2f size, + vec2f uvscale) { make_rect(quadspos, positions, normals, texcoords, steps, size, uvscale); quadsnorm = quadspos; quadstexcoord = quadspos; } void make_fvbox(vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f size, vec3f uvscale) { + vector& normals, vector& texcoords, vec3i steps, vec3f size, + vec3f uvscale) { make_box(quadspos, positions, normals, texcoords, steps, size, uvscale); quadsnorm = quadspos; quadstexcoord = quadspos; @@ -3795,9 +3765,8 @@ void make_hair(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, const vector& striangles, const vector& squads, const vector& spos, const vector& snorm, - const vector& stexcoord, vec2i steps, vec2f len, - vec2f rad, vec2f noise, vec2f clump, - vec2f rotation, int seed) { + const vector& stexcoord, vec2i steps, vec2f len, vec2f rad, + vec2f noise, vec2f clump, vec2f rotation, int seed) { auto alltriangles = striangles; auto quads_triangles = quads_to_triangles(squads); alltriangles.insert( @@ -3867,8 +3836,8 @@ void make_hair2(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, const vector& striangles, const vector& squads, const vector& spos, const vector& snorm, - const vector& stexcoord, vec2i steps, vec2f len, - vec2f rad, float noise, float gravity, int seed) { + const vector& stexcoord, vec2i steps, vec2f len, vec2f rad, + float noise, float gravity, int seed) { auto alltriangles = striangles; auto quads_triangles = quads_to_triangles(squads); alltriangles.insert( diff --git a/libs/yocto/yocto_shape.h b/libs/yocto/yocto_shape.h index b2e667c1d..7c05d328b 100644 --- a/libs/yocto/yocto_shape.h +++ b/libs/yocto/yocto_shape.h @@ -117,8 +117,8 @@ struct shape_point { // Shape sampling vector sample_shape_cdf(const shape_data& shape); void sample_shape_cdf(vector& cdf, const shape_data& shape); -shape_point sample_shape(const shape_data& shape, const vector& cdf, - float rn, vec2f ruv); +shape_point sample_shape( + const shape_data& shape, const vector& cdf, float rn, vec2f ruv); vector sample_shape( const shape_data& shape, int num_samples, uint64_t seed = 98729387); @@ -215,39 +215,35 @@ vector fvshape_stats(const fvshape_data& shape, bool verbose = false); namespace yocto { // Make a plane. -shape_data make_rect(vec2i steps = {1, 1}, vec2f scale = {1, 1}, - vec2f uvscale = {1, 1}); -shape_data make_bulged_rect(vec2i steps = {1, 1}, - vec2f scale = {1, 1}, vec2f uvscale = {1, 1}, - float radius = 0.3f); +shape_data make_rect( + vec2i steps = {1, 1}, vec2f scale = {1, 1}, vec2f uvscale = {1, 1}); +shape_data make_bulged_rect(vec2i steps = {1, 1}, vec2f scale = {1, 1}, + vec2f uvscale = {1, 1}, float radius = 0.3f); // Make a plane in the xz plane. -shape_data make_recty(vec2i steps = {1, 1}, vec2f scale = {1, 1}, - vec2f uvscale = {1, 1}); -shape_data make_bulged_recty(vec2i steps = {1, 1}, - vec2f scale = {1, 1}, vec2f uvscale = {1, 1}, - float radius = 0.3f); +shape_data make_recty( + vec2i steps = {1, 1}, vec2f scale = {1, 1}, vec2f uvscale = {1, 1}); +shape_data make_bulged_recty(vec2i steps = {1, 1}, vec2f scale = {1, 1}, + vec2f uvscale = {1, 1}, float radius = 0.3f); // Make a box. -shape_data make_box(vec3i steps = {1, 1, 1}, - vec3f scale = {1, 1, 1}, vec3f uvscale = {1, 1, 1}); -shape_data make_rounded_box(vec3i steps = {1, 1, 1}, - vec3f scale = {1, 1, 1}, vec3f uvscale = {1, 1, 1}, - float radius = 0.3f); +shape_data make_box(vec3i steps = {1, 1, 1}, vec3f scale = {1, 1, 1}, + vec3f uvscale = {1, 1, 1}); +shape_data make_rounded_box(vec3i steps = {1, 1, 1}, vec3f scale = {1, 1, 1}, + vec3f uvscale = {1, 1, 1}, float radius = 0.3f); // Make a quad stack -shape_data make_rect_stack(vec3i steps = {1, 1, 1}, - vec3f scale = {1, 1, 1}, vec2f uvscale = {1, 1}); +shape_data make_rect_stack( + vec3i steps = {1, 1, 1}, vec3f scale = {1, 1, 1}, vec2f uvscale = {1, 1}); // Make a floor. -shape_data make_floor(vec2i steps = {1, 1}, - vec2f scale = {10, 10}, vec2f uvscale = {10, 10}); -shape_data make_bent_floor(vec2i steps = {1, 1}, - vec2f scale = {10, 10}, vec2f uvscale = {10, 10}, - float bent = 0.5f); +shape_data make_floor( + vec2i steps = {1, 1}, vec2f scale = {10, 10}, vec2f uvscale = {10, 10}); +shape_data make_bent_floor(vec2i steps = {1, 1}, vec2f scale = {10, 10}, + vec2f uvscale = {10, 10}, float bent = 0.5f); // Make a sphere. shape_data make_sphere(int steps = 32, float scale = 1, float uvscale = 1); // Make a sphere. -shape_data make_uvsphere(vec2i steps = {32, 32}, float scale = 1, - vec2f uvscale = {1, 1}); -shape_data make_uvspherey(vec2i steps = {32, 32}, float scale = 1, - vec2f uvscale = {1, 1}); +shape_data make_uvsphere( + vec2i steps = {32, 32}, float scale = 1, vec2f uvscale = {1, 1}); +shape_data make_uvspherey( + vec2i steps = {32, 32}, float scale = 1, vec2f uvscale = {1, 1}); // Make a sphere with slipped caps. shape_data make_capped_uvsphere(vec2i steps = {32, 32}, float scale = 1, vec2f uvscale = {1, 1}, float height = 0.3f); @@ -259,44 +255,41 @@ shape_data make_disk(int steps = 32, float scale = 1, float uvscale = 1); shape_data make_bulged_disk( int steps = 32, float scale = 1, float uvscale = 1, float height = 0.3f); // Make a uv disk -shape_data make_uvdisk(vec2i steps = {32, 32}, float scale = 1, - vec2f uvscale = {1, 1}); +shape_data make_uvdisk( + vec2i steps = {32, 32}, float scale = 1, vec2f uvscale = {1, 1}); // Make a uv cylinder -shape_data make_uvcylinder(vec3i steps = {32, 32, 32}, - vec2f scale = {1, 1}, vec3f uvscale = {1, 1, 1}); +shape_data make_uvcylinder(vec3i steps = {32, 32, 32}, vec2f scale = {1, 1}, + vec3f uvscale = {1, 1, 1}); // Make a rounded uv cylinder shape_data make_rounded_uvcylinder(vec3i steps = {32, 32, 32}, - vec2f scale = {1, 1}, vec3f uvscale = {1, 1, 1}, - float radius = 0.3f); + vec2f scale = {1, 1}, vec3f uvscale = {1, 1, 1}, float radius = 0.3f); // Make a uv capsule -shape_data make_uvcapsule(vec3i steps = {32, 32, 32}, - vec2f scale = {1, 1}, vec3f uvscale = {1, 1, 1}); +shape_data make_uvcapsule(vec3i steps = {32, 32, 32}, vec2f scale = {1, 1}, + vec3f uvscale = {1, 1, 1}); // Make a uv cone -shape_data make_uvcone(vec3i steps = {32, 32, 32}, - vec2f scale = {1, 1}, vec3f uvscale = {1, 1, 1}); +shape_data make_uvcone(vec3i steps = {32, 32, 32}, vec2f scale = {1, 1}, + vec3f uvscale = {1, 1, 1}); // Make a facevarying rect -fvshape_data make_fvrect(vec2i steps = {1, 1}, - vec2f scale = {1, 1}, vec2f uvscale = {1, 1}); +fvshape_data make_fvrect( + vec2i steps = {1, 1}, vec2f scale = {1, 1}, vec2f uvscale = {1, 1}); // Make a facevarying box -fvshape_data make_fvbox(vec3i steps = {1, 1, 1}, - vec3f scale = {1, 1, 1}, vec3f uvscale = {1, 1, 1}); +fvshape_data make_fvbox(vec3i steps = {1, 1, 1}, vec3f scale = {1, 1, 1}, + vec3f uvscale = {1, 1, 1}); // Make a facevarying sphere fvshape_data make_fvsphere(int steps = 32, float scale = 1, float uvscale = 1); // Generate lines set along a quad. Returns lines, pos, norm, texcoord, radius. -shape_data make_lines(int num = 65536, int steps = 4, - vec2f scale = {1, 1}, vec2f uvscale = {1, 1}, - vec2f radius = {0.001f, 0.001f}); +shape_data make_lines(int num = 65536, int steps = 4, vec2f scale = {1, 1}, + vec2f uvscale = {1, 1}, vec2f radius = {0.001f, 0.001f}); // Make a point primitive. Returns points, pos, norm, texcoord, radius. shape_data make_point(float radius = 0.001f); // Make a point set on a grid. Returns points, pos, norm, texcoord, radius. shape_data make_points( int num = 65536, float uvscale = 1, float radius = 0.001f); -shape_data make_points(vec2i steps = {256, 256}, - vec2f size = {1, 1}, vec2f uvscale = {1, 1}, - vec2f radius = {0.001f, 0.001f}); +shape_data make_points(vec2i steps = {256, 256}, vec2f size = {1, 1}, + vec2f uvscale = {1, 1}, vec2f radius = {0.001f, 0.001f}); // Make random points in a cube. Returns points, pos, norm, texcoord, radius. shape_data make_random_points(int num = 65536, vec3f size = {1, 1, 1}, float uvscale = 1, float radius = 0.001f, uint64_t seed = 17); @@ -317,8 +310,8 @@ shape_data make_geosphere(int subdivisions = 0, float scale = 1); // rotation: rotation added to hair (angle/strength) shape_data make_hair(const shape_data& shape, vec2i steps = {8, 65536}, vec2f length = {0.1f, 0.1f}, vec2f radius = {0.001f, 0.001f}, - vec2f noise = {0, 10}, vec2f clump = {0, 128}, - vec2f rotation = {0, 0}, int seed = 7); + vec2f noise = {0, 10}, vec2f clump = {0, 128}, vec2f rotation = {0, 0}, + int seed = 7); // Grow hairs around a shape shape_data make_hair2(const shape_data& shape, vec2i steps = {8, 65536}, @@ -327,9 +320,8 @@ shape_data make_hair2(const shape_data& shape, vec2i steps = {8, 65536}, // Grow hairs around a shape shape_data make_random_hairs(const shape_data& shape, int num = 65536, - int steps = 8, vec2f length = {1, 1}, - vec2f radius = {0.01, 0.01}, float noise = 0, float gravity = 0.05, - uint64_t seed = 7); + int steps = 8, vec2f length = {1, 1}, vec2f radius = {0.01, 0.01}, + float noise = 0, float gravity = 0.05, uint64_t seed = 7); // Grow points around a shape shape_data make_random_points(const shape_data& shape, int num = 65536, @@ -395,8 +387,7 @@ vector flip_normals(const vector& normals); vector flip_triangles(const vector& triangles); vector flip_quads(const vector& quads); // Align vertex positions. Alignment is 0: none, 1: min, 2: max, 3: center. -vector align_vertices( - const vector& positions, vec3i alignment); +vector align_vertices(const vector& positions, vec3i alignment); } // namespace yocto @@ -700,10 +691,9 @@ void sample_triangles_cdf(vector& cdf, const vector& triangles, const vector& positions); // Pick a point on a quad mesh uniformly. -pair sample_quads( - const vector& cdf, float re, vec2f ruv); -vector sample_quads_cdf( - const vector& quads, const vector& positions); +pair sample_quads(const vector& cdf, float re, vec2f ruv); +vector sample_quads_cdf( + const vector& quads, const vector& positions); void sample_quads_cdf(vector& cdf, const vector& quads, const vector& positions); @@ -729,51 +719,51 @@ namespace yocto { // Make a quad. void make_rect(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale); void make_bulged_rect(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float height); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float height); // Make a quad. void make_recty(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale); void make_bulged_recty(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float height); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float height); // Make a cube. void make_box(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec3f uvscale); + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec3f uvscale); void make_rounded_box(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec3f uvscale, float radius); + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec3f uvscale, float radius); void make_rect_stack(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f scale, vec2f uvscale); + vector& normals, vector& texcoords, vec3i steps, vec3f scale, + vec2f uvscale); void make_floor(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale); void make_bent_floor(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f scale, vec2f uvscale, float radius); + vector& normals, vector& texcoords, vec2i steps, vec2f scale, + vec2f uvscale, float radius); // Generate a sphere void make_sphere(vector& quads, vector& positions, vector& normals, vector& texcoords, int steps, float scale, float uvscale); // Generate a uvsphere void make_uvsphere(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale); void make_capped_uvsphere(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale, float cap); + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale, float cap); void make_uvspherey(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale); void make_capped_uvspherey(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale, float cap); + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale, float cap); // Generate a disk void make_disk(vector& quads, vector& positions, vector& normals, vector& texcoords, int steps, float scale, @@ -783,22 +773,21 @@ void make_bulged_disk(vector& quads, vector& positions, float uvscale, float height); // Generate a uvdisk void make_uvdisk(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - float scale, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, float scale, + vec2f uvscale); // Generate a uvcylinder void make_uvcylinder(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec2f scale, vec3f uvscale); + vector& normals, vector& texcoords, vec3i steps, vec2f scale, + vec3f uvscale); // Generate a uvcylinder void make_rounded_uvcylinder(vector& quads, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec2f scale, vec3f uvscale, float radius); + vector& normals, vector& texcoords, vec3i steps, vec2f scale, + vec3f uvscale, float radius); // Generate lines set along a quad. void make_lines(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, - vec2i steps, vec2f size, vec2f uvscale, - vec2f rad); + vec2i steps, vec2f size, vec2f uvscale, vec2f rad); // Generate a point at the origin. void make_point(vector& points, vector& positions, @@ -814,14 +803,12 @@ void make_points(vector& points, vector& positions, // Generate a point set along a quad. void make_points(vector& points, vector& positions, vector& normals, vector& texcoords, vector& radius, - vec2i steps, vec2f size, vec2f uvscale, - vec2f rad); + vec2i steps, vec2f size, vec2f uvscale, vec2f rad); // Generate a point set. void make_random_points(vector& points, vector& positions, vector& normals, vector& texcoords, vector& radius, - int num, vec3f size, float uvscale, float point_radius, - uint64_t seed); + int num, vec3f size, float uvscale, float point_radius, uint64_t seed); // Make a bezier circle. Returns bezier, pos. void make_bezier_circle( @@ -830,12 +817,12 @@ void make_bezier_circle( // Make fvquad void make_fvrect(vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, - vector& normals, vector& texcoords, vec2i steps, - vec2f size, vec2f uvscale); + vector& normals, vector& texcoords, vec2i steps, vec2f size, + vec2f uvscale); void make_fvbox(vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, - vector& normals, vector& texcoords, vec3i steps, - vec3f size, vec3f uvscale); + vector& normals, vector& texcoords, vec3i steps, vec3f size, + vec3f uvscale); void make_fvsphere(vector& quadspos, vector& quadsnorm, vector& quadstexcoord, vector& positions, vector& normals, vector& texcoords, int steps, float size, @@ -882,17 +869,16 @@ void make_hair(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, const vector& striangles, const vector& squads, const vector& spos, const vector& snorm, - const vector& stexcoord, vec2i steps, vec2f len, - vec2f rad, vec2f noise, vec2f clump, - vec2f rotation, int seed); + const vector& stexcoord, vec2i steps, vec2f len, vec2f rad, + vec2f noise, vec2f clump, vec2f rotation, int seed); // Grow hairs around a shape void make_hair2(vector& lines, vector& positions, vector& normals, vector& texcoords, vector& radius, const vector& striangles, const vector& squads, const vector& spos, const vector& snorm, - const vector& stexcoord, vec2i steps, vec2f len, - vec2f rad, float noise, float gravity, int seed); + const vector& stexcoord, vec2i steps, vec2f len, vec2f rad, + float noise, float gravity, int seed); // Thickens a shape by copy9ing the shape content, rescaling it and flipping // its normals. Note that this is very much not robust and only useful for diff --git a/libs/yocto/yocto_trace.cpp b/libs/yocto/yocto_trace.cpp index a79412b83..7507ceebf 100644 --- a/libs/yocto/yocto_trace.cpp +++ b/libs/yocto/yocto_trace.cpp @@ -149,8 +149,8 @@ static scene_intersection intersect_instance(const trace_bvh& bvh, namespace yocto { // Evaluates/sample the BRDF scaled by the cosine of the incoming direction. -static vec3f eval_emission(const material_point& material, vec3f normal, - vec3f outgoing) { +static vec3f eval_emission( + const material_point& material, vec3f normal, vec3f outgoing) { return dot(normal, outgoing) >= 0 ? material.emission : vec3f{0, 0, 0}; } @@ -233,8 +233,8 @@ static vec3f sample_bsdfcos(const material_point& material, vec3f normal, } } -static vec3f sample_delta(const material_point& material, vec3f normal, - vec3f outgoing, float rnl) { +static vec3f sample_delta( + const material_point& material, vec3f normal, vec3f outgoing, float rnl) { if (material.roughness != 0) return {0, 0, 0}; if (material.type == material_type::reflective) { @@ -253,8 +253,8 @@ static vec3f sample_delta(const material_point& material, vec3f normal, } // Compute the weight for sampling the BRDF -static float sample_bsdfcos_pdf(const material_point& material, - vec3f normal, vec3f outgoing, vec3f incoming) { +static float sample_bsdfcos_pdf(const material_point& material, vec3f normal, + vec3f outgoing, vec3f incoming) { if (material.roughness == 0) return 0; if (material.type == material_type::matte) { @@ -282,8 +282,8 @@ static float sample_bsdfcos_pdf(const material_point& material, } } -static float sample_delta_pdf(const material_point& material, - vec3f normal, vec3f outgoing, vec3f incoming) { +static float sample_delta_pdf(const material_point& material, vec3f normal, + vec3f outgoing, vec3f incoming) { if (material.roughness != 0) return 0; if (material.type == material_type::reflective) { @@ -301,21 +301,21 @@ static float sample_delta_pdf(const material_point& material, } } -static vec3f eval_scattering(const material_point& material, - vec3f outgoing, vec3f incoming) { +static vec3f eval_scattering( + const material_point& material, vec3f outgoing, vec3f incoming) { if (material.density == vec3f{0, 0, 0}) return {0, 0, 0}; return material.scattering * material.density * eval_phasefunction(material.scanisotropy, outgoing, incoming); } -static vec3f sample_scattering(const material_point& material, - vec3f outgoing, float rnl, vec2f rn) { +static vec3f sample_scattering( + const material_point& material, vec3f outgoing, float rnl, vec2f rn) { if (material.density == vec3f{0, 0, 0}) return {0, 0, 0}; return sample_phasefunction(material.scanisotropy, outgoing, rn); } -static float sample_scattering_pdf(const material_point& material, - vec3f outgoing, vec3f incoming) { +static float sample_scattering_pdf( + const material_point& material, vec3f outgoing, vec3f incoming) { if (material.density == vec3f{0, 0, 0}) return 0; return sample_phasefunction_pdf(material.scanisotropy, outgoing, incoming); }