Add shaded blend mode for the decals

This commit is contained in:
Magnus Norddahl 2016-11-17 14:28:14 +01:00
parent 511eb59479
commit b02e3d9514
5 changed files with 36 additions and 11 deletions

View file

@ -260,7 +260,7 @@ void DrawTriangleCodegen::LoopBlockX(TriDrawVariant variant, bool truecolor)
SetStencilBlock(x / 8 + y / 8 * stencilPitch); SetStencilBlock(x / 8 + y / 8 * stencilPitch);
SSABool covered = a == SSAInt(0xF) && b == SSAInt(0xF) && c == SSAInt(0xF) && !clipneeded; SSABool covered = a == SSAInt(0xF) && b == SSAInt(0xF) && c == SSAInt(0xF) && !clipneeded;
if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::FillSubsector) if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::DrawShadedSubsector && variant != TriDrawVariant::FillSubsector)
{ {
covered = covered && StencilIsSingleValue(); covered = covered && StencilIsSingleValue();
} }
@ -287,7 +287,7 @@ void DrawTriangleCodegen::LoopBlockX(TriDrawVariant variant, bool truecolor)
void DrawTriangleCodegen::LoopFullBlock(TriDrawVariant variant, bool truecolor) void DrawTriangleCodegen::LoopFullBlock(TriDrawVariant variant, bool truecolor)
{ {
SSAIfBlock branch_stenciltest; SSAIfBlock branch_stenciltest;
if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::FillSubsector) if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::DrawShadedSubsector && variant != TriDrawVariant::FillSubsector)
{ {
branch_stenciltest.if_block(StencilGetSingle() == stencilTestValue); branch_stenciltest.if_block(StencilGetSingle() == stencilTestValue);
} }
@ -325,7 +325,7 @@ void DrawTriangleCodegen::LoopFullBlock(TriDrawVariant variant, bool truecolor)
varying[i] = stack_varying[i].load(); varying[i] = stack_varying[i].load();
loopx.loop_block(ix < SSAInt(q), q); loopx.loop_block(ix < SSAInt(q), q);
{ {
if (variant == TriDrawVariant::DrawSubsector || variant == TriDrawVariant::FillSubsector) if (variant == TriDrawVariant::DrawSubsector || variant == TriDrawVariant::DrawShadedSubsector || variant == TriDrawVariant::FillSubsector)
{ {
SSAIfBlock branch; SSAIfBlock branch;
branch.if_block(subsectorbuffer[ix].load(true) >= subsectorDepth); branch.if_block(subsectorbuffer[ix].load(true) >= subsectorDepth);
@ -353,7 +353,7 @@ void DrawTriangleCodegen::LoopFullBlock(TriDrawVariant variant, bool truecolor)
loopy.end_block(); loopy.end_block();
} }
if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::FillSubsector) if (variant != TriDrawVariant::DrawSubsector && variant != TriDrawVariant::DrawShadedSubsector && variant != TriDrawVariant::FillSubsector)
{ {
branch_stenciltest.end_block(); branch_stenciltest.end_block();
} }
@ -404,7 +404,7 @@ void DrawTriangleCodegen::LoopPartialBlock(TriDrawVariant variant, bool truecolo
SSABool visible = (ix + x >= clipleft) && (ix + x < clipright) && (cliptop <= y + iy) && (clipbottom > y + iy); SSABool visible = (ix + x >= clipleft) && (ix + x < clipright) && (cliptop <= y + iy) && (clipbottom > y + iy);
SSABool covered = CX1 > SSAInt(0) && CX2 > SSAInt(0) && CX3 > SSAInt(0) && visible; SSABool covered = CX1 > SSAInt(0) && CX2 > SSAInt(0) && CX3 > SSAInt(0) && visible;
if (variant == TriDrawVariant::DrawSubsector || variant == TriDrawVariant::FillSubsector) if (variant == TriDrawVariant::DrawSubsector || variant == TriDrawVariant::DrawShadedSubsector || variant == TriDrawVariant::FillSubsector)
{ {
covered = covered && subsectorbuffer[ix].load(true) >= subsectorDepth; covered = covered && subsectorbuffer[ix].load(true) >= subsectorDepth;
} }
@ -473,14 +473,14 @@ void DrawTriangleCodegen::ProcessPixel(SSAUBytePtr buffer, SSAIntPtr subsectorbu
SSAInt uvoffset = upos * textureHeight + vpos; SSAInt uvoffset = upos * textureHeight + vpos;
if (truecolor) if (truecolor)
{
if (variant == TriDrawVariant::DrawMasked || variant == TriDrawVariant::DrawSubsector)
{ {
SSAVec4i fg = texturePixels[uvoffset * 4].load_vec4ub(true); SSAVec4i fg = texturePixels[uvoffset * 4].load_vec4ub(true);
SSAInt fg_alpha = fg[3]; SSAInt fg_alpha = fg[3];
fg = (fg * currentlight) >> 8; fg = (fg * currentlight) >> 8;
fg.insert(3, fg_alpha); fg.insert(3, fg_alpha);
if (variant == TriDrawVariant::DrawMasked || variant == TriDrawVariant::DrawSubsector)
{
SSAIfBlock branch_transparency; SSAIfBlock branch_transparency;
branch_transparency.if_block(fg_alpha > SSAInt(127)); branch_transparency.if_block(fg_alpha > SSAInt(127));
{ {
@ -490,8 +490,22 @@ void DrawTriangleCodegen::ProcessPixel(SSAUBytePtr buffer, SSAIntPtr subsectorbu
} }
branch_transparency.end_block(); branch_transparency.end_block();
} }
else if (variant == TriDrawVariant::DrawShadedSubsector)
{
SSAInt alpha = texturePixels[uvoffset * 4].load(true).zext_int();
alpha = alpha + (alpha >> 7); // // 255 -> 256
SSAInt inv_alpha = 256 - alpha;
SSAVec4i bgcolor = buffer.load_vec4ub(false);
buffer.store_vec4ub(blend_add(shade_bgra_simple(SSAVec4i::unpack(solidcolor), currentlight), bgcolor, alpha, inv_alpha));
}
else else
{ {
SSAVec4i fg = texturePixels[uvoffset * 4].load_vec4ub(true);
SSAInt fg_alpha = fg[3];
fg = (fg * currentlight) >> 8;
fg.insert(3, fg_alpha);
buffer.store_vec4ub(fg); buffer.store_vec4ub(fg);
subsectorbuffer.store(subsectorDepth); subsectorbuffer.store(subsectorDepth);
} }

View file

@ -190,6 +190,8 @@ LLVMDrawersImpl::LLVMDrawersImpl()
CodegenDrawTriangle("TriDraw32", TriDrawVariant::Draw, true); CodegenDrawTriangle("TriDraw32", TriDrawVariant::Draw, true);
CodegenDrawTriangle("TriDrawSubsector8", TriDrawVariant::DrawSubsector, false); CodegenDrawTriangle("TriDrawSubsector8", TriDrawVariant::DrawSubsector, false);
CodegenDrawTriangle("TriDrawSubsector32", TriDrawVariant::DrawSubsector, true); CodegenDrawTriangle("TriDrawSubsector32", TriDrawVariant::DrawSubsector, true);
CodegenDrawTriangle("TriDrawShadedSubsector8", TriDrawVariant::DrawShadedSubsector, false);
CodegenDrawTriangle("TriDrawShadedSubsector32", TriDrawVariant::DrawShadedSubsector, true);
CodegenDrawTriangle("TriFillSubsector8", TriDrawVariant::FillSubsector, false); CodegenDrawTriangle("TriFillSubsector8", TriDrawVariant::FillSubsector, false);
CodegenDrawTriangle("TriFillSubsector32", TriDrawVariant::FillSubsector, true); CodegenDrawTriangle("TriFillSubsector32", TriDrawVariant::FillSubsector, true);
CodegenDrawTriangle("TriFill8", TriDrawVariant::Fill, false); CodegenDrawTriangle("TriFill8", TriDrawVariant::Fill, false);
@ -264,6 +266,8 @@ LLVMDrawersImpl::LLVMDrawersImpl()
TriDraw32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDraw32"); TriDraw32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDraw32");
TriDrawSubsector8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawSubsector8"); TriDrawSubsector8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawSubsector8");
TriDrawSubsector32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawSubsector32"); TriDrawSubsector32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawSubsector32");
TriDrawShadedSubsector8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawShadedSubsector8");
TriDrawShadedSubsector32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriDrawShadedSubsector32");
TriFillSubsector8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFillSubsector8"); TriFillSubsector8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFillSubsector8");
TriFillSubsector32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFillSubsector32"); TriFillSubsector32 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFillSubsector32");
TriFill8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFill8"); TriFill8 = mProgram.GetProcAddress<void(const TriDrawTriangleArgs *, WorkerThreadData *)>("TriFill8");

View file

@ -266,6 +266,7 @@ enum class TriDrawVariant
DrawMasked, DrawMasked,
Fill, Fill,
DrawSubsector, DrawSubsector,
DrawShadedSubsector,
FillSubsector, FillSubsector,
Stencil, Stencil,
}; };
@ -349,6 +350,8 @@ public:
void(*TriDraw32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriDraw32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriDrawSubsector8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriDrawSubsector8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriDrawSubsector32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriDrawSubsector32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriDrawShadedSubsector8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriDrawShadedSubsector32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriFillSubsector8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriFillSubsector8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriFillSubsector32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriFillSubsector32)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;
void(*TriFill8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr; void(*TriFill8)(const TriDrawTriangleArgs *, WorkerThreadData *) = nullptr;

View file

@ -155,5 +155,7 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, co
args.stenciltestvalue = 0; args.stenciltestvalue = 0;
args.stencilwritevalue = 1; args.stencilwritevalue = 1;
args.SetTexture(tex); args.SetTexture(tex);
PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector); args.solidcolor = decal->AlphaColor;
//mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor);
PolyTriangleDrawer::draw(args, TriDrawVariant::DrawShadedSubsector);
} }

View file

@ -62,6 +62,7 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, TriDrawVarian
case TriDrawVariant::Draw: drawfunc = r_swtruecolor ? llvm->TriDraw32: llvm->TriDraw8; break; case TriDrawVariant::Draw: drawfunc = r_swtruecolor ? llvm->TriDraw32: llvm->TriDraw8; break;
case TriDrawVariant::Fill: drawfunc = r_swtruecolor ? llvm->TriFill32 : llvm->TriFill8; break; case TriDrawVariant::Fill: drawfunc = r_swtruecolor ? llvm->TriFill32 : llvm->TriFill8; break;
case TriDrawVariant::DrawSubsector: drawfunc = r_swtruecolor ? llvm->TriDrawSubsector32 : llvm->TriDrawSubsector8; break; case TriDrawVariant::DrawSubsector: drawfunc = r_swtruecolor ? llvm->TriDrawSubsector32 : llvm->TriDrawSubsector8; break;
case TriDrawVariant::DrawShadedSubsector: drawfunc = r_swtruecolor ? llvm->TriDrawShadedSubsector32 : llvm->TriDrawShadedSubsector8; break;
case TriDrawVariant::FillSubsector: drawfunc = r_swtruecolor ? llvm->TriFillSubsector32 : llvm->TriFillSubsector8; break; case TriDrawVariant::FillSubsector: drawfunc = r_swtruecolor ? llvm->TriFillSubsector32 : llvm->TriFillSubsector8; break;
case TriDrawVariant::Stencil: drawfunc = llvm->TriStencil; break; case TriDrawVariant::Stencil: drawfunc = llvm->TriStencil; break;
} }
@ -72,6 +73,7 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, TriDrawVarian
case TriDrawVariant::Draw: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::draw32 : ScreenPolyTriangleDrawer::draw; break; case TriDrawVariant::Draw: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::draw32 : ScreenPolyTriangleDrawer::draw; break;
case TriDrawVariant::FillSubsector: case TriDrawVariant::FillSubsector:
case TriDrawVariant::Fill: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::fill32 : ScreenPolyTriangleDrawer::fill; break; case TriDrawVariant::Fill: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::fill32 : ScreenPolyTriangleDrawer::fill; break;
case TriDrawVariant::DrawShadedSubsector:
case TriDrawVariant::DrawSubsector: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::drawsubsector32 : llvm->TriDrawSubsector8; break; case TriDrawVariant::DrawSubsector: drawfunc = r_swtruecolor ? ScreenPolyTriangleDrawer::drawsubsector32 : llvm->TriDrawSubsector8; break;
case TriDrawVariant::Stencil: drawfunc = ScreenPolyTriangleDrawer::stencil; break; case TriDrawVariant::Stencil: drawfunc = ScreenPolyTriangleDrawer::stencil; break;
} }