单工噪声着色器?

Exp*_*ork 3 directx shader perlin-noise simplex-noise

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

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

fis*_*ood 7

是的,你真的应该把这项工作转移到 GPU 上,这是它最擅长的。

GPU 上的单工噪声是一个已解决的问题。您可以在此处找到有关该主题的出色论文,也可以从此处获取实现。

该实现在 GLSL 中,但移植它只是将 vec3 和 vec4 更改为 float3 和 float4 的问题。

使用它后,我发现迄今为止最快的噪声函数实现是 inigo quilez 对 Perlin 噪声的实现(下面提供的实现取自 shadertoy.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
Run Code Online (Sandbox Code Playgroud)