gpt4 book ai didi

directx - 单纯形噪声着色器?

转载 作者:行者123 更新时间:2023-12-01 01:10:38 25 4
gpt4 key购买 nike

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

此外,对于纹理,使用 3D 噪声还是 2D 噪声更好?

最佳答案

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

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

该实现是在 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

关于directx - 单纯形噪声着色器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com