directx – Simplex Noise着色器?

我有几个关于Simplex Noise的问题.我正在使用Simplex Noise在directx中生成地形,但我现在正在使用类等.我可能也会将它用于纹理,所以是否有必要将其更改为着色器实现?如果是这样,这很容易做到吗?

另外,对于纹理来说,使用3D或2D噪声会更好吗?

最佳答案 是的,你真的应该将这项工作转移到GPU,这是它最擅长的.

GPU上的单工噪声是一个已解决的问题.您可以找到关于主题here的优秀论文,或者您可以从here获取实施.

这个实现是在GLSL中,但移植它只是改变vec3和& vec4是浮动3和浮动4的.

使用它之后,我发现到目前为止最快的噪声函数实现是由inigo quilez实现的Perlin噪声(下面提供的实现来自于shadowrtoy.com网站上的代码.这是一个很棒的网站,请查看它!

#ifndef __noise_hlsl_
#define __noise_hlsl_

// hash based 3d value noise
// function taken from https://www.shadertoy.com/view/XslGRr
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// ported from GLSL to HLSL

float hash( float n )
{
    return frac(sin(n)*43758.5453);
}

float noise( float3 x )
{
    // The noise function returns a value in the range -1.0f -> 1.0f

    float3 p = floor(x);
    float3 f = frac(x);

    f       = f*f*(3.0-2.0*f);
    float n = p.x + p.y*57.0 + 113.0*p.z;

    return lerp(lerp(lerp( hash(n+0.0), hash(n+1.0),f.x),
                   lerp( hash(n+57.0), hash(n+58.0),f.x),f.y),
               lerp(lerp( hash(n+113.0), hash(n+114.0),f.x),
                   lerp( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
}

#endif
点赞