@@ -73,10 +73,13 @@ extern ConVar replay_rendersetting_renderglow;
73
73
#include " clienteffectprecachesystem.h"
74
74
#include " materialsystem/imaterialvar.h"
75
75
#include " object_motion_blur_effect.h"
76
+ #include " viewpostprocess.h"
76
77
77
78
// memdbgon must be the last include file in a .cpp file!!!
78
79
#include " tier0/memdbgon.h"
79
80
81
+ extern bool g_bDumpRenderTargets;
82
+
80
83
using namespace vgui ;
81
84
82
85
#define ACHIEVEMENT_ANNOUNCEMENT_MIN_TIME 10
@@ -843,20 +846,75 @@ void ClientModeShared::DoObjectMotionBlur(const CNewViewSetup *pSetup)
843
846
pRenderContext->ClearColor4ub (127 , 127 , 0 , 0 );
844
847
// Clear only color, not depth & stencil
845
848
pRenderContext->ClearBuffers (true , false , false );
849
+ // pRenderContext->FogMode(MATERIAL_FOG_NONE);
846
850
847
851
// Save off state
848
852
Vector vOrigColor;
849
853
render->GetColorModulation (vOrigColor.Base ());
854
+ float flSavedBlend = render->GetBlend ();
850
855
851
856
// Use a solid-color unlit material to render velocity into the buffer
852
857
g_pStudioRender->ForcedMaterialOverride (pGlowColorMaterial);
858
+
859
+ pRenderContext->SetLightingOrigin (vec3_origin);
860
+ pRenderContext->SetAmbientLight (1 .0f , 1 .0f , 1 .0f );
861
+
862
+ /* static */ Vector white[6 ] =
863
+ {
864
+ Vector (1 .0f , 1 .0f , 1 .0f ),
865
+ Vector (1 .0f , 1 .0f , 1 .0f ),
866
+ Vector (1 .0f , 1 .0f , 1 .0f ),
867
+ Vector (1 .0f , 1 .0f , 1 .0f ),
868
+ Vector (1 .0f , 1 .0f , 1 .0f ),
869
+ Vector (1 .0f , 1 .0f , 1 .0f ),
870
+ };
871
+
872
+ g_pStudioRender->SetAmbientLightColors (white);
873
+ g_pStudioRender->SetLocalLights (0 , NULL );
874
+
875
+ modelrender->SuppressEngineLighting (true );
876
+ render->SetBlend (1 .0f );
853
877
g_ObjectMotionBlurManager.DrawObjects ();
878
+ modelrender->SuppressEngineLighting (false );
879
+
854
880
g_pStudioRender->ForcedMaterialOverride (NULL );
855
881
856
882
render->SetColorModulation (vOrigColor.Base ());
857
883
884
+ // Optionally write the rendered image to a debug texture
885
+ if (g_bDumpRenderTargets)
886
+ {
887
+ DumpTGAofRenderTarget (pSetup->width , pSetup->height , " ObjectBlurVelocity" );
888
+ }
889
+
858
890
pRenderContext->PopRenderTargetAndViewport ();
859
891
892
+ // Render objects to stencil
893
+ {
894
+
895
+
896
+ // Set alpha to 0 so we don't touch any color pixels
897
+ render->SetBlend (0 .0f );
898
+ pRenderContext->OverrideDepthEnable (true , false );
899
+ pRenderContext->ClearBuffers (false , false , true );
900
+
901
+ ShaderStencilState_t stencilState;
902
+ stencilState.m_bEnable = true ;
903
+ stencilState.m_nReferenceValue = 1 ;
904
+ stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_ALWAYS;
905
+ stencilState.m_PassOp = STENCILOPERATION_REPLACE;
906
+ stencilState.m_FailOp = STENCILOPERATION_KEEP;
907
+ stencilState.m_ZFailOp = STENCILOPERATION_KEEP;
908
+
909
+ stencilState.SetStencilState (pRenderContext);
910
+
911
+ g_ObjectMotionBlurManager.DrawObjects ();
912
+
913
+ pRenderContext->OverrideDepthEnable (false , false );
914
+ }
915
+
916
+ render->SetBlend (flSavedBlend);
917
+
860
918
//
861
919
// Render full-screen pass
862
920
//
@@ -874,6 +932,17 @@ void ClientModeShared::DoObjectMotionBlur(const CNewViewSetup *pSetup)
874
932
pVelocityTextureVariable = pMotionBlurMaterial->FindVar (" $velocity_texture" , &bFound2, true );
875
933
if (bFound1 && bFound2)
876
934
{
935
+ ShaderStencilState_t stencilState;
936
+ stencilState.m_bEnable = true ;
937
+ stencilState.m_nWriteMask = 0 ; // We're not changing stencil
938
+ stencilState.m_nReferenceValue = 1 ;
939
+ stencilState.m_nTestMask = 1 ;
940
+ stencilState.m_CompareFunc = STENCILCOMPARISONFUNCTION_EQUAL;
941
+ stencilState.m_PassOp = STENCILOPERATION_KEEP;
942
+ stencilState.m_FailOp = STENCILOPERATION_KEEP;
943
+ stencilState.m_ZFailOp = STENCILOPERATION_KEEP;
944
+ stencilState.SetStencilState (pRenderContext);
945
+
877
946
pFBTextureVariable->SetTextureValue (pFullFrameFB);
878
947
879
948
pVelocityTextureVariable->SetTextureValue (pFullFrameFB1);
@@ -883,6 +952,8 @@ void ClientModeShared::DoObjectMotionBlur(const CNewViewSetup *pSetup)
883
952
884
953
pRenderContext->DrawScreenSpaceRectangle (pMotionBlurMaterial, 0 , 0 , nWidth, nHeight, 0 .0f , 0 .0f , nWidth - 1 , nHeight - 1 , nWidth, nHeight);
885
954
}
955
+
956
+ pRenderContext->SetStencilEnable (false );
886
957
}
887
958
888
959
// -----------------------------------------------------------------------------
0 commit comments