Add stencil blend mode as apparently the shaded mode uses indices whiles stencil uses mask/alpha..

This commit is contained in:
Magnus Norddahl 2016-11-21 05:52:02 +01:00
parent e7d64a380a
commit 5e9c9c825d
6 changed files with 33 additions and 12 deletions

View file

@ -581,10 +581,13 @@ SSAVec4i DrawTriangleCodegen::ProcessPixel32(SSAVec4i bg, SSAInt *varying)
fg = Sample32(uvoffset);
output = blend_revsub(shade_bgra_simple(fg, currentlight), bg, srcalpha, calc_blend_bgalpha(fg, destalpha));
break;
case TriBlendMode::Shaded:
case TriBlendMode::Stencil:
fg = Sample32(uvoffset);
output = blend_stencil(shade_bgra_simple(SSAVec4i::unpack(color), currentlight), fg[3], bg, srcalpha, destalpha);
break;
case TriBlendMode::Shaded:
output = blend_stencil(shade_bgra_simple(SSAVec4i::unpack(color), currentlight), Sample8(uvoffset), bg, srcalpha, destalpha);
break;
case TriBlendMode::TranslateCopy:
fg = TranslateSample32(uvoffset);
output = blend_copy(shade_bgra_simple(fg, currentlight));
@ -662,6 +665,9 @@ SSAInt DrawTriangleCodegen::ProcessPixel8(SSAInt bg, SSAInt *varying)
fg = ToBgra(Shade8(Sample8(uvoffset)));
output = ToPal8(blend_revsub(fg, ToBgra(bg), srcalpha, calc_blend_bgalpha(fg, destalpha)));
break;
case TriBlendMode::Stencil:
output = ToPal8(blend_stencil(ToBgra(Shade8(color)), (Sample8(uvoffset) == SSAInt(0)).select(SSAInt(0), SSAInt(256)), ToBgra(bg), srcalpha, destalpha));
break;
case TriBlendMode::Shaded:
output = ToPal8(blend_stencil(ToBgra(Shade8(color)), Sample8(uvoffset), ToBgra(bg), srcalpha, destalpha));
break;

View file

@ -127,7 +127,7 @@ LLVMDrawers *LLVMDrawers::Instance()
LLVMDrawersImpl::LLVMDrawersImpl()
{
int version = 4; // Increment this number if the drawer codegen is modified (forces recreation of the module).
int version = 5; // Increment this number if the drawer codegen is modified (forces recreation of the module).
std::string targetCPU = mProgram.GetTargetCPU();
bool loaded = mProgram.LoadCachedModule(version, targetCPU);
if (!loaded)

View file

@ -281,7 +281,8 @@ enum class TriBlendMode
Add, // blend_add(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
Sub, // blend_sub(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
RevSub, // blend_revsub(shade(fg), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
Shaded, // blend_stencil(shade(color), fg, bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
Stencil, // blend_stencil(shade(color), fg.a, bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
Shaded, // blend_stencil(shade(color), fg.index, bg, srcalpha, calc_blend_bgalpha(fg, destalpha))
TranslateCopy, // blend_copy(shade(translate(fg)))
TranslateAlphaBlend, // blend_alpha_blend(shade(translate(fg)), bg)
TranslateAdd, // blend_add(shade(translate(fg)), bg, srcalpha, calc_blend_bgalpha(fg, destalpha))

View file

@ -130,6 +130,8 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, co
PolyDrawArgs args;
args.uniforms.flags = 0;
args.SetColormap(front->ColorMap);
args.SetTexture(tex, decal->Translation, true);
if (fullbrightSprite || fixedlightlev >= 0 || fixedcolormap)
{
args.uniforms.light = 256;
@ -150,8 +152,8 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, co
args.uniforms.color = ((uint32_t)decal->AlphaColor) >> 24;
}
args.uniforms.srcalpha = 256;
args.uniforms.destalpha = 0;
args.uniforms.srcalpha = (uint32_t)(decal->Alpha * 256.0 + 0.5);
args.uniforms.destalpha = 256 - args.uniforms.srcalpha;
args.objectToClip = &worldToClip;
args.vinput = vertices;
@ -160,8 +162,6 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, co
args.ccw = true;
args.stenciltestvalue = 0;
args.stencilwritevalue = 1;
args.SetTexture(tex);
args.SetColormap(front->ColorMap);
//mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor);
PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::Shaded);
}

View file

@ -185,14 +185,14 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subse
args.uniforms.destalpha = (uint32_t)(256 - thing->Alpha * 256);
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256);
args.uniforms.color = 0xff000000 | thing->fillcolor;
blendmode = TriBlendMode::Shaded;
blendmode = TriBlendMode::Stencil;
}
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_AddStencil])
{
args.uniforms.destalpha = 256;
args.uniforms.srcalpha = (uint32_t)(thing->Alpha * 256) * 2; // Don't know this needs to be multiplied by two..
args.uniforms.color = 0xff000000 | thing->fillcolor;
blendmode = TriBlendMode::Shaded;
blendmode = TriBlendMode::Stencil;
}
else if (thing->RenderStyle == LegacyRenderStyles[STYLE_Shaded])
{
@ -215,6 +215,11 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subse
blendmode = args.translation ? TriBlendMode::TranslateAdd : TriBlendMode::Add;
}
if (blendmode == TriBlendMode::Shaded)
{
args.SetTexture(tex, thing->Translation, true);
}
if (!r_swtruecolor)
{
uint32_t r = (args.uniforms.color >> 16) & 0xff;

View file

@ -67,7 +67,7 @@ public:
translation = nullptr;
}
void SetTexture(FTexture *texture, uint32_t translationID)
void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false)
{
if (translationID != 0xffffffff && translationID != 0)
{
@ -86,7 +86,16 @@ public:
}
}
SetTexture(texture);
if (forcePal)
{
textureWidth = texture->GetWidth();
textureHeight = texture->GetHeight();
texturePixels = texture->GetPixels();
}
else
{
SetTexture(texture);
}
}
void SetColormap(FSWColormap *base_colormap)