echo icon indicating copy to clipboard operation
echo copied to clipboard

Material blend models

Open timi-liuliang opened this issue 4 years ago • 0 comments
trafficstars

Opaque Masked Translucent Additive Mulitply

Supporting configure all properties is too complex!

	class BlendState: public RenderState
	{
	public:
		enum BlendOperation
		{
			BOP_ADD, 
			BOP_SUB, 
			BOP_REV_SUB, 
			BOP_MIN, 
			BOP_MAX,
		};

		enum BlendFactor
		{
			BF_ZERO,
			BF_ONE,
			BF_SRC_ALPHA,
			BF_DST_ALPHA,
			BF_INV_SRC_ALPHA,
			BF_INV_DST_ALPHA,
			BF_SRC_COLOR,
			BF_DST_COLOR,
			BF_INV_SRC_COLOR,
			BF_INV_DST_COLOR,
			BF_SRC_ALPHA_SAT, 
			BF_MAX,
		};

		BlendState();
		virtual ~BlendState();

		// blend enable
		bool isBlendEnable() const { return m_blendEnable; }
		void setBlendEnable(bool enable);

		// src blend
		BlendFactor getSrcBlend() const { return m_srcBlend; }
		void setSrcBlend(BlendFactor blendFactor);

		// dst blend
		BlendFactor getDstBlend() const { return m_dstBlend; }
		void setDstBlend(BlendFactor blendFactor);

	public:
		bool				m_blendEnable = false;
		BlendFactor			m_srcBlend = BF_ONE;
		BlendFactor			m_dstBlend = BF_ZERO;
		BlendOperation		m_blendOP = BOP_ADD;
		BlendFactor			m_srcAlphaBlend = BF_ONE;
		BlendFactor			m_dstAlphaBlend = BF_ZERO;
		BlendOperation		m_alphaBlendOP = BOP_ADD;
		ui8					m_colorWriteMask = CMASK_COLOR;
		bool				m_a2cEnable = false;
		Color				m_blendFactor = { 0.f, 0.f, 0.f, 0.f};
	};
Mode Description
BLEND_Opaque Final color = Source color. This means that the Material will draw on top of the background. This blend mode is compatible with lighting.
BLEND_Masked Final color = Source color if OpacityMask > OpacityMaskClipValue, otherwise the pixel is discarded. This blend mode is compatible with lighting.
BLEND_Translucent Final color = Source color * Opacity + Dest color * (1 - Opacity). This blend mode is NOT compatible with dynamic lighting.
BLEND_Additive Final color = Source color + Dest color. This blend mode is NOT compatible with dynamic lighting.
BLEND_Multiply Final color = Source color x Dest color. This blend mode is NOT compatible with dynamic lighting, or fog, unless this is a decal material.

timi-liuliang avatar Oct 29 '21 08:10 timi-liuliang