Page MenuHome

Geometry Nodes: Add Voronoi Texture
ClosedPublic

Authored by Charlie Jolly (charlie) on Oct 1 2021, 11:54 AM.

Diff Detail

Repository
rB Blender
Branch
master
Build Status
Buildable 17499
Build 17499: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Charlie Jolly (charlie) requested review of this revision.Oct 1 2021, 11:54 AM

This is in a working state but I'm happy if one of the core devs takes it over as it may be more efficient than a code review.

Add missing input clamping for randomness and smoothness

Jacques Lucke (JacquesLucke) requested changes to this revision.Oct 1 2021, 1:53 PM

Lots of warnings: P2468.
Would be nice if you could provide a test file to see that it matches cycles.
Still thinking about how the amount of code can be reduced a bit...

source/blender/blenlib/BLI_noise.hh
58

Use r_color and r_w as parameter names.

source/blender/blenlib/intern/noise.cc
887

Should use const whenever possible.

915

There is a division by zero here when smoothness is zero.

This revision now requires changes to proceed.Oct 1 2021, 1:53 PM
Charlie Jolly (charlie) marked 2 inline comments as done.Oct 1 2021, 2:17 PM
Charlie Jolly (charlie) marked an inline comment as done.Oct 1 2021, 2:27 PM
Charlie Jolly (charlie) updated this revision to Diff 42792.EditedOct 1 2021, 5:23 PM

Address comments. All the modes are working but there is a bug causing different output to Cycles/Eevee.

File used for validating noise:

Fixed bug and compatibilty with Cycles. The hash_float_to_float functions in noise.cc work differently but are named the same. Added compatible hash functions with shd_ prefix.

Jacques Lucke (JacquesLucke) requested changes to this revision.Oct 3 2021, 1:35 PM

I see that the noise functions are different, my question is whether we need to different noise functions with the same interface, or if we can get rid of some of the functions I added in rBd8a5b768f0763dab725401460e229787d080476a instead.
Also, all of the math functions like distance/len/... shouldn't be defined in noise.cc, but in their corresponding header.

This revision now requires changes to proceed.Oct 3 2021, 1:35 PM

Fix 1d. Tidy up math functions, use built in where possible.

I see that the noise functions are different, my question is whether we need to different noise functions with the same interface, or if we can get rid of some of the functions I added in rBd8a5b768f0763dab725401460e229787d080476a instead.
Also, all of the math functions like distance/len/... shouldn't be defined in noise.cc, but in their corresponding header.

For the Voronoi/White Noise, we need the compatible hash functions. I don't know if they are slower/faster/better than the ones you added. The ones you added are in use in node_geo_distribute_points_on_faces.cc.

Charlie Jolly (charlie) updated this revision to Diff 42850.EditedOct 3 2021, 3:28 PM

Move math functions out of noise.cc

Following file was used to compare the output with Cycles.

The same hash functions are used in D12719: Geometry Nodes: Add White Noise texture.

source/blender/blenlib/BLI_float4.hh
83

Add an assert that checks that f != 0.0f.

132

This has to handle the case when a is zero.

source/blender/blenlib/BLI_noise.hh
54

Did you consider removing these functions now? They are only used in the distribute node, but it is fine when we change the distribution still. The goal is to not need the shd prefix in the functions below.

71

Use a header like

/* --------------------------------------------------------------------
 * Voronoi noise.
 */
72

The 1d, 2d, ... doesn't have to be part of the function name if I'm not mistaken. This can be handled by c++ overloading. This is also used in the perlin noise functions below.

source/blender/blenlib/intern/noise.cc
822–823

Use const whenever possible here.

1180

Hm, we should be careful with using enums defined in DNA in blenlib...
Should be fine for now, but maybe we want to have a separate enum in BLI_noise.hh in the future.

1183

Use a switch statement and use BLI_assert_unreachable when an invalid metric is passed in.

Charlie Jolly (charlie) marked 8 inline comments as done.Oct 3 2021, 8:01 PM
Charlie Jolly (charlie) added inline comments.
source/blender/blenlib/BLI_noise.hh
54

Yes, swapped for shd compatible.

source/blender/blenlib/intern/noise.cc
1180

Used a local enum with a prefix and comment to keep aligned with DNA.

Charlie Jolly (charlie) marked 2 inline comments as done.

Address comments. Rename and use shader compatible hash functions.

@Omar Emara (OmarSquircleArt) I've added you as a reviewer as the Voronoi code is originally your patch.

Charlie Jolly (charlie) updated this revision to Diff 43122.EditedOct 11 2021, 11:00 AM

Update to master.

The changes to float hash also fix T92103.

Jacques Lucke (JacquesLucke) requested changes to this revision.Oct 14 2021, 3:21 PM

Some warnings: P2500.

A simple way to reduce the duplication a little bit for now is to add some lambdas like:

auto get_vector = [&](int param_index) -> const VArray<float3> & {
    return params.readonly_single_input<float3>(param_index, "Vector");
};

Same for the other parameters. These lambdas can then be used in all the different cases.
More things can be improved in the future, but with this change I think this is good enough.

This revision now requires changes to proceed.Oct 14 2021, 3:21 PM
Charlie Jolly (charlie) updated this revision to Diff 43343.EditedOct 14 2021, 11:48 PM

Address comments and dedupe.

Jacques Lucke (JacquesLucke) requested changes to this revision.Oct 15 2021, 11:16 AM
Jacques Lucke (JacquesLucke) added inline comments.
source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
256

This is not exactly what I meant unfortunately. Sorry for being not precise enough.
In the current state this adds unnecessary overhead, because e.g. get_vec is called for every index in the mask.

You'd still have to do this above the loops:

const VArray<float3> &vectors = get_vec(0);
/* ... */
MutableSpan<float> r_distance = get_r_distance(4);
This revision now requires changes to proceed.Oct 15 2021, 11:16 AM
Charlie Jolly (charlie) marked an inline comment as done.Oct 15 2021, 11:43 AM

Use lambdas for ouputs and use param++ for socket number.
Use more verbose variable names. E.g. r_pos > r_position.

Conistency, get_smooth > get_smoothness

When Smoothness is set to exactly, the result seems unexpected. The values become much larger suddenly. Not sure if this is the same in shading.

Besides that, looks good in my tests.

source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
241

Should be called get_r_distance, instead of set_distance. Same for the other lambdas.

Charlie Jolly (charlie) marked an inline comment as done.Oct 15 2021, 2:03 PM

Fix issue with smoothness. Bizarrely the function seems to rely on non-safe division. Since this is the same code as shader, this could be looked at later.

This revision is now accepted and ready to land.Oct 15 2021, 4:23 PM
This revision was automatically updated to reflect the committed changes.