mirror of
https://bitbucket.org/CPMADevs/cnq3
synced 2025-04-06 01:21:44 +00:00
fixed the blend equations to match the GL/D3D specs
This commit is contained in:
parent
0684780348
commit
3aef00f466
2 changed files with 22 additions and 22 deletions
|
@ -26,56 +26,56 @@ along with Challenge Quake 3. If not, see <https://www.gnu.org/licenses/>.
|
|||
#endif
|
||||
|
||||
|
||||
float4 BlendSource(float4 src, float4 dst, uint stateBits)
|
||||
float4 BlendFactorSource(float4 src, float4 dst, uint stateBits)
|
||||
{
|
||||
if(stateBits == GLS_SRCBLEND_ZERO)
|
||||
return float4(0.0, 0.0, 0.0, 0.0);
|
||||
else if(stateBits == GLS_SRCBLEND_ONE)
|
||||
return src;
|
||||
return float4(1.0, 1.0, 1.0, 1.0);
|
||||
else if(stateBits == GLS_SRCBLEND_DST_COLOR)
|
||||
return src * dst;
|
||||
return dst;
|
||||
else if(stateBits == GLS_SRCBLEND_ONE_MINUS_DST_COLOR)
|
||||
return src * (float4(1.0, 1.0, 1.0, 1.0) - dst);
|
||||
return float4(1.0, 1.0, 1.0, 1.0) - dst;
|
||||
else if(stateBits == GLS_SRCBLEND_SRC_ALPHA)
|
||||
return src * float4(src.a, src.a, src.a, 1.0);
|
||||
return src.aaaa;
|
||||
else if(stateBits == GLS_SRCBLEND_ONE_MINUS_SRC_ALPHA)
|
||||
return src * float4(1.0 - src.a, 1.0 - src.a, 1.0 - src.a, 1.0);
|
||||
return (1.0 - src.a).xxxx;
|
||||
else if(stateBits == GLS_SRCBLEND_DST_ALPHA)
|
||||
return src * float4(dst.a, dst.a, dst.a, 1.0);
|
||||
return dst.aaaa;
|
||||
else if(stateBits == GLS_SRCBLEND_ONE_MINUS_DST_ALPHA)
|
||||
return src * float4(1.0 - dst.a, 1.0 - dst.a, 1.0 - dst.a, 1.0);
|
||||
return (1.0 - dst.a).xxxx;
|
||||
else if(stateBits == GLS_SRCBLEND_ALPHA_SATURATE)
|
||||
return src * float4(src.a, src.a, src.a, 1.0);
|
||||
return float4(min(src.a, 1.0 - dst.a).xxx, 1.0);
|
||||
else
|
||||
return src;
|
||||
return float4(1.0, 1.0, 1.0, 1.0); // 0 => replace mode
|
||||
}
|
||||
|
||||
float4 BlendDest(float4 src, float4 dst, uint stateBits)
|
||||
float4 BlendFactorDest(float4 src, float4 dst, uint stateBits)
|
||||
{
|
||||
if(stateBits == GLS_DSTBLEND_ZERO)
|
||||
return float4(0.0, 0.0, 0.0, 0.0);
|
||||
else if(stateBits == GLS_DSTBLEND_ONE)
|
||||
return dst;
|
||||
return float4(1.0, 1.0, 1.0, 1.0);
|
||||
else if(stateBits == GLS_DSTBLEND_SRC_COLOR)
|
||||
return dst * src;
|
||||
return src;
|
||||
else if(stateBits == GLS_DSTBLEND_ONE_MINUS_SRC_COLOR)
|
||||
return dst * float4(1.0 - src.r, 1.0 - src.g, 1.0 - src.b, 1.0 - src.a);
|
||||
return float4(1.0, 1.0, 1.0, 1.0) - src;
|
||||
else if(stateBits == GLS_DSTBLEND_SRC_ALPHA)
|
||||
return dst * float4(src.a, src.a, src.a, 1.0);
|
||||
return src.aaaa;
|
||||
else if(stateBits == GLS_DSTBLEND_ONE_MINUS_SRC_ALPHA)
|
||||
return dst * float4(1.0 - src.a, 1.0 - src.a, 1.0 - src.a, 0.0);
|
||||
return (1.0 - src.a).xxxx;
|
||||
else if(stateBits == GLS_DSTBLEND_DST_ALPHA)
|
||||
return dst * float4(dst.a, dst.a, dst.a, 1.0);
|
||||
return dst.aaaa;
|
||||
else if(stateBits == GLS_DSTBLEND_ONE_MINUS_DST_ALPHA)
|
||||
return dst * float4(1.0 - dst.a, 1.0 - dst.a, 1.0 - dst.a, 1.0);
|
||||
return (1.0 - dst.a).xxxx;
|
||||
else
|
||||
return float4(0.0, 0.0, 0.0, 0.0);
|
||||
return float4(0.0, 0.0, 0.0, 0.0); // 0 => replace mode
|
||||
}
|
||||
|
||||
float4 Blend(float4 src, float4 dst, uint stateBits)
|
||||
{
|
||||
float4 srcOut = BlendSource(src, dst, stateBits & GLS_SRCBLEND_BITS);
|
||||
float4 dstOut = BlendDest(src, dst, stateBits & GLS_DSTBLEND_BITS);
|
||||
float4 srcOut = src * BlendFactorSource(src, dst, stateBits & GLS_SRCBLEND_BITS);
|
||||
float4 dstOut = dst * BlendFactorDest(src, dst, stateBits & GLS_DSTBLEND_BITS);
|
||||
|
||||
return srcOut + dstOut;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ float3 BlendInScatteredLight(float4 srcColor, float3 dstColor, uint blendBits)
|
|||
}
|
||||
|
||||
uint dstBlend = blendBits & GLS_DSTBLEND_BITS;
|
||||
float3 dstContrib = BlendDest(srcColor, float4(dstColor, 1), dstBlend).rgb;
|
||||
float3 dstContrib = dstColor * BlendFactorDest(srcColor, float4(dstColor, 1), dstBlend).rgb;
|
||||
float3 result = srcContrib + dstContrib;
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue