From 90b8409017eebadd0f33b2b05050e118d27a69f6 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Tue, 22 Jan 2019 14:34:44 -0800 Subject: [PATCH] Better way of drawing the view sphere outline. --- common/lc_context.cpp | 1 + common/lc_viewsphere.cpp | 24 +++++++++++++++------ resources/shaders/unlit_view_sphere_ps.glsl | 3 +-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/lc_context.cpp b/common/lc_context.cpp index 0347c1ab..e8162aea 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -374,6 +374,7 @@ void lcContext::SetMaterial(lcMaterialType MaterialType) } break; + case LC_MATERIAL_UNLIT_VIEW_SPHERE: case LC_NUM_MATERIALS: break; } diff --git a/common/lc_viewsphere.cpp b/common/lc_viewsphere.cpp index e65c81de..305b8624 100644 --- a/common/lc_viewsphere.cpp +++ b/common/lc_viewsphere.cpp @@ -166,6 +166,23 @@ void lcViewSphere::Draw() int Bottom = (Location == lcViewSphereLocation::BOTTOM_LEFT || Location == lcViewSphereLocation::BOTTOM_RIGHT) ? 0 : Height - ViewportSize; Context->SetViewport(Left, Bottom, ViewportSize, ViewportSize); + glDepthFunc(GL_ALWAYS); + glEnable(GL_CULL_FACE); + + Context->SetVertexBuffer(mVertexBuffer); + Context->SetVertexFormatPosition(3); + Context->SetIndexBuffer(mIndexBuffer); + + Context->SetMaterial(LC_MATERIAL_UNLIT_COLOR); + Context->SetColor(lcVector4(0.0f, 0.0f, 0.0f, 1.0f)); + + float Scale = 1.005f + 2.0f / (float)ViewportSize; + Context->SetWorldMatrix(lcMatrix44Scale(lcVector3(Scale, Scale, Scale))); + Context->SetViewMatrix(GetViewMatrix()); + Context->SetProjectionMatrix(GetProjectionMatrix()); + + Context->DrawIndexedPrimitives(GL_TRIANGLES, mSubdivisions * mSubdivisions * 6 * 6, GL_UNSIGNED_SHORT, 0); + Context->SetMaterial(LC_MATERIAL_UNLIT_VIEW_SPHERE); Context->BindTextureCubeMap(mTexture->mTexture); @@ -173,13 +190,6 @@ void lcViewSphere::Draw() Context->SetViewMatrix(GetViewMatrix()); Context->SetProjectionMatrix(GetProjectionMatrix()); - glDepthFunc(GL_ALWAYS); - glEnable(GL_CULL_FACE); - - Context->SetVertexBuffer(mVertexBuffer); - Context->SetVertexFormatPosition(3); - Context->SetIndexBuffer(mIndexBuffer); - lcVector4 HighlightPosition(0.0f, 0.0f, 0.0f, 0.0f); if (mIntersectionFlags.any()) diff --git a/resources/shaders/unlit_view_sphere_ps.glsl b/resources/shaders/unlit_view_sphere_ps.glsl index 4a68370a..5d4ca661 100644 --- a/resources/shaders/unlit_view_sphere_ps.glsl +++ b/resources/shaders/unlit_view_sphere_ps.glsl @@ -9,7 +9,6 @@ void main() LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a; LC_SHADER_PRECISION float Distance = length(vec3(HighlightParams[0]) - PixelNormal); LC_SHADER_PRECISION float Highlight = step(Distance, HighlightParams[0].w); - LC_SHADER_PRECISION float Edge = smoothstep(0.05, 0.15, dot(PixelNormal, vec3(HighlightParams[4]))); - gl_FragColor = mix(mix(HighlightParams[2], HighlightParams[3], Highlight), HighlightParams[1], TexelAlpha) * Edge; + gl_FragColor = mix(mix(HighlightParams[2], HighlightParams[3], Highlight), HighlightParams[1], TexelAlpha); }