diff --git a/src/rendering/polyrenderer/backend/poly_buffers.cpp b/src/rendering/polyrenderer/backend/poly_buffers.cpp index ad6a36857..526c5279c 100644 --- a/src/rendering/polyrenderer/backend/poly_buffers.cpp +++ b/src/rendering/polyrenderer/backend/poly_buffers.cpp @@ -86,9 +86,29 @@ void PolyVertexInputAssembly::Load(PolyTriangleThreadData *thread, const void *v const uint8_t *vertex = static_cast(vertices) + mStride * index; const float *attrVertex = reinterpret_cast(vertex + mOffsets[VATTR_VERTEX]); const float *attrTexcoord = reinterpret_cast(vertex + mOffsets[VATTR_TEXCOORD]); + const uint8_t *attrColor = reinterpret_cast(vertex + mOffsets[VATTR_COLOR]); thread->mainVertexShader.aPosition = { attrVertex[0], attrVertex[1], attrVertex[2], 1.0f }; thread->mainVertexShader.aTexCoord = { attrTexcoord[0], attrTexcoord[1] }; + + if (UseVertexData) + { + uint32_t r = attrColor[0]; + uint32_t g = attrColor[1]; + uint32_t b = attrColor[2]; + uint32_t a = attrColor[3]; + thread->mainVertexShader.aColor = MAKEARGB(a, r, g, b); + } + else + { + const auto &c = thread->mainVertexShader.Data.uVertexColor; + thread->mainVertexShader.aColor = MAKEARGB( + static_cast(c.W * 255.0f + 0.5f), + static_cast(c.X * 255.0f + 0.5f), + static_cast(c.Y * 255.0f + 0.5f), + static_cast(c.Z * 255.0f + 0.5f) + ); + } } ///////////////////////////////////////////////////////////////////////////// diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index 81efcd737..01f345160 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -330,12 +330,7 @@ void PolyTriangleThreadData::PushStreamData(const StreamData &data, const PolyPu case SHADER_Paletted: break; case SHADER_NoTexture: - drawargs.SetStyle(TriBlendMode::Fill); - drawargs.SetColor(MAKEARGB( - static_cast(mainVertexShader.Data.uVertexColor.W * 255.0f + 0.5f), - static_cast(mainVertexShader.Data.uVertexColor.X * 255.0f + 0.5f), - static_cast(mainVertexShader.Data.uVertexColor.Y * 255.0f + 0.5f), - static_cast(mainVertexShader.Data.uVertexColor.Z * 255.0f + 0.5f)), 0); + drawargs.SetStyle(TriBlendMode::FillTranslucent); return; case SHADER_BasicFuzz: case SHADER_SmoothFuzz: @@ -346,7 +341,6 @@ void PolyTriangleThreadData::PushStreamData(const StreamData &data, const PolyPu case SHADER_SmoothNoiseFuzz: case SHADER_SoftwareFuzz: drawargs.SetStyle(TriBlendMode::Fuzzy); - drawargs.SetColor(0xff000000, 0); return; } @@ -431,7 +425,7 @@ void PolyTriangleThreadData::SetDepthRange(float min, float max) void PolyTriangleThreadData::SetDepthBias(float depthBiasConstantFactor, float depthBiasSlopeFactor) { - depthbias = (float)(depthBiasConstantFactor / 65536.0); + depthbias = (float)(depthBiasConstantFactor / 2500.0); } void PolyTriangleThreadData::SetColorMask(bool r, bool g, bool b, bool a) @@ -659,6 +653,8 @@ void PolyTriangleThreadData::DrawShadedTriangle(const ShadedTriVertex *const* ve if (IsDegenerate(vert)) return; + drawargs.SetColor(vert[0]->vColor, 0); + // Cull, clip and generate additional vertices as needed ScreenTriVertex clippedvert[max_additional_vertices]; int numclipvert = ClipEdge(vert); diff --git a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h index 56486d047..a431f8941 100644 --- a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -15,6 +15,7 @@ public: Vec4f gl_Position; float gl_ClipDistance[5]; Vec4f vTexCoord; + uint32_t vColor; Vec4f pixelpos; }; @@ -24,13 +25,12 @@ public: // Input Vec4f aPosition; Vec2f aTexCoord; - Vec4f aColor; + uint32_t aColor; Vec4f aVertex2; Vec4f aNormal; Vec4f aNormal2; // Output - Vec4f vColor; Vec3f glowdist; Vec3f gradientdist; Vec4f vWorldNormal; @@ -243,6 +243,8 @@ public: pixelpos = (*objectToWorld) * objpos; } + vColor = drawargs->Color(); + // Calculate gl_ClipDistance[i] for (int i = 0; i < 3; i++) { diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.cpp b/src/rendering/polyrenderer/drawers/screen_triangle.cpp index 1bc6a708c..e8ce32528 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/screen_triangle.cpp @@ -2128,6 +2128,7 @@ void(*ScreenTriangle::SpanDrawers8[])(int, int, int, const TriDrawTriangleArgs * &DrawSpan8, &DrawSpan8, &DrawSpan8, + &DrawSpan8, &DrawSpan8, &DrawSpan8, &DrawSpan8, @@ -2160,6 +2161,7 @@ void(*ScreenTriangle::SpanDrawers32[])(int, int, int, const TriDrawTriangleArgs &DrawSpan32, &DrawSpan32, &DrawSpan32, + &DrawSpan32, &DrawSpan32, &DrawSpan32, &DrawSpan32, diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.h b/src/rendering/polyrenderer/drawers/screen_triangle.h index 92d346376..3e9bef620 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.h +++ b/src/rendering/polyrenderer/drawers/screen_triangle.h @@ -104,6 +104,7 @@ enum class TriBlendMode FogBoundary, SrcColor, Fill, + FillTranslucent, Normal, Fuzzy, Stencil, @@ -162,6 +163,7 @@ namespace TriScreenDrawerModes struct StyleFogBoundary { static const int BlendOp = STYLEOP_Add, BlendSrc = STYLEALPHA_One, BlendDest = STYLEALPHA_Zero, Flags = STYLEF_Alpha1, SWFlags = SWSTYLEF_FogBoundary; }; struct StyleSrcColor { static const int BlendOp = STYLEOP_Add, BlendSrc = STYLEALPHA_Src, BlendDest = STYLEALPHA_InvSrc, Flags = STYLEF_Alpha1, SWFlags = SWSTYLEF_SrcColorOneMinusSrcColor; }; struct StyleFill { static const int BlendOp = STYLEOP_Add, BlendSrc = STYLEALPHA_One, BlendDest = STYLEALPHA_Zero, Flags = STYLEF_Alpha1, SWFlags = SWSTYLEF_Fill; }; + struct StyleFillTranslucent { static const int BlendOp = STYLEOP_Add, BlendSrc = STYLEALPHA_Src, BlendDest = STYLEALPHA_InvSrc, Flags = STYLEF_Alpha1, SWFlags = SWSTYLEF_Fill; }; struct StyleNormal { static const int BlendOp = STYLEOP_Add, BlendSrc = STYLEALPHA_Src, BlendDest = STYLEALPHA_InvSrc, Flags = STYLEF_Alpha1, SWFlags = 0; }; struct StyleFuzzy { static const int BlendOp = STYLEOP_Fuzz, BlendSrc = STYLEALPHA_Src, BlendDest = STYLEALPHA_InvSrc, Flags = 0, SWFlags = 0; };