From 081373742ee503cfd10bcfb892d536156e52ac51 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sat, 16 Nov 2019 12:15:49 -0800 Subject: [PATCH] Translucent mesh sorting fixes and improvements. --- common/lc_scene.cpp | 2 +- common/lc_scene.h | 5 +++++ common/view.cpp | 8 ++++++-- resources/shaders/fakelit_texture_decal_ps.glsl | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index f1c3a020..fc3b5715 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -45,7 +45,7 @@ void lcScene::End() auto TranslucentMeshCompare = [this](int Index1, int Index2) { - return mRenderMeshes[Index1].Distance < mRenderMeshes[Index2].Distance; + return mRenderMeshes[Index1].Distance > mRenderMeshes[Index2].Distance; }; std::sort(mTranslucentMeshes.begin(), mTranslucentMeshes.end(), TranslucentMeshCompare); diff --git a/common/lc_scene.h b/common/lc_scene.h index 940f0555..ef900603 100644 --- a/common/lc_scene.h +++ b/common/lc_scene.h @@ -27,6 +27,11 @@ public: return mActiveSubmodelInstance; } + const lcMatrix44& GetViewMatrix() const + { + return mViewMatrix; + } + void SetDrawInterface(bool DrawInterface) { mDrawInterface = DrawInterface; diff --git a/common/view.cpp b/common/view.cpp index 2113deab..f90678dc 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -874,6 +874,12 @@ void View::OnDraw() mContext->SetProjectionMatrix(GetProjectionMatrix()); } + if (DrawInterface) + { + mContext->SetViewMatrix(mScene.GetViewMatrix()); + DrawGrid(); + } + mContext->SetLineWidth(Preferences.mLineWidth); mScene.Draw(mContext); @@ -912,8 +918,6 @@ void View::OnDraw() mContext->SetLineWidth(1.0f); - DrawGrid(); - if (Preferences.mDrawAxes) DrawAxes(); diff --git a/resources/shaders/fakelit_texture_decal_ps.glsl b/resources/shaders/fakelit_texture_decal_ps.glsl index 1f06b538..d23967ca 100644 --- a/resources/shaders/fakelit_texture_decal_ps.glsl +++ b/resources/shaders/fakelit_texture_decal_ps.glsl @@ -12,6 +12,6 @@ void main() { LC_PIXEL_FAKE_LIGHTING LC_SHADER_PRECISION vec4 TexelColor = texture2D(Texture, PixelTexCoord); - LC_SHADER_PRECISION vec4 DiffuseColor = mix(MaterialColor, TexelColor, TexelColor.a); - gl_FragColor = vec4(vec3(DiffuseColor) * Diffuse + SpecularColor, DiffuseColor.a); + LC_SHADER_PRECISION vec3 DiffuseColor = mix(MaterialColor.rgb, TexelColor.rgb, TexelColor.a); + gl_FragColor = vec4(DiffuseColor * Diffuse + SpecularColor, max(TexelColor.a, MaterialColor.a)); }