sumi 发表于 2019-12-22 18:00

Octane利用OSL创建车漆Flakes贴图

本帖最后由 sumi 于 2020-3-31 12:48 编辑

虽然Octane有flakes的OSL预设,不过默认的不能控制flakes贴图的投射模式。

新建一个OSL节点,并把以下代码复制替换进去,然后点击上方的Compile按钮即可。

shader flakes
(
    point position = P,
    float scale = 1 [[ float min = 1e-4, float max = 1e3, float sliderexponent = 4 ]],
    float flake_size = 0.5 [[ string description = "Relative size of the flakes",
      float min = 0, float max = 10 ]],
    float flake_size_variance = 0.0 [[ string description = "0.0 makes all flakes the same size, 1.0 assigns random size between 0 and the given flake size",
      float min = 0, float max = 1 ]],
    float strength = 0.3 [[ string description = "The strength of the normal map",
      float min = 0, float max = .5 ]],
      output color cOut = color(0.5, 0.5, 1.0)
)
{
    point uvw = position / scale;
    float safe_flake_size_variance = clamp(flake_size_variance, 0, 1.0);
    point base = floor(uvw);

    point nearestFlakePos = point(0.0, 0.0, 1.0);
    float bestDistance = 99;
    for (float cellx = -1.5; cellx < 1; cellx += 1.0)
    {
      for (float celly = -1.5; celly < 1; celly += 1.0)
      {
            for (float cellz = -1.5; cellz < 1; cellz += 1.0)
            {
                point cellCenter = base + point(cellx, celly, cellz);

                cellCenter += (vector) cellnoise(cellCenter);

                float cellDistance = distance(uvw, cellCenter);
                float maxDistance = flake_size;
                if (cellDistance < maxDistance)
                {
                  float uSize = cellnoise(cellCenter + vector(-600, 600, 600));
                  maxDistance -= flake_size_variance * uSize * flake_size;
                  if (cellDistance < maxDistance)
                  {
                        if (cellDistance < flake_size && cellDistance < bestDistance)
                        {
                            bestDistance = cellDistance;
                            nearestFlakePos = cellCenter;
                        }
                  }
                }
            }
      }
    }

    if (bestDistance != 99)
    {
      vector random = cellnoise(nearestFlakePos);
      float ang = random * M_PI * 2;
      // sample disk, non-uniform: more densely near the origin
      vector distortion = vector(sin(ang), cos(ang), 0)
                            * sqrt(-2 * log(1 - .999 * random));
      cOut = normalize(vector(0, 0, 1) + distortion * strength) * .5 + .5;
    }
}

测试效果


sumi 发表于 2020-3-31 12:45

游客 113.111.48.x 发表于 2020-3-26 20:26
根本不行

可能是你的OC版本问题,3.07用不了的。也有可能是你的参数调整有问题,我更新了下参数设置,你可以参考下。

发表于 2020-3-26 20:26

根本不行
页: [1]
查看完整版本: Octane利用OSL创建车漆Flakes贴图