单纯形噪声调整仅在一个方向上起作用
Simplex Noise Adjustments only working in one direction
我正在使用单纯形噪声制作高度图。我正在 运行 调整它以形成一个小岛的轻微趋势。在实际渲染生物群落和其他特征之前,我只是在努力使值正确。我有 运行 的问题,我的代码应该可以产生这种在中间形成一个岛的趋势,但似乎只在一个方向上起作用。
是否有特殊原因?我的 class 处理地形的平滑处理在 x 和 y 方向上做同样的事情,但只有一个有效。
public class MapGenerator{
public double[][] toRender;
int maxHeight = 300;
public MapGenerator() {
int xResolution = 200;
int yResolution = 200;
double[][] result = new double[xResolution][yResolution];
for (int x = 0; x < xResolution; x++){
for (int y = 0; y < yResolution; y++){
result[x][y] = transformPoint(x, y, xResolution, yResolution, SimplexNoise.noise(x, y));
}
}
toRender = result;
}
private double transformPoint(int x, int y, int xSize, int ySize, double point){
System.out.println();
System.out.println(point);
point += 20 * Math.sin(x * Math.PI / xSize);
point += 20 * Math.sin(y * Math.PI / ySize);
System.out.println(point);
return point;
}
}
白噪声图像:
With only X (Y commented out):
[只有Y(X被注释掉):](类似于X和Y,不能post link因为声望。)
[没有X和Y:](类似于只有X,不能post link因为声望。)
我不是 100% 知道你的错误所在。它可能在您的日常噪音中。为了对此进行调试,我删除了对 noise
的调用并替换为常数值 0.5。然后我让它的其余部分开始工作,所以我在图像的中心看到了一个白色的光晕。然后我添加了 noise
回调。 (注意我在这里使用我自己的 SimplexNoise
。)
所以问题出在您的范围内(Math.min( 1.0, point ))
或您的图形显示(您未显示)或您的 SimplexNoise
(您也未显示)。
import SimpleUtils.noise.SimplexNoise;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
*
* @author Brenden Towey
*/
public class MapGenerator
{
public static void main( String[] args )
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
JFrame frame = new JFrame();
frame.add( new JLabel( new ImageIcon( new MapGenerator().toImage() )));
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
} );
}
public double[][] toRender;
int maxHeight = 300;
int xResolution = 200;
int yResolution = 200;
public MapGenerator()
{
double[][] result = new double[ xResolution ][ yResolution ];
SimplexNoise noise = new SimplexNoise();
for( int x = 0; x < xResolution; x++ )
for( int y = 0; y < yResolution; y++ )
result[x][y] = transformPoint( x, y, noise.noise(x, y) );
toRender = result;
}
private double transformPoint( int x, int y, double point )
{
point += 2 * Math.sin( x * Math.PI / xResolution )/2.0;
point += 2 * Math.sin( y * Math.PI / yResolution )/2.0;
return Math.min( 1.0, point);
}
public Image toImage()
{
BufferedImage image = new BufferedImage( xResolution,
yResolution, BufferedImage.TYPE_INT_RGB );
for( int x = 0; x < xResolution; x++ )
for( int y = 0; y < yResolution; y++ )
image.setRGB( x, y, greyScale( toRender[x][y] ) );
return image;
}
private int greyScale( double toRender )
{
int scale = (int) ( 255 * toRender );
return scale + (scale << 8) + (scale << 16);
}
}
我正在使用单纯形噪声制作高度图。我正在 运行 调整它以形成一个小岛的轻微趋势。在实际渲染生物群落和其他特征之前,我只是在努力使值正确。我有 运行 的问题,我的代码应该可以产生这种在中间形成一个岛的趋势,但似乎只在一个方向上起作用。
是否有特殊原因?我的 class 处理地形的平滑处理在 x 和 y 方向上做同样的事情,但只有一个有效。
public class MapGenerator{
public double[][] toRender;
int maxHeight = 300;
public MapGenerator() {
int xResolution = 200;
int yResolution = 200;
double[][] result = new double[xResolution][yResolution];
for (int x = 0; x < xResolution; x++){
for (int y = 0; y < yResolution; y++){
result[x][y] = transformPoint(x, y, xResolution, yResolution, SimplexNoise.noise(x, y));
}
}
toRender = result;
}
private double transformPoint(int x, int y, int xSize, int ySize, double point){
System.out.println();
System.out.println(point);
point += 20 * Math.sin(x * Math.PI / xSize);
point += 20 * Math.sin(y * Math.PI / ySize);
System.out.println(point);
return point;
}
}
白噪声图像:
With only X (Y commented out):
[只有Y(X被注释掉):](类似于X和Y,不能post link因为声望。)
[没有X和Y:](类似于只有X,不能post link因为声望。)
我不是 100% 知道你的错误所在。它可能在您的日常噪音中。为了对此进行调试,我删除了对 noise
的调用并替换为常数值 0.5。然后我让它的其余部分开始工作,所以我在图像的中心看到了一个白色的光晕。然后我添加了 noise
回调。 (注意我在这里使用我自己的 SimplexNoise
。)
所以问题出在您的范围内(Math.min( 1.0, point ))
或您的图形显示(您未显示)或您的 SimplexNoise
(您也未显示)。
import SimpleUtils.noise.SimplexNoise;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
/**
*
* @author Brenden Towey
*/
public class MapGenerator
{
public static void main( String[] args )
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
JFrame frame = new JFrame();
frame.add( new JLabel( new ImageIcon( new MapGenerator().toImage() )));
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
} );
}
public double[][] toRender;
int maxHeight = 300;
int xResolution = 200;
int yResolution = 200;
public MapGenerator()
{
double[][] result = new double[ xResolution ][ yResolution ];
SimplexNoise noise = new SimplexNoise();
for( int x = 0; x < xResolution; x++ )
for( int y = 0; y < yResolution; y++ )
result[x][y] = transformPoint( x, y, noise.noise(x, y) );
toRender = result;
}
private double transformPoint( int x, int y, double point )
{
point += 2 * Math.sin( x * Math.PI / xResolution )/2.0;
point += 2 * Math.sin( y * Math.PI / yResolution )/2.0;
return Math.min( 1.0, point);
}
public Image toImage()
{
BufferedImage image = new BufferedImage( xResolution,
yResolution, BufferedImage.TYPE_INT_RGB );
for( int x = 0; x < xResolution; x++ )
for( int y = 0; y < yResolution; y++ )
image.setRGB( x, y, greyScale( toRender[x][y] ) );
return image;
}
private int greyScale( double toRender )
{
int scale = (int) ( 255 * toRender );
return scale + (scale << 8) + (scale << 16);
}
}