Fix #119797: Noise Texture Precision Issues #119884
|
@ -7,76 +7,86 @@
|
|||
|
||||
#define vector3 point
|
||||
|
||||
float safe_noise(float p)
|
||||
float safe_noise(float co)
|
||||
{
|
||||
float f = noise("noise", p);
|
||||
if (isinf(f)) {
|
||||
return 0.5;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
float p = fmod(co, 100000.0);
|
||||
|
||||
return noise("noise", p);
|
||||
}
|
||||
|
||||
float safe_noise(vector2 p)
|
||||
float safe_noise(vector2 co)
|
||||
{
|
||||
float f = noise("noise", p.x, p.y);
|
||||
if (isinf(f)) {
|
||||
return 0.5;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector2 p = vector2(fmod(co.x, 100000.0), fmod(co.y, 100000.0));
|
||||
|
||||
return noise("noise", p.x, p.y);
|
||||
}
|
||||
|
||||
float safe_noise(vector3 p)
|
||||
float safe_noise(vector3 co)
|
||||
{
|
||||
float f = noise("noise", p);
|
||||
if (isinf(f)) {
|
||||
return 0.5;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector3 p = vector3(fmod(co.x, 100000.0), fmod(co.y, 100000.0), fmod(co.z, 100000.0));
|
||||
Hoshinova marked this conversation as resolved
|
||||
|
||||
return noise("noise", p);
|
||||
}
|
||||
|
||||
float safe_noise(vector4 p)
|
||||
float safe_noise(vector4 co)
|
||||
{
|
||||
float f = noise("noise", vector3(p.x, p.y, p.z), p.w);
|
||||
if (isinf(f)) {
|
||||
return 0.5;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector4 p = vector4(
|
||||
fmod(co.x, 100000.0), fmod(co.y, 100000.0), fmod(co.z, 100000.0), fmod(co.w, 100000.0));
|
||||
|
||||
return noise("noise", vector3(p.x, p.y, p.z), p.w);
|
||||
}
|
||||
|
||||
float safe_snoise(float p)
|
||||
float safe_snoise(float co)
|
||||
{
|
||||
float f = noise("snoise", p);
|
||||
if (isinf(f)) {
|
||||
return 0.0;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
float p = fmod(co, 100000.0);
|
||||
|
||||
return noise("snoise", p);
|
||||
}
|
||||
|
||||
float safe_snoise(vector2 p)
|
||||
float safe_snoise(vector2 co)
|
||||
{
|
||||
float f = noise("snoise", p.x, p.y);
|
||||
if (isinf(f)) {
|
||||
return 0.0;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector2 p = vector2(fmod(co.x, 100000.0), fmod(co.y, 100000.0));
|
||||
|
||||
return noise("snoise", p.x, p.y);
|
||||
}
|
||||
|
||||
float safe_snoise(vector3 p)
|
||||
float safe_snoise(vector3 co)
|
||||
{
|
||||
float f = noise("snoise", p);
|
||||
if (isinf(f)) {
|
||||
return 0.0;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector3 p = vector3(fmod(co.x, 100000.0), fmod(co.y, 100000.0), fmod(co.z, 100000.0));
|
||||
|
||||
return noise("snoise", p);
|
||||
}
|
||||
|
||||
float safe_snoise(vector4 p)
|
||||
float safe_snoise(vector4 co)
|
||||
{
|
||||
float f = noise("snoise", vector3(p.x, p.y, p.z), p.w);
|
||||
if (isinf(f)) {
|
||||
return 0.0;
|
||||
}
|
||||
return f;
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
vector4 p = vector4(
|
||||
fmod(co.x, 100000.0), fmod(co.y, 100000.0), fmod(co.z, 100000.0), fmod(co.w, 100000.0));
|
||||
|
||||
return noise("snoise", vector3(p.x, p.y, p.z), p.w);
|
||||
}
|
||||
|
||||
#define NOISE_FBM(T) \
|
||||
|
|
|
@ -684,7 +684,12 @@ ccl_device_inline float noise_scale4(float result)
|
|||
|
||||
ccl_device_inline float snoise_1d(float p)
|
||||
{
|
||||
return noise_scale1(ensure_finite(perlin_1d(p)));
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
p = fmodf(p, 100000.0f);
|
||||
|
||||
return noise_scale1(perlin_1d(p));
|
||||
}
|
||||
|
||||
ccl_device_inline float noise_1d(float p)
|
||||
|
@ -694,7 +699,12 @@ ccl_device_inline float noise_1d(float p)
|
|||
|
||||
ccl_device_inline float snoise_2d(float2 p)
|
||||
{
|
||||
return noise_scale2(ensure_finite(perlin_2d(p.x, p.y)));
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
p = make_float2(fmodf(p.x, 100000.0f), fmodf(p.y, 100000.0f));
|
||||
|
||||
return noise_scale2(perlin_2d(p.x, p.y));
|
||||
}
|
||||
|
||||
ccl_device_inline float noise_2d(float2 p)
|
||||
|
@ -704,7 +714,12 @@ ccl_device_inline float noise_2d(float2 p)
|
|||
|
||||
ccl_device_inline float snoise_3d(float3 p)
|
||||
{
|
||||
return noise_scale3(ensure_finite(perlin_3d(p.x, p.y, p.z)));
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
p = make_float3(fmodf(p.x, 100000.0f), fmodf(p.y, 100000.0f), fmodf(p.z, 100000.0f));
|
||||
|
||||
return noise_scale3(perlin_3d(p.x, p.y, p.z));
|
||||
}
|
||||
|
||||
ccl_device_inline float noise_3d(float3 p)
|
||||
|
@ -714,7 +729,13 @@ ccl_device_inline float noise_3d(float3 p)
|
|||
|
||||
ccl_device_inline float snoise_4d(float4 p)
|
||||
{
|
||||
return noise_scale4(ensure_finite(perlin_4d(p.x, p.y, p.z, p.w)));
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
p = make_float4(
|
||||
fmodf(p.x, 100000.0f), fmodf(p.y, 100000.0f), fmodf(p.z, 100000.0f), fmodf(p.w, 100000.0f));
|
||||
|
||||
return noise_scale4(perlin_4d(p.x, p.y, p.z, p.w));
|
||||
}
|
||||
|
||||
ccl_device_inline float noise_4d(float4 p)
|
||||
|
|
|
@ -490,21 +490,45 @@ BLI_INLINE float perlin_noise(float4 position)
|
|||
|
||||
float perlin_signed(float position)
|
||||
{
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
position = fmodf(position, 100000.0f);
|
||||
|
||||
return perlin_noise(position) * 0.2500f;
|
||||
}
|
||||
|
||||
float perlin_signed(float2 position)
|
||||
{
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
position = float2(fmodf(position.x, 100000.0f), fmodf(position.y, 100000.0f));
|
||||
|
||||
return perlin_noise(position) * 0.6616f;
|
||||
}
|
||||
|
||||
float perlin_signed(float3 position)
|
||||
{
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
position = float3(
|
||||
fmodf(position.x, 100000.0f), fmodf(position.y, 100000.0f), fmodf(position.z, 100000.0f));
|
||||
|
||||
return perlin_noise(position) * 0.9820f;
|
||||
}
|
||||
|
||||
float perlin_signed(float4 position)
|
||||
{
|
||||
/* Repeat Perlin noise texture every 100000.0f on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0f, however at such scales
|
||||
* this usually shouldn't be noticible. */
|
||||
position = float4(fmodf(position.x, 100000.0f),
|
||||
fmodf(position.y, 100000.0f),
|
||||
fmodf(position.z, 100000.0f),
|
||||
fmodf(position.w, 100000.0f));
|
||||
|
||||
return perlin_noise(position) * 0.8344f;
|
||||
}
|
||||
|
||||
|
|
|
@ -260,8 +260,12 @@ float noise_scale4(float result)
|
|||
|
||||
float snoise(float p)
|
||||
{
|
||||
float r = noise_perlin(p);
|
||||
return (isinf(r)) ? 0.0 : noise_scale1(r);
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
p = compatible_fmod(p, 100000.0);
|
||||
|
||||
return noise_scale1(noise_perlin(p));
|
||||
}
|
||||
|
||||
float noise(float p)
|
||||
|
@ -271,8 +275,12 @@ float noise(float p)
|
|||
|
||||
float snoise(vec2 p)
|
||||
{
|
||||
float r = noise_perlin(p);
|
||||
return (isinf(r)) ? 0.0 : noise_scale2(r);
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
p = vec2(compatible_fmod(p.x, 100000.0), compatible_fmod(p.y, 100000.0));
|
||||
|
||||
return noise_scale2(noise_perlin(p));
|
||||
}
|
||||
|
||||
float noise(vec2 p)
|
||||
|
@ -282,8 +290,14 @@ float noise(vec2 p)
|
|||
|
||||
float snoise(vec3 p)
|
||||
{
|
||||
float r = noise_perlin(p);
|
||||
return (isinf(r)) ? 0.0 : noise_scale3(r);
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
p = vec3(compatible_fmod(p.x, 100000.0),
|
||||
compatible_fmod(p.y, 100000.0),
|
||||
compatible_fmod(p.z, 100000.0));
|
||||
|
||||
return noise_scale3(noise_perlin(p));
|
||||
}
|
||||
|
||||
float noise(vec3 p)
|
||||
|
@ -293,8 +307,15 @@ float noise(vec3 p)
|
|||
|
||||
float snoise(vec4 p)
|
||||
{
|
||||
float r = noise_perlin(p);
|
||||
return (isinf(r)) ? 0.0 : noise_scale4(r);
|
||||
/* Repeat Perlin noise texture every 100000.0 on each axis to prevent floating point
|
||||
* representation issues. This causes discontinuities every 100000.0, however at such scales this
|
||||
* usually shouldn't be noticible. */
|
||||
p = vec4(compatible_fmod(p.x, 100000.0),
|
||||
compatible_fmod(p.y, 100000.0),
|
||||
compatible_fmod(p.z, 100000.0),
|
||||
compatible_fmod(p.w, 100000.0));
|
||||
|
||||
return noise_scale4(noise_perlin(p));
|
||||
}
|
||||
|
||||
float noise(vec4 p)
|
||||
|
|
Loading…
Reference in New Issue
Seems like we have
fmod
vector variants that should be used instead?