Fix T79803: Wrong Distance To Edge 1D Voronoi
The current 1D Voronoi implementation for the Distance to Edge option computes the distance to the cells instead. This patch fixes that and compute the distance to the edge. Reviewed By: JacquesLucke, brecht Differential Revision: https://developer.blender.org/D8634
This commit is contained in:
parent
d2c52d4de2
commit
340cbc7f15
|
@ -175,14 +175,13 @@ void voronoi_distance_to_edge_1d(float w, float randomness, output float outDist
|
||||||
float cellPosition = floor(w);
|
float cellPosition = floor(w);
|
||||||
float localPosition = w - cellPosition;
|
float localPosition = w - cellPosition;
|
||||||
|
|
||||||
float minDistance = 8.0;
|
float midPointPosition = hash_float_to_float(cellPosition) * randomness;
|
||||||
for (int i = -1; i <= 1; i++) {
|
float leftPointPosition = -1.0 + hash_float_to_float(cellPosition - 1.0) * randomness;
|
||||||
float cellOffset = float(i);
|
float rightPointPosition = 1.0 + hash_float_to_float(cellPosition + 1.0) * randomness;
|
||||||
float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
|
float distanceToMidLeft = distance((midPointPosition + leftPointPosition) / 2.0, localPosition);
|
||||||
float distanceToPoint = distance(pointPosition, localPosition);
|
float distanceToMidRight = distance((midPointPosition + rightPointPosition) / 2.0, localPosition);
|
||||||
minDistance = min(distanceToPoint, minDistance);
|
|
||||||
}
|
outDistance = min(distanceToMidLeft, distanceToMidRight);
|
||||||
outDistance = minDistance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void voronoi_n_sphere_radius_1d(float w, float randomness, output float outRadius)
|
void voronoi_n_sphere_radius_1d(float w, float randomness, output float outRadius)
|
||||||
|
|
|
@ -144,14 +144,13 @@ ccl_device void voronoi_distance_to_edge_1d(float w, float randomness, float *ou
|
||||||
float cellPosition = floorf(w);
|
float cellPosition = floorf(w);
|
||||||
float localPosition = w - cellPosition;
|
float localPosition = w - cellPosition;
|
||||||
|
|
||||||
float minDistance = 8.0f;
|
float midPointPosition = hash_float_to_float(cellPosition) * randomness;
|
||||||
for (int i = -1; i <= 1; i++) {
|
float leftPointPosition = -1.0f + hash_float_to_float(cellPosition - 1.0f) * randomness;
|
||||||
float cellOffset = i;
|
float rightPointPosition = 1.0f + hash_float_to_float(cellPosition + 1.0f) * randomness;
|
||||||
float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
|
float distanceToMidLeft = fabsf((midPointPosition + leftPointPosition) / 2.0f - localPosition);
|
||||||
float distanceToPoint = fabsf(pointPosition - localPosition);
|
float distanceToMidRight = fabsf((midPointPosition + rightPointPosition) / 2.0f - localPosition);
|
||||||
minDistance = min(distanceToPoint, minDistance);
|
|
||||||
}
|
*outDistance = min(distanceToMidLeft, distanceToMidRight);
|
||||||
*outDistance = minDistance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ccl_device void voronoi_n_sphere_radius_1d(float w, float randomness, float *outRadius)
|
ccl_device void voronoi_n_sphere_radius_1d(float w, float randomness, float *outRadius)
|
||||||
|
|
|
@ -158,14 +158,13 @@ void node_tex_voronoi_distance_to_edge_1d(vec3 coord,
|
||||||
float cellPosition = floor(scaledCoord);
|
float cellPosition = floor(scaledCoord);
|
||||||
float localPosition = scaledCoord - cellPosition;
|
float localPosition = scaledCoord - cellPosition;
|
||||||
|
|
||||||
float minDistance = 8.0;
|
float midPointPosition = hash_float_to_float(cellPosition) * randomness;
|
||||||
for (int i = -1; i <= 1; i++) {
|
float leftPointPosition = -1.0 + hash_float_to_float(cellPosition - 1.0) * randomness;
|
||||||
float cellOffset = float(i);
|
float rightPointPosition = 1.0 + hash_float_to_float(cellPosition + 1.0) * randomness;
|
||||||
float pointPosition = cellOffset + hash_float_to_float(cellPosition + cellOffset) * randomness;
|
float distanceToMidLeft = distance((midPointPosition + leftPointPosition) / 2.0, localPosition);
|
||||||
float distanceToPoint = voronoi_distance(pointPosition, localPosition, metric, exponent);
|
float distanceToMidRight = distance((midPointPosition + rightPointPosition) / 2.0, localPosition);
|
||||||
minDistance = min(distanceToPoint, minDistance);
|
|
||||||
}
|
outDistance = min(distanceToMidLeft, distanceToMidRight);
|
||||||
outDistance = minDistance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_tex_voronoi_n_sphere_radius_1d(vec3 coord,
|
void node_tex_voronoi_n_sphere_radius_1d(vec3 coord,
|
||||||
|
|
Loading…
Reference in New Issue