tajourney tajourney
  • 首页
  • 渲染
    • PBR
    • NPR
  • 引擎
    • Unity
    • UE
  • DCC
    • Houdini
    • PhotoShop
    • Blender
  • 优化
  • 工具
  • 杂谈
    • 游戏
  • 友链
  • 关于
    • About Me
    • 网站公告
    • 维护记录
    • QA
  • 注册
  • 登录
首页 › DCC › Blender › Blender MixColor 节点算法解析

Blender MixColor 节点算法解析

糯米
2年前Blender阅读 1,016

最近在写Blender内的材质,对于MixColor这个节点产生了一些困惑:

Blender MixColor 节点算法解析-tajourney

比如上图Multi,Add,Mix对应的Fac值是如何参与计算的。Multi,Add,Mix等本身的计算公式还好。

有:function mix = mix(col1,col2,fac) = col1 * (1-fac) + col2 * fac;

忍不住去翻了下Blender源码。

Mix Color定义在:

https://github.com/blender/blender/blob/2864c20302513dae0443af461d225b5a1987267a/intern/cycles/kernel/osl/shaders/node_mix_color.osl#L9

/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
 *
 * SPDX-License-Identifier: Apache-2.0 */

#include "node_color.h"
#include "node_color_blend.h"
#include "stdcycles.h"

shader node_mix_color(string blend_type = "mix",
                      int use_clamp = 0,
                      int use_clamp_result = 0,
                      float Factor = 0.5,
                      color A = 0.0,
                      color B = 0.0,
                      output color Result = 0.0)
{
  float t = (use_clamp) ? clamp(Factor, 0.0, 1.0) : Factor;

  if (blend_type == "mix")
    Result = mix(A, B, t);
  if (blend_type == "add")
    Result = node_mix_add(t, A, B);
  if (blend_type == "multiply")
    Result = node_mix_mul(t, A, B);
  if (blend_type == "screen")
    Result = node_mix_screen(t, A, B);
  if (blend_type == "overlay")
    Result = node_mix_overlay(t, A, B);
  if (blend_type == "subtract")
    Result = node_mix_sub(t, A, B);
  if (blend_type == "divide")
    Result = node_mix_div(t, A, B);
  if (blend_type == "difference")
    Result = node_mix_diff(t, A, B);
  if (blend_type == "exclusion")
    Result = node_mix_exclusion(t, A, B);
  if (blend_type == "darken")
    Result = node_mix_dark(t, A, B);
  if (blend_type == "lighten")
    Result = node_mix_light(t, A, B);
  if (blend_type == "dodge")
    Result = node_mix_dodge(t, A, B);
  if (blend_type == "burn")
    Result = node_mix_burn(t, A, B);
  if (blend_type == "hue")
    Result = node_mix_hue(t, A, B);
  if (blend_type == "saturation")
    Result = node_mix_sat(t, A, B);
  if (blend_type == "value")
    Result = node_mix_val(t, A, B);
  if (blend_type == "color")
    Result = node_mix_color(t, A, B);
  if (blend_type == "soft_light")
    Result = node_mix_soft(t, A, B);
  if (blend_type == "linear_light")
    Result = node_mix_linear(t, A, B);

  if (use_clamp_result)
    Result = clamp(Result, 0.0, 1.0);
}

在node_color_blend.h头文件中:

color node_mix_add(float t, color col1, color col2)
{
  return mix(col1, col1 + col2, t);
}

color node_mix_mul(float t, color col1, color col2)
{
  return mix(col1, col1 * col2, t);
}
...

所以就mul/add而言,他们与Mix的不同就是算法中的颜色2参数。

补充dark 、light算法:

color node_mix_dark(float t, color col1, color col2)
{
  return mix(col1, min(col1, col2), t);
}

color node_mix_light(float t, color col1, color col2)
{
  return mix(col1, max(col1, col2), t);
}
赞(0)

请登录以参与评论

现在登录
暂无评论
搜索
近期文章
  • 终末地人物渲染(更新中) 2025年3月17日
  • Unity APV体素化光栅化实现 2025年2月5日
  • Unity 不同 ReflectionProbe 打断 Instancing 解决方案 2025年1月15日
  • Renderdoc 原神截帧记录 2024年8月22日
  • Houdini VAT:Vellum Cltoh笔记 2 2024年7月17日
归档
  • 2025年3月 (1)
  • 2025年2月 (1)
  • 2025年1月 (1)
  • 2024年8月 (1)
  • 2024年7月 (2)
  • 2024年1月 (1)
  • 2023年10月 (3)
  • 2023年9月 (4)
  • 2023年8月 (5)
  • 2023年7月 (4)
  • 2023年6月 (4)
  • 2023年5月 (1)
  • 2023年4月 (3)
  • 2023年3月 (11)
  • 2023年2月 (11)
  • 2023年1月 (1)
  • 2022年7月 (1)
  • 2022年6月 (2)
  • 2022年5月 (1)
  • 2022年4月 (1)
  • 2022年3月 (1)
  • 2022年2月 (1)
  • 2022年1月 (7)
  • 0
  • 0
Copyright © 2022-2025 tajourney. Dev by nuomi 版权所有.
鲁ICP备19015245号
  • 首页
  • 渲染
    • PBR
    • NPR
  • 引擎
    • Unity
    • UE
  • DCC
    • Houdini
    • PhotoShop
    • Blender
  • 优化
  • 工具
  • 杂谈
    • 游戏
  • 友链
  • 关于
    • About Me
    • 网站公告
    • 维护记录
    • QA
糯米
日语学习中
68
文章
15
评论
44
喜欢