@@ -83,7 +83,8 @@ Example:
8383 blend_asrc = sa; blend_adst = 1;
8484
8585 .. warning ::
86- Blending *operations * (as well as blending constants for ``bf `` and ``ibf `` blending modes) need to be configured in C++ code.
86+ Blend *constants * for the ``bf `` and ``ibf `` factors still need to be configured in C++ code.
87+ Blend *operations *, however, can be set directly in DSHL -- see **Blend operation ** below.
8788
8889If you don't configure blending factors in the shader, these defaults will be used:
8990
@@ -92,17 +93,66 @@ If you don't configure blending factors in the shader, these defaults will be us
9293 blend_src = 1; blend_dst = 0;
9394 blend_asrc = 1; blend_adst = 0;
9495
96+ **Blend operation **
97+
98+ The weighted source and destination values are combined with a *blend operation * --
99+ the ``<colorBlendOp> `` / ``<alphaBlendOp> `` in the pseudocode above. By default this is
100+ addition; it can be changed with these state variables:
101+
102+ - ``blend_op `` -- RGB blend operation
103+ - ``blend_aop `` -- alpha blend operation
104+
105+ Each accepts one of the following operations:
106+
107+ - ``add `` -- ``src + dst `` (default)
108+ - ``min `` -- ``min(src, dst) ``
109+ - ``max `` -- ``max(src, dst) ``
110+
111+ Example (max blending):
112+
113+ .. code-block :: c
114+
115+ blend_src = 1; blend_dst = 1;
116+ blend_op = max;
117+
118+ .. note ::
119+ Only ``add ``, ``min `` and ``max `` are exposed in DSHL.
120+ The hardware ``subtract `` / ``revsubtract `` operations are not available here.
121+
122+ If you don't set an operation, it defaults to ``add ``.
123+
124+ .. important ::
125+ ``blend_op `` and ``blend_aop `` only have an effect when blending is enabled for the
126+ target, i.e. when its ``blend_src `` and ``blend_dst `` factors are set.
127+
128+ ``blend_aop `` additionally requires *separate alpha blending *, which is turned on by
129+ setting the separate alpha factors ``blend_asrc `` **and ** ``blend_adst `` -- **not ** by
130+ setting ``blend_aop `` itself. If the separate alpha factors are not set, the alpha
131+ channel reuses the color operation ``blend_op ``, and ``blend_aop `` (including its
132+ ``add `` default) is ignored.
133+
134+ So, with blending enabled, setting only ``blend_op = max `` (no ``blend_aop ``, no
135+ separate alpha factors) makes **both ** color and alpha blend with ``max ``. To give
136+ alpha a different operation you must also set ``blend_asrc `` / ``blend_adst ``.
137+
138+ Like blend factors, ``blend_op `` / ``blend_aop `` can be indexed per render target
139+ for independent blending (see below).
140+
141+ .. warning ::
142+ Dual-source blending (the ``sc1 `` / ``isc1 `` / ``sa1 `` / ``isa1 `` factors)
143+ only supports the ``add `` blend operation.
144+
95145**Independent blending **
96146
97147Dagor supports independent blending, i.e. different render targets may have different blending settings.
98- This is done by providing an index to ``blend_src, blend_dst, blend_asrc, blend_adst `` variables with ``[] `` operator.
148+ This is done by providing an index to ``blend_src, blend_dst, blend_asrc, blend_adst, blend_op, blend_aop `` variables with ``[] `` operator.
99149
100150.. code-block :: c
101151
102152 blend_src[0] = 1; blend_dst[0] = 0;
103153 blend_src[1] = 0; blend_dst[1] = 1;
104154
105- Without an index, the desired blend factor affects all render targets.
155+ Without an index, the value affects all render targets.
106156
107157-------------
108158Depth/Stencil
0 commit comments