diff --git a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp index 4ee444067..3dca72544 100644 --- a/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp +++ b/src/r_compiler/fixedfunction/drawtrianglecodegen.cpp @@ -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; diff --git a/src/r_compiler/llvmdrawers.cpp b/src/r_compiler/llvmdrawers.cpp index 82cac4a18..6745af8e4 100644 --- a/src/r_compiler/llvmdrawers.cpp +++ b/src/r_compiler/llvmdrawers.cpp @@ -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) diff --git a/src/r_compiler/llvmdrawers.h b/src/r_compiler/llvmdrawers.h index dbaef8b47..6113b1d04 100644 --- a/src/r_compiler/llvmdrawers.h +++ b/src/r_compiler/llvmdrawers.h @@ -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)) diff --git a/src/r_poly_decal.cpp b/src/r_poly_decal.cpp index f23ca2863..ef20c9de7 100644 --- a/src/r_poly_decal.cpp +++ b/src/r_poly_decal.cpp @@ -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); } diff --git a/src/r_poly_sprite.cpp b/src/r_poly_sprite.cpp index bc032b91c..38ddd46df 100644 --- a/src/r_poly_sprite.cpp +++ b/src/r_poly_sprite.cpp @@ -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; diff --git a/src/r_poly_triangle.h b/src/r_poly_triangle.h index 9fd8b7a9a..7d58ed5ed 100644 --- a/src/r_poly_triangle.h +++ b/src/r_poly_triangle.h @@ -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) { @@ -85,8 +85,17 @@ public: return; } } - - SetTexture(texture); + + if (forcePal) + { + textureWidth = texture->GetWidth(); + textureHeight = texture->GetHeight(); + texturePixels = texture->GetPixels(); + } + else + { + SetTexture(texture); + } } void SetColormap(FSWColormap *base_colormap)