【问题标题】:Use Perlin noise to render wood使用 Perlin 噪声来渲染木材
【发布时间】:2013-09-18 10:51:09
【问题描述】:

我正在阅读面向游戏编程和艺术家的着色器。在第 13 章“从零开始构建材质”中,作者介绍了一些渲染技术,利用 Perlin 噪声模拟大理石或木材等复杂材质。但我对木材渲染感到困惑。 为了模拟木材,我们需要一个函数沿特定平面给出一个圆形值,以便我们可以在树林中创建环。这就是作者所说的“沿平面取两个轴的点积,在该平面上创建圆形值”

Circle = dot(noisetxr.xy, noisetxr.xy);

noisetxr 是一个float3,它是一个纹理坐标来采样噪声纹理,我不明白为什么点积会给出一个圆形值
以下是完整代码(hlsl 中的像素着色器):

float persistance;
float4 wood_color;  //a predefined value
sampler Texture0;   // noise texture
float4 ps_main(float3 txr: TEXCOORD0) : COLOR 
{
   // Determine two set of coordinates, one for the noise
   // and one for the wood rings
   float3 noisetxr = txr;
   txr = txr/8;

   // Combine 3 octaves of noise together.
   float final_noise = 0;
   for(int i=0;i<2;i++)
      final_noise += ((1.0/pow(persistance,i))*
        ((tex3D(Texture0, txr*pow(2,i))*2)-1));

   // The wood is defined by a set of concentric rings in the XY
   // plane. Those rings are pertubated by the computed noise.
   final_noise = abs(final_noise);
   float grain = cos(dot(noisetxr.xy,noisetxr.xy) + final_noise*4);//what is this ??
   return wood_color - pow(grain,8)/2; //raising the cosine to higher power
}

我知道将余弦函数提高到更高的幂会产生更尖锐的环,但是点积是什么意思?为什么它可以创建一个圆圈值?

【问题讨论】:

    标签: graphics shader hlsl noise


    【解决方案1】:

    向量与自身的点积只会导致向量的平方长度。因此,对于 xy 平面中的每个点,dot(noisetxr.xy,noisetxr.xy) 返回该点到原点的平方距离。现在你在这个距离上应用一个余弦函数,这意味着对于平面上与原点具有相同距离的所有点,它会创建相同的输出值 => 围绕原点的相等值的圆。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-15
      • 2020-06-06
      • 2011-09-20
      • 2021-06-30
      • 2013-07-23
      • 2020-06-22
      • 2011-03-19
      • 1970-01-01
      相关资源
      最近更新 更多