Better way of drawing the view sphere outline.

This commit is contained in:
Leonardo Zide 2019-01-22 14:34:44 -08:00
parent dfa1a66906
commit 90b8409017
3 changed files with 19 additions and 9 deletions

View file

@ -374,6 +374,7 @@ void lcContext::SetMaterial(lcMaterialType MaterialType)
} }
break; break;
case LC_MATERIAL_UNLIT_VIEW_SPHERE:
case LC_NUM_MATERIALS: case LC_NUM_MATERIALS:
break; break;
} }

View file

@ -166,13 +166,6 @@ void lcViewSphere::Draw()
int Bottom = (Location == lcViewSphereLocation::BOTTOM_LEFT || Location == lcViewSphereLocation::BOTTOM_RIGHT) ? 0 : Height - ViewportSize; int Bottom = (Location == lcViewSphereLocation::BOTTOM_LEFT || Location == lcViewSphereLocation::BOTTOM_RIGHT) ? 0 : Height - ViewportSize;
Context->SetViewport(Left, Bottom, ViewportSize, ViewportSize); Context->SetViewport(Left, Bottom, ViewportSize, ViewportSize);
Context->SetMaterial(LC_MATERIAL_UNLIT_VIEW_SPHERE);
Context->BindTextureCubeMap(mTexture->mTexture);
Context->SetWorldMatrix(lcMatrix44Identity());
Context->SetViewMatrix(GetViewMatrix());
Context->SetProjectionMatrix(GetProjectionMatrix());
glDepthFunc(GL_ALWAYS); glDepthFunc(GL_ALWAYS);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
@ -180,6 +173,23 @@ void lcViewSphere::Draw()
Context->SetVertexFormatPosition(3); Context->SetVertexFormatPosition(3);
Context->SetIndexBuffer(mIndexBuffer); 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);
Context->SetWorldMatrix(lcMatrix44Identity());
Context->SetViewMatrix(GetViewMatrix());
Context->SetProjectionMatrix(GetProjectionMatrix());
lcVector4 HighlightPosition(0.0f, 0.0f, 0.0f, 0.0f); lcVector4 HighlightPosition(0.0f, 0.0f, 0.0f, 0.0f);
if (mIntersectionFlags.any()) if (mIntersectionFlags.any())

View file

@ -9,7 +9,6 @@ void main()
LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a; LC_SHADER_PRECISION float TexelAlpha = textureCube(Texture, PixelNormal).a;
LC_SHADER_PRECISION float Distance = length(vec3(HighlightParams[0]) - PixelNormal); LC_SHADER_PRECISION float Distance = length(vec3(HighlightParams[0]) - PixelNormal);
LC_SHADER_PRECISION float Highlight = step(Distance, HighlightParams[0].w); 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);
} }