Shader BlendMode Formulas shader的各种混合叠加模式算法.

【本文系外部转贴, 查看原文
| 导语  shader的各种混合叠加模式算法.

Equations used when blending drawn content with the screen or active Canvas.

Color components are generally in the range of [0, 1] rather than [0, 255] for the purposes of these equations. Results are clamped to [0, 1] except when a Canvas is active that has a floating-point / HDR format.

Description:

  • dst - existing color in the screen.
  • src - the color of the drawn object (the color output by the pixel shader, or the global color multiplied by the texture's color – if any, if no shader is used.)
  • res - resulting color.

Here are the BlendMode formulas for all 0.10.x versions:

alpha

"alphamultiply" alpha mode

   res.r = dst.r * (1 - src.a) + src.r * src.a
   res.g = dst.g * (1 - src.a) + src.g * src.a
   res.b = dst.b * (1 - src.a) + src.b * src.a
   res.a = dst.a * (1 - src.a) + src.a

"premultiplied" alpha mode

   res.r = dst.r * (1 - src.a) + src.r
   res.g = dst.g * (1 - src.a) + src.g
   res.b = dst.b * (1 - src.a) + src.b
   res.a = dst.a * (1 - src.a) + src.a

add

"alphamultiply" alpha mode

   res.r = dst.r + (src.r * src.a)
   res.g = dst.g + (src.g * src.a)
   res.b = dst.b + (src.b * src.a)
   res.a = dst.a

"premultiplied" alpha mode

   res.r = dst.r + src.r
   res.g = dst.g + src.g
   res.b = dst.b + src.b
   res.a = dst.a

subtract

"alphamultiply" alpha mode

   res.r = dst.r - (src.r * src.a)
   res.g = dst.g - (src.g * src.a)
   res.b = dst.b - (src.b * src.a)
   res.a = dst.a

"premultiplied" alpha mode

   res.r = dst.r - src.r
   res.g = dst.g - src.g
   res.b = dst.b - src.b
   res.a = dst.a

replace

"alphamultiply" alpha mode

   res.r = src.r * src.a
   res.g = src.g * src.a
   res.b = src.b * src.a
   res.a = src.a

"premultiplied" alpha mode

   res.r = src.r
   res.g = src.g
   res.b = src.b
   res.a = src.a

multiply (both alpha modes)

   res.r = src.r * dst.r
   res.g = src.g * dst.g
   res.b = src.b * dst.b
   res.a = src.a * dst.a

lighten

"premultiplied" alpha mode

   res.r = max(src.r, dst.r)
   res.g = max(src.g, dst.g)
   res.b = max(src.b, dst.b)
   res.a = max(src.a, dst.a)

darken

"premultiplied" alpha mode

   res.r = min(src.r, dst.r)
   res.g = min(src.g, dst.g)
   res.b = min(src.b, dst.b)
   res.a = min(src.a, dst.a)

screen

Note: The math for this blend mode is not completely correct when using the "alphamultiply" alpha mode. Prefer the "premultiplied" variant (and be sure your content has its RGB multiplied by its alpha at some point before blending), when possible.

"alphamultiply" alpha mode

   res.r = dst.r * (1 - src.r) + (src.r * src.a)
   res.g = dst.g * (1 - src.g) + (src.g * src.a)
   res.b = dst.b * (1 - src.b) + (src.b * src.a)
   res.a = dst.a * (1 - src.a) + src.a

"premultiplied" alpha mode

   res.r = dst.r * (1 - src.r) + src.r
   res.g = dst.g * (1 - src.g) + src.g
   res.b = dst.b * (1 - src.b) + src.b
   res.a = dst.a * (1 - src.a) + src.a

Older Versions

alpha (0.9.00.9.1, and 0.9.2)

   res.r = dst.r * (1 - src.a) + src.r * src.a
   res.g = dst.g * (1 - src.a) + src.g * src.a
   res.b = dst.b * (1 - src.a) + src.b * src.a
   res.a = dst.a * (1 - src.a) + src.a

alpha (0.8.0 and older)

   res.r = dst.r * (1 - src.a) + src.r * src.a
   res.g = dst.g * (1 - src.a) + src.g * src.a
   res.b = dst.b * (1 - src.a) + src.b * src.a
   res.a = dst.a * (1 - src.a) + src.a * src.a

premultiplied (0.9.2 and older)

   res.r = dst.r * (1 - src.a) + src.r
   res.g = dst.g * (1 - src.a) + src.g
   res.b = dst.b * (1 - src.a) + src.b
   res.a = dst.a * (1 - src.a) + src.a

screen (0.9.2 and older)

   res.r = dst.r * (1 - src.r) + src.r
   res.g = dst.g * (1 - src.g) + src.g
   res.b = dst.b * (1 - src.b) + src.b
   res.a = dst.a * (1 - src.a) + src.a

additive (0.9.2 and older)

   res.r = dst.r + (src.r * src.a)
   res.g = dst.g + (src.g * src.a)
   res.b = dst.b + (src.b * src.a)
   res.a = dst.a + (src.a * src.a)

subtractive (0.9.2 and older)

   res.r = dst.r - src.r * src.a
   res.g = dst.g - src.g * src.a
   res.b = dst.b - src.b * src.a
   res.a = dst.a - src.a * src.a

multiplicative (0.9.00.9.1, and 0.9.2)

   res.r = src.r * dst.r
   res.g = src.g * dst.g
   res.b = src.b * dst.b
   res.a = src.a * dst.a

multiplicative (0.8.0 and older)

   res.r = dst.r * (1 - src.a) + src.r * dst.r
   res.g = dst.g * (1 - src.a) + src.g * dst.g
   res.b = dst.b * (1 - src.a) + src.b * dst.b
   res.a = dst.a * (1 - src.a) + src.a * dst.a

replace (0.9.2 and older)

   res.r = src.r
   res.g = src.g
   res.b = src.b
   res.a = src.a
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
-------------------- FairyGUI Copyright © 2014-2020 FairyGUI.com Version 3.4.0 [email protected] -------------------- FairyGUI is a flexible UI framework for Unity, working with the professional FREE Game UI Editor: FairyGUI Editor. Download the editor from here: http://en.fairygui.com/ -------------------- Get Started -------------------- Run demos in Assets/FairyGUI/Examples/Scenes. The UI project is in Examples-UIProject.zip, unzip it anywhere. Use FairyGUI Editor to open it. Using FairyGUI in Unity: * Place a UIPanel in scene by using editor menu GameObject/FairyGUI/UIPanel. * Or using UIPackage.CreateObject to create UI component dynamically, and then use GRoot.inst.AddChild to show it on screen. ----------------- Version History ----------------- 3.4.0 - NEW: Add multi-display support. - NEW: Add API DynamicFont(name, font). - IMPROVED: Compatibility with 2018.3. - FIXED: Incorrect letter spacing on mobile platform. - FIXED: Same transition hook may be called twice. - FIXED: Exception raised when texture was disposed before object was disposed. 3.3.0 - NEW: Add textfield maxwidth feature. - NEW: Add API to query package dependencies. - IMPROVED: Graphics module refactor. Now it is more convenient to create various shapes(pie, lines, polygon etc) and do mesh deform. Memory usage on building mesh is also dropped. Also supports automatically setup uv for arbitrary quad to avoid seam between 2 triangles. All shaders are updated, don't forget to replace shaders in your project. - IMPROVED: Text-Brighter mechanism is removed, so FairyGUI-Text-Brighter.shader is removed. - IMPROVED: Add support for shrinking multi-line text. - IMPROVED: Improve Lua support. 3.2.0 - NEW: Add DisplayObjectInfo component. Define script symbol FAIRYGUI_TEST to enable it. - FIXED: A virtual list scrolling bug. - FIXED: A BlendMode bug. 3.1.0 - NEW: Draw extra 8 directions instead of 4 directions to archive text outline effect. Toggle option is UIConfig.enhancedTextOutlineEffect. - IMPROVED: Eexecution efficiency optimizations. - IMPROVED: GoWrapper now supports multiple materials. - FIXED: Correct cleanup action for RemovePackage. 3.0.0 From this version, we change package data format to binary. Editor version 3.9.0 with 'binary format' option checked in publish dialog is required to generating this kind of format. Old XML format is not supported anymore. - NEW: Add UIPackage.UnloadAssets and UIPackage.ReloadAssets to allow unload package resources without removing the package. - NEW: Add TransitionActionType.Text and TransitionActionType.Icon. 2.4.0 - NEW: GTween is introduced, DOTween is no longer used inside FairyGUI. - NEW: Transitions now support playing partially and pausing. - IMPROVED: Change the way of registering bitmap font. - FIXED: A GButton pivot issue. - FIXED: Correct text align behavior. 2.3.0 - NEW: Allow loader to load component. - NEW: Add text template feature. - FIXED: Exclude invisible object in FairyBatching. 2.2.0 - NEW: Modify shaders to fit linear color space. - IMPROVED: Improve relation system to handle conditions that anchor is set. - IMPROVED: Eliminate GC in transition. - FIXED: Fixed a bug of unloading bundle in UIPackage. - FIXED: Fixed issue that some blend mode(multiply, screen) works improperly. 2.1.0 - NEW: Add GGraph.DrawRoundRect. - NEW: Add FillType.ScaleNoBorder. - FIXED: Repair potential problems of virtual list. - FIXED: Fixed a bug in handling shared materials. 2.0.0 - NEW: RTL Text rendering support. Define scripting symbols RTL_TEXT_SUPPORT to enabled it. - NEW: Support for setting GObject.data in editor. - NEW: Support for setting selectedIcon of list item in editor. - IMPROVED: Add UIConfig.depthSupportForPaitingMode. - IMPROVED: Set sorting order of popup automatically. - FIXED: Fixed a text layout bug when line spacing is negative. - FIXED: Reset ScrollPane.draggingPane when an active scrollPane is being disposed. - FIXED: Fixed a bug of skew rendering.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值