1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Add tests for FastNoiseLite/NoiseTexture

+ fix some issues with seamless noise generation
This commit is contained in:
Hendrik Brucker
2023-01-06 02:46:08 +01:00
parent 95ce236b7d
commit ffb8c74f26
5 changed files with 919 additions and 13 deletions

View File

@@ -107,8 +107,8 @@ class Noise : public Resource {
int skirt_height = MAX(1, p_height * p_blend_skirt);
int src_width = p_width + skirt_width;
int src_height = p_height + skirt_height;
int half_width = p_width * .5;
int half_height = p_height * .5;
int half_width = p_width * 0.5;
int half_height = p_height * 0.5;
int skirt_edge_x = half_width + skirt_width;
int skirt_edge_y = half_height + skirt_height;
@@ -146,7 +146,7 @@ class Noise : public Resource {
// Blend the vertical skirt over the middle seam.
for (int x = half_width; x < skirt_edge_x; x++) {
int alpha = 255 * (1 - Math::smoothstep(.1f, .9f, float(x - half_width) / float(skirt_width)));
int alpha = 255 * (1 - Math::smoothstep(0.1f, 0.9f, float(x - half_width) / float(skirt_width)));
for (int y = 0; y < p_height; y++) {
// Skip the center square
if (y == half_height) {
@@ -160,7 +160,7 @@ class Noise : public Resource {
// Blend the horizontal skirt over the middle seam.
for (int y = half_height; y < skirt_edge_y; y++) {
int alpha = 255 * (1 - Math::smoothstep(.1f, .9f, float(y - half_height) / float(skirt_height)));
int alpha = 255 * (1 - Math::smoothstep(0.1f, 0.9f, float(y - half_height) / float(skirt_height)));
for (int x = 0; x < p_width; x++) {
// Skip the center square
if (x == half_width) {
@@ -175,8 +175,8 @@ class Noise : public Resource {
// Fill in the center square. Wr starts at the top left of Q4, which is the equivalent of the top left of s3, unless a modulo is used.
for (int y = half_height; y < skirt_edge_y; y++) {
for (int x = half_width; x < skirt_edge_x; x++) {
int xpos = 255 * (1 - Math::smoothstep(.1f, .9f, float(x - half_width) / float(skirt_width)));
int ypos = 255 * (1 - Math::smoothstep(.1f, .9f, float(y - half_height) / float(skirt_height)));
int xpos = 255 * (1 - Math::smoothstep(0.1f, 0.9f, float(x - half_width) / float(skirt_width)));
int ypos = 255 * (1 - Math::smoothstep(0.1f, 0.9f, float(y - half_height) / float(skirt_height)));
// Blend s3(Q1) onto s5(Q2) for the top half.
T top_blend = _alpha_blend<T>(rd_src(x, y, img_buff<T>::ALT_X), rd_src(x, y, img_buff<T>::DEFAULT), xpos);