Skip to content

Commit

Permalink
UPBGE: Fix for Depth transparency
Browse files Browse the repository at this point in the history
Thanks to @youle31 for the code to recover it
  • Loading branch information
lordloki committed May 8, 2020
1 parent 9ec291e commit 4ded0a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
10 changes: 8 additions & 2 deletions source/gameengine/Rasterizer/RAS_BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
# pragma warning (disable:4786)
#endif

#include "KX_Globals.h"
#include "KX_KetsjiEngine.h"
#include "RAS_MaterialBucket.h"
#include "RAS_Mesh.h"
#include "RAS_MeshUser.h"
#include "RAS_ICanvas.h"
#include "RAS_IMaterial.h"
#include "RAS_Rasterizer.h"

Expand All @@ -45,6 +48,8 @@
#include <algorithm>
/* sorting */



RAS_BucketManager::SortedMeshSlot::SortedMeshSlot(RAS_MeshSlot *ms, const mt::vec3& pnorm)
:m_ms(ms)
{
Expand Down Expand Up @@ -269,7 +274,6 @@ void RAS_BucketManager::Renderbuckets(RAS_Rasterizer::DrawType drawingMode, cons
/* Rendering solid and alpha (regular and instancing) materials
* with their shaders.
*/

m_nodeData.m_shaderOverride = false;
rasty->SetDepthMask(RAS_Rasterizer::RAS_DEPTHMASK_ENABLED);

Expand All @@ -280,7 +284,9 @@ void RAS_BucketManager::Renderbuckets(RAS_Rasterizer::DrawType drawingMode, cons

// Update depth transparency depth texture after rendering all solid materials.
if ((m_buckets[ALPHA_DEPTH_BUCKET].size() + m_buckets[ALPHA_DEPTH_INSTANCING_BUCKET].size()) > 0) {
rasty->UpdateGlobalDepthTexture(offScreen);
KX_KetsjiEngine *ketsji = KX_GetActiveEngine();
RAS_ICanvas* canvas = ketsji->GetCanvas();
rasty->UpdateGlobalDepthTexture(offScreen, canvas);
}
RenderBasicBuckets(rasty, ALPHA_INSTANCING_BUCKET);
RenderSortedBuckets(rasty, ALPHA_BUCKET);
Expand Down
14 changes: 7 additions & 7 deletions source/gameengine/Rasterizer/RAS_Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1320,19 +1320,19 @@ void RAS_Rasterizer::LoadIdentity()
m_impl->LoadIdentity();
}

void RAS_Rasterizer::UpdateGlobalDepthTexture(RAS_OffScreen *offScreen)
void RAS_Rasterizer::UpdateGlobalDepthTexture(RAS_OffScreen *offScreen, RAS_ICanvas *canvas)
{
/* In case of multisamples the depth off screen must be blit to be used in shader.
* But the original off screen must be kept bound after the blit. */
/*if (offScreen->GetSamples()) {
RAS_OffScreen *dstOffScreen = GetOffScreen(RAS_Rasterizer::RAS_OFFSCREEN_BLIT_DEPTH);
offScreen->Blit(dstOffScreen, false, true);
if (offScreen->GetSamples()) {
RAS_OffScreen *dstOffScreen = canvas->GetOffScreen(RAS_OffScreen::RAS_OFFSCREEN_BLIT_DEPTH);
offScreen->Blit(dstOffScreen, true);
// Restore original off screen.
offScreen->Bind();
offScreen = dstOffScreen;
} TODO utiliser mulisample comme single sample ?*/

GPU_texture_set_global_depth(offScreen->GetDepthTexture());
}
GPUTexture* gputex = offScreen->GetDepthTexture();
GPU_texture_set_global_depth(gputex);
}

void RAS_Rasterizer::ResetGlobalDepthTexture()
Expand Down
2 changes: 1 addition & 1 deletion source/gameengine/Rasterizer/RAS_Rasterizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ class RAS_Rasterizer : public mt::SimdClassAllocator
/** Set the current off screen depth to the global depth texture used by materials.
* In case of mutlisample off screen a blit to RAS_OFFSCREEN_BLIT_DEPTH is procceed.
*/
void UpdateGlobalDepthTexture(RAS_OffScreen *offScreen);
void UpdateGlobalDepthTexture(RAS_OffScreen *offScreen, RAS_ICanvas *canvas);
/// Set the global depth texture to an empty texture.
void ResetGlobalDepthTexture();

Expand Down

0 comments on commit 4ded0a6

Please sign in to comment.