From 3cd70284fc19393fb00ca32558d3f20bb0f0d0ac Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Fri, 14 Sep 2018 21:09:53 +0300 Subject: [PATCH] [drape][metal] Added bookmark shaders for Metal. --- drape_frontend/frontend_renderer.cpp | 1 - drape_frontend/transit_scheme_renderer.cpp | 2 - shaders/Metal/map.metal | 82 ++++++++++++++++++++++ shaders/metal_program_pool.mm | 8 +-- 4 files changed, 86 insertions(+), 7 deletions(-) diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 09d3709054..df52ffec03 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -299,7 +299,6 @@ void FrontendRenderer::AcceptMessage(ref_ptr message) case Message::Type::FlushUserMarks: { - if (m_apiVersion == dp::ApiVersion::Metal) return; // TODO(@darina, @rokuz): TEMPORARY ref_ptr msg = message; TUserMarksRenderData marksRenderData = msg->AcceptRenderData(); for (auto & renderData : marksRenderData) diff --git a/drape_frontend/transit_scheme_renderer.cpp b/drape_frontend/transit_scheme_renderer.cpp index a85ac9f7bd..a3f7ab0915 100644 --- a/drape_frontend/transit_scheme_renderer.cpp +++ b/drape_frontend/transit_scheme_renderer.cpp @@ -102,11 +102,9 @@ void TransitSchemeRenderer::AddRenderData(ref_ptr context, PrepareRenderData(context, mng, tree, m_markersRenderData, std::move(renderData)); break; case TransitRenderData::Type::Text: - break; // TODO(@darina): TEMPORARY PrepareRenderData(context, mng, tree, m_textRenderData, std::move(renderData)); break; case TransitRenderData::Type::Stubs: - break; // TODO(@darina): TEMPORARY PrepareRenderData(context, mng, tree, m_colorSymbolRenderData, std::move(renderData)); break; } diff --git a/shaders/Metal/map.metal b/shaders/Metal/map.metal index ac15d1f5f4..451b30129d 100644 --- a/shaders/Metal/map.metal +++ b/shaders/Metal/map.metal @@ -752,3 +752,85 @@ fragment float4 fsMaskedTexturing(const MaskedTexturingFragment_T in [[stage_in] finalColor.a *= uniforms.u_opacity; return finalColor; } + +// UserMark + +typedef struct +{ + float3 a_position [[attribute(0)]]; + float2 a_normal [[attribute(1)]]; + float4 a_texCoords [[attribute(2)]]; + float4 a_colorAndAnimate [[attribute(3)]]; +} UserMarkVertex_T; + +typedef struct +{ + float4 position [[position]]; + float4 texCoords; + float3 maskColor; +} UserMarkFragment_T; + +typedef struct +{ + float4 color [[color(0)]]; + float depth [[depth(any)]]; +} UserMarkOut_T; + +vertex UserMarkFragment_T vsUserMark(const UserMarkVertex_T in [[stage_in]], + constant Uniforms_T & uniforms [[buffer(1)]]) +{ + UserMarkFragment_T out; + + float2 normal = in.a_normal; + if (in.a_colorAndAnimate.w > 0.0) + normal = uniforms.u_interpolation * normal; + + float4 p = float4(in.a_position, 1.0) * uniforms.u_modelView; + float4 pos = float4(normal, 0.0, 0.0) + p; + float4 projectedPivot = p * uniforms.u_projection; + out.position = ApplyPivotTransform(pos * uniforms.u_projection, uniforms.u_pivotTransform, 0.0); + out.position.z = projectedPivot.y / projectedPivot.w * 0.5 + 0.5; + out.texCoords = in.a_texCoords; + out.maskColor = in.a_colorAndAnimate.rgb; + + return out; +} + +vertex UserMarkFragment_T vsUserMarkBillboard(const UserMarkVertex_T in [[stage_in]], + constant Uniforms_T & uniforms [[buffer(1)]]) +{ + UserMarkFragment_T out; + + float2 normal = in.a_normal; + if (in.a_colorAndAnimate.w > 0.0) + normal = uniforms.u_interpolation * normal; + + float4 pivot = float4(in.a_position.xyz, 1.0) * uniforms.u_modelView; + float4 offset = float4(normal, 0.0, 0.0) * uniforms.u_projection; + float4 projectedPivot = pivot * uniforms.u_projection; + out.position = ApplyBillboardPivotTransform(projectedPivot, uniforms.u_pivotTransform, 0.0, offset.xy); + out.position.z = projectedPivot.y / projectedPivot.w * 0.5 + 0.5; + + out.texCoords = in.a_texCoords; + out.maskColor = in.a_colorAndAnimate.rgb; + return out; +} + +fragment UserMarkOut_T fsUserMark(const UserMarkFragment_T in [[stage_in]], + constant Uniforms_T & uniforms [[buffer(0)]], + texture2d u_colorTex [[texture(0)]], + sampler u_colorTexSampler [[sampler(0)]]) +{ + UserMarkOut_T out; + + float4 color = u_colorTex.sample(u_colorTexSampler, in.texCoords.xy); + float4 bgColor = u_colorTex.sample(u_colorTexSampler, in.texCoords.zw) * float4(in.maskColor, 1.0); + float4 finalColor = mix(color, mix(bgColor, color, color.a), bgColor.a); + finalColor.a = clamp(color.a + bgColor.a, 0.0, 1.0) * uniforms.u_opacity; + if (finalColor.a < 0.001) + out.depth = 1.0; + else + out.depth = in.position.z; + out.color = finalColor; + return out; +} diff --git a/shaders/metal_program_pool.mm b/shaders/metal_program_pool.mm index a351dbe20d..894e24d1a9 100644 --- a/shaders/metal_program_pool.mm +++ b/shaders/metal_program_pool.mm @@ -50,8 +50,8 @@ std::array(Program::ProgramsCount)> const kMeta ProgramInfo("vsColoredSymbol", "fsColoredSymbol", {{0, 2}}), // ColoredSymbol ProgramInfo("vsTexturing", "fsTexturing", {{0, 2}}), // Texturing ProgramInfo("vsMaskedTexturing", "fsMaskedTexturing", {{0, 3}}), // MaskedTexturing - ProgramInfo("", "", {}), // Bookmark - ProgramInfo("", "", {}), // BookmarkAnim + ProgramInfo("vsUserMark", "fsUserMark", {{0, 3}}), // Bookmark + ProgramInfo("vsUserMark", "fsUserMark", {{0, 3}}), // BookmarkAnim ProgramInfo("vsTextOutlined", "fsText", {{0, 2}, {3, 4}}), // TextOutlined ProgramInfo("vsText", "fsText", {{0, 1}, {2, 3}}), // Text ProgramInfo("vsText", "fsTextFixed", {{0, 1}, {2, 3}}), // TextFixed @@ -86,8 +86,8 @@ std::array(Program::ProgramsCount)> const kMeta ProgramInfo("vsColoredSymbolBillboard", "fsColoredSymbol", {{0, 2}}), // ColoredSymbolBillboard ProgramInfo("vsTexturingBillboard", "fsTexturing", {{0, 2}}), // TexturingBillboard ProgramInfo("vsMaskedTexturingBillboard", "fsMaskedTexturing", {{0, 3}}), // MaskedTexturingBillboard - ProgramInfo("", "", {}), // BookmarkBillboard - ProgramInfo("", "", {}), // BookmarkAnimBillboard + ProgramInfo("vsUserMarkBillboard", "fsUserMark", {{0, 3}}), // BookmarkBillboard + ProgramInfo("vsUserMarkBillboard", "fsUserMark", {{0, 3}}), // BookmarkAnimBillboard ProgramInfo("vsTextOutlinedBillboard", "fsText", {{0, 2}, {3, 4}}), // TextOutlinedBillboard ProgramInfo("vsTextBillboard", "fsText", {{0, 1}, {2, 3}}), // TextBillboard ProgramInfo("vsTextBollboard", "fsTextFixed", {{0, 1}, {2, 3}}), // TextFixedBillboard