diff --git a/drape/shaders/arrow3d_fragment_shader.fsh b/drape/shaders/arrow3d_fragment_shader.fsh index 523906d492..e6dcb2dc06 100644 --- a/drape/shaders/arrow3d_fragment_shader.fsh +++ b/drape/shaders/arrow3d_fragment_shader.fsh @@ -1,4 +1,4 @@ -varying float v_intensity; +varying vec2 v_intensity; #ifdef SAMSUNG_GOOGLE_NEXUS uniform sampler2D u_colorTex; @@ -14,7 +14,8 @@ void main() lowp vec4 fakeColor = texture2D(u_colorTex, vec2(0.0, 0.0)) * kFakeColorScalar; #endif - vec4 resColor = vec4((v_intensity * 0.3 + 0.7) * u_color.rgb, u_color.a); + float alpha = smoothstep(0.8, 1.0, v_intensity.y); + vec4 resColor = vec4((v_intensity.x * 0.5 + 0.5) * u_color.rgb, u_color.a * alpha); #ifdef SAMSUNG_GOOGLE_NEXUS gl_FragColor = resColor + fakeColor; diff --git a/drape/shaders/arrow3d_vertex_shader.vsh b/drape/shaders/arrow3d_vertex_shader.vsh index 1fd6741a9c..ddd1063394 100644 --- a/drape/shaders/arrow3d_vertex_shader.vsh +++ b/drape/shaders/arrow3d_vertex_shader.vsh @@ -1,17 +1,15 @@ -attribute vec3 a_pos; +attribute vec4 a_pos; attribute vec3 a_normal; uniform mat4 m_transform; -varying float v_intensity; +varying vec2 v_intensity; -const vec4 lightDir = vec4(1.0, 0.0, 3.0, 0.0); +const vec3 lightDir = vec3(0.316, 0.0, 0.948); void main() { - vec4 position = m_transform * vec4(a_pos, 1.0); - vec4 normal = m_transform * vec4(a_normal + a_pos, 1.0); - v_intensity = max(0.0, -dot(normalize(lightDir), normalize(normal - position))); + vec4 position = m_transform * vec4(a_pos.xyz, 1.0); + v_intensity = vec2(max(0.0, -dot(lightDir, a_normal)), a_pos.w); gl_Position = position; } - diff --git a/drape_frontend/arrow3d.cpp b/drape_frontend/arrow3d.cpp index c4ee715bdb..5453040db5 100644 --- a/drape_frontend/arrow3d.cpp +++ b/drape_frontend/arrow3d.cpp @@ -21,8 +21,7 @@ namespace df { -double const kArrowSizeX = 2.0; -double const kArrowSizeY = 3.0; +double const kArrowSize = 22.0; double const kArrow3dScaleMin = 1.0; double const kArrow3dScaleMax = 2.2; double const kArrow3dMinZoom = 16; @@ -31,31 +30,33 @@ Arrow3d::Arrow3d() : m_state(gpu::ARROW_3D_PROGRAM, dp::GLState::OverlayLayer) { m_vertices = { - 0.0f, 0.0f, -1.0f, - -1.0f, -1.0f, 0.0f, - 0.0f, 2.0f, 0.0f, - - 0.0f, 0.0f, -1.0f, - 0.0f, 2.0f, 0.0f, - 1.0f, -1.0f, 0.0f, - - 0.0f, 0.0f, -1.0f, - 0.0f, -0.5f, 0.0f, - -1.0f, -1.0f, 0.0f, - - 0.0f, 0.0f, -1.0f, - 1.0f, -1.0f, 0.0f, - 0.0f, -0.5f, 0.0f + 0.0f, 0.0f, -1.0f, 1.0, -1.2f, -1.0f, 0.0f, 1.0, 0.0f, 2.0f, 0.0f, 1.0, + 0.0f, 0.0f, -1.0f, 1.0, 0.0f, 2.0f, 0.0f, 1.0, 1.2f, -1.0f, 0.0f, 1.0, + 0.0f, 0.0f, -1.0f, 1.0, 0.0f, -0.5f, 0.0f, 1.0, -1.2f, -1.0f, 0.0f, 1.0, + 0.0f, 0.0f, -1.0f, 1.0, 1.2f, -1.0f, 0.0f, 1.0, 0.0f, -0.5f, 0.0f, 1.0, + + 0.0f, 2.27f, 0.0f, 0.0, 1.4f, -1.17f, 0.0f, 0.0, 0.0f, 2.0f, 0.0f, 1.0, + 0.0f, 2.0f, 0.0f, 1.0, 1.4f, -1.17f, 0.0f, 0.0, 1.2f, -1.0f, 0.0f, 1.0, + 0.0f, 2.27f, 0.0f, 0.0, 0.0f, 2.0f, 0.0f, 1.0, -1.4f, -1.17f, 0.0f, 0.0, + 0.0f, 2.0f, 0.0f, 1.0, -1.2f, -1.0f, 0.0f, 1.0, -1.4f, -1.17f, 0.0f, 0.0, + + 1.2f, -1.0f, 0.0f, 1.0, 1.4f, -1.17f, 0.0f, 0.0, 0.0f, -0.67f, 0.0f, 0.0, + 0.0f, -0.5f, 0.0f, 1.0, 1.2f, -1.0f, 0.0f, 1.0, 0.0f, -0.67f, 0.0f, 0.0, + -1.2f, -1.0f, 0.0f, 1.0, 0.0f, -0.67f, 0.0f, 0.0, -1.4f, -1.17f, 0.0f, 0.0, + 0.0f, -0.5f, 0.0f, 1.0, 0.0f, -0.67f, 0.0f, 0.0, -1.2f, -1.0f, 0.0f, 1.0, }; - m_normals.resize(m_vertices.size()); - for (size_t triangle = 0; triangle < m_vertices.size() / 9; ++triangle) + int constexpr kVerticesInRow = 12; + int constexpr kComponentsInVertex = 4; + m_normals.reserve(m_vertices.size()); + for (size_t triangle = 0; triangle < m_vertices.size() / kVerticesInRow; ++triangle) { - glsl::vec3 v[3]; + glsl::vec4 v[3]; for (size_t vertex = 0; vertex < 3; ++vertex) { - size_t const offset = triangle * 9 + vertex * 3; - v[vertex] = glsl::vec3(m_vertices[offset], m_vertices[offset + 1], m_vertices[offset + 2]); + size_t const offset = triangle * kVerticesInRow + vertex * kComponentsInVertex; + v[vertex] = glsl::vec4(m_vertices[offset], m_vertices[offset + 1], + m_vertices[offset + 2], m_vertices[offset + 3]); } glsl::vec3 normal = glsl::cross(glsl::vec3(v[1].x - v[0].x, v[1].y - v[0].y, v[1].z - v[0].z), @@ -64,10 +65,9 @@ Arrow3d::Arrow3d() for (size_t vertex = 0; vertex < 3; ++vertex) { - size_t const offset = triangle * 9 + vertex * 3; - m_normals[offset] = normal.x; - m_normals[offset + 1] = normal.y; - m_normals[offset + 2] = normal.z; + m_normals.push_back(normal.x); + m_normals.push_back(normal.y); + m_normals.push_back(normal.z); } } } @@ -153,9 +153,9 @@ void Arrow3d::Render(ScreenBase const & screen, ref_ptr m double const t = (zoomLevel - kArrow3dMinZoom) / (kMaxZoom - kArrow3dMinZoom); double const arrowScale = kArrow3dScaleMin * (1.0 - t) + kArrow3dScaleMax * t; - double const scaleX = m_pixelWidth * arrowScale * 2.0 / screen.PixelRect().SizeX() / kArrowSizeX; - double const scaleY = m_pixelHeight * arrowScale * 2.0 / screen.PixelRect().SizeY() / kArrowSizeY; - double const scaleZ = scaleX; + double const scaleX = kArrowSize * arrowScale * 2.0 / screen.PixelRect().SizeX(); + double const scaleY = kArrowSize * arrowScale * 2.0 / screen.PixelRect().SizeY(); + double const scaleZ = screen.isPerspective() ? (0.002 * screen.GetDepth3d()) : 1.0; m2::PointD const pos = screen.GtoP(m_position); double const dX = 2.0 * pos.x / screen.PixelRect().SizeX() - 1.0; @@ -177,7 +177,8 @@ void Arrow3d::Render(ScreenBase const & screen, ref_ptr m translateM(3, 1) = -dY; math::Matrix modelTransform = rotateM * scaleM * translateM; - modelTransform = modelTransform * math::Matrix(screen.Pto3dMatrix()); + if (screen.isPerspective()) + modelTransform = modelTransform * math::Matrix(screen.Pto3dMatrix()); dp::UniformValuesStorage uniforms; uniforms.SetMatrix4x4Value("m_transform", modelTransform.m_data); @@ -190,13 +191,13 @@ void Arrow3d::Render(ScreenBase const & screen, ref_ptr m GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer); GLFunctions::glEnableVertexAttribute(m_attributePosition); - GLFunctions::glVertexAttributePointer(m_attributePosition, 3, gl_const::GLFloatType, false, 0, 0); + GLFunctions::glVertexAttributePointer(m_attributePosition, 4, gl_const::GLFloatType, false, 0, 0); GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer); GLFunctions::glEnableVertexAttribute(m_attributeNormal); GLFunctions::glVertexAttributePointer(m_attributeNormal, 3, gl_const::GLFloatType, false, 0, 0); - GLFunctions::glDrawArrays(gl_const::GLTriangles, 0, m_vertices.size() / 3); + GLFunctions::glDrawArrays(gl_const::GLTriangles, 0, m_vertices.size() / 4); prg->Unbind(); GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer); diff --git a/drape_frontend/my_position.cpp b/drape_frontend/my_position.cpp index a5645cc3cd..0724e478dd 100644 --- a/drape_frontend/my_position.cpp +++ b/drape_frontend/my_position.cpp @@ -113,7 +113,7 @@ void MyPosition::RenderMyPosition(ScreenBase const & screen, ref_ptr mng, dp::UniformValuesStorage const & commonUniforms) { - if (screen.isPerspective() && m_isRoutingMode && m_showAzimuth) + if (m_showAzimuth) { m_arrow3d.SetPosition(m_position); m_arrow3d.SetAzimuth(m_azimuth); @@ -126,9 +126,7 @@ void MyPosition::RenderMyPosition(ScreenBase const & screen, uniforms.SetFloatValue("u_position", m_position.x, m_position.y, dp::depth::MY_POSITION_MARK); uniforms.SetFloatValue("u_azimut", -(m_azimuth + screen.GetAngle())); uniforms.SetFloatValue("u_opacity", 1.0); - RenderPart(mng, uniforms, (m_showAzimuth == true) ? - (m_obsoletePosition ? MY_POSITION_ARROW_GRAY : MY_POSITION_ARROW) : - MY_POSITION_POINT); + RenderPart(mng, uniforms, MY_POSITION_POINT); } } diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 0feaf86a64..80d361b3c1 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -19,8 +19,8 @@ namespace df namespace { -int const kPositionOffsetY = 75; -int const kPositionOffsetYIn3D = 80; +int const kPositionOffsetY = 104; +int const kPositionOffsetYIn3D = 104; double const kGpsBearingLifetimeSec = 5.0; double const kMinSpeedThresholdMps = 1.0; diff --git a/geometry/screenbase.hpp b/geometry/screenbase.hpp index b5f43a1562..9ac6650bd6 100644 --- a/geometry/screenbase.hpp +++ b/geometry/screenbase.hpp @@ -141,6 +141,8 @@ public: double GetAngleFOV() const { return m_3dFOV; } double GetScale3d() const { return m_3dScale; } + double GetDepth3d() const { return m_3dFarZ - m_3dNearZ; } + m2::PointD P3dtoP(m2::PointD const & pt) const; Matrix3dT const & Pto3dMatrix() const { return m_Pto3d; }