Octane利用OSL创建车漆Flakes贴图

[复制链接]
查看2081 | 回复2 | 2019-12-22 18:00 | 显示全部楼层 |阅读模式
本帖最后由 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[0] * 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[1]));
        cOut = normalize(vector(0, 0, 1) + distortion * strength) * .5 + .5;
    }
}

测试效果
11.png

最近访客

  • c4d_255e1caa3b
    2023-12-21
  • 布丁薛
    2022-12-12
  • c4d_845a506413
    2022-11-14
  • 毛线
    2022-07-01
  • 小汤TA
    2022-04-21
  • 九月萤
    2022-02-22
  • qq_LeoWang_twg
    2022-02-09
  • ZRK
    2022-02-04
  • lx4115985
    2021-12-15
回复 呼我投币

使用道具 举报

sumi | 2020-3-31 12:45 | 显示全部楼层

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

使用道具 举报

平台游客| 2020-3-26 20:26
根本不行
回复 投币

使用道具

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

最近参与
19年第1期周练

67

主题

523 小时

在线时间

5万

C币

管理3级

Rank: 7Rank: 7Rank: 7

积分
59319
所在小组
A组
我的组号
18
注册时间
2019-10-24

2020年周练成员推荐周练成员2019年周练成员专栏分享作者