mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
largely based on work by @rextimmy: add premultiplied alpha
This commit is contained in:
parent
c1e99364b7
commit
bd21a207ef
6 changed files with 37 additions and 11 deletions
|
|
@ -82,6 +82,7 @@ ImplementEnumType( MaterialBlendOp,
|
|||
"@ingroup GFX\n\n")
|
||||
{ Material::None, "None", "Disable blending for this material." },
|
||||
{ Material::Mul, "Mul", "Multiplicative blending." },
|
||||
{ Material::PreMul, "PreMul", "Premultiplied alpha." },
|
||||
{ Material::Add, "Add", "Adds the color of the material to the frame buffer with full alpha for each pixel." },
|
||||
{ Material::AddAlpha, "AddAlpha", "The color is modulated by the alpha channel before being added to the frame buffer." },
|
||||
{ Material::Sub, "Sub", "Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect." },
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ public:
|
|||
{
|
||||
None = 0,
|
||||
Mul,
|
||||
PreMul,
|
||||
Add,
|
||||
AddAlpha, // add modulated with alpha channel
|
||||
Sub,
|
||||
|
|
|
|||
|
|
@ -128,6 +128,12 @@ void ProcessedMaterial::_setBlendState(Material::BlendOp blendOp, GFXStateBlockD
|
|||
desc.blendDest = GFXBlendInvSrcAlpha;
|
||||
break;
|
||||
}
|
||||
case Material::PreMul:
|
||||
{
|
||||
desc.blendSrc = GFXBlendOne;
|
||||
desc.blendDest = GFXBlendInvSrcAlpha;
|
||||
break;
|
||||
}
|
||||
case Material::LerpAlpha:
|
||||
{
|
||||
desc.blendSrc = GFXBlendSrcAlpha;
|
||||
|
|
|
|||
|
|
@ -115,6 +115,10 @@ LangElement* ShaderFeatureGLSL::assignColor( LangElement *elem,
|
|||
assign = new GenOp( "@ *= @", color, elem );
|
||||
break;
|
||||
|
||||
case Material::PreMul:
|
||||
assign = new GenOp("@.rgb = @.rgb + (@.rgb*(1.0-@.a))", color, elem, color, elem);
|
||||
break;
|
||||
|
||||
case Material::AddAlpha:
|
||||
assign = new GenOp( "@ += @ * @.a", color, elem, elem );
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -115,6 +115,10 @@ LangElement* ShaderFeatureHLSL::assignColor( LangElement *elem,
|
|||
assign = new GenOp( "@ *= @", color, elem );
|
||||
break;
|
||||
|
||||
case Material::PreMul:
|
||||
assign = new GenOp("@.rgb = @.rgb + (@.rgb*(1.0-@.a))", color, elem, color, elem);
|
||||
break;
|
||||
|
||||
case Material::AddAlpha:
|
||||
assign = new GenOp( "@ += @ * @.a", color, elem, elem );
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue