From 961f0a21b2330d73bda42cd557bb7de633a93ef0 Mon Sep 17 00:00:00 2001 From: nullifiedcat Date: Mon, 17 Apr 2017 22:01:47 +0300 Subject: [PATCH] started stencil stuff --- src/EffectGlow.cpp | 71 +++++++++++++++++++++++++++++++++++++++++----- src/EffectGlow.hpp | 3 ++ src/netvars.cpp | 1 + src/netvars.h | 1 + 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/src/EffectGlow.cpp b/src/EffectGlow.cpp index f9a20705..642a0f7f 100644 --- a/src/EffectGlow.cpp +++ b/src/EffectGlow.cpp @@ -137,6 +137,39 @@ bool EffectGlow::ShouldRenderChams(IClientEntity* entity) { return false; } +struct ShaderStencilState_t +{ + bool m_bEnable; + StencilOperation_t m_FailOp; + StencilOperation_t m_ZFailOp; + StencilOperation_t m_PassOp; + StencilComparisonFunction_t m_CompareFunc; + int m_nReferenceValue; + uint32 m_nTestMask; + uint32 m_nWriteMask; + + ShaderStencilState_t() + { + m_bEnable = false; + m_PassOp = m_FailOp = m_ZFailOp = STENCILOPERATION_KEEP; + m_CompareFunc = STENCILCOMPARISONFUNCTION_ALWAYS; + m_nReferenceValue = 0; + m_nTestMask = m_nWriteMask = 0xFFFFFFFF; + } + + void SetStencilState( CMatRenderContextPtr &pRenderContext ) + { + pRenderContext->SetStencilEnable( m_bEnable ); + pRenderContext->SetStencilFailOperation( m_FailOp ); + pRenderContext->SetStencilZFailOperation( m_ZFailOp ); + pRenderContext->SetStencilPassOperation( m_PassOp ); + pRenderContext->SetStencilCompareFunction( m_CompareFunc ); + pRenderContext->SetStencilReferenceValue( m_nReferenceValue ); + pRenderContext->SetStencilTestMask( m_nTestMask ); + pRenderContext->SetStencilWriteMask( m_nWriteMask ); + } +}; + static CTextureReference buffers[4] {}; ITexture* GetBuffer(int i) { @@ -189,7 +222,36 @@ IMaterial* GetBlurY() { return blur; } +static CatVar solid_when(CV_INT, "glow_experimental_solid_when", "0", "...", "Never, Always, Unoccluded, Occluded"); +void EffectGlow::DrawToStencil(IClientEntity* entity) { + ShaderStencilState_t state; + state.m_bEnable = true; + switch ((int)solid_when) { + case 0: + state.m_PassOp = STENCILOPERATION_REPLACE; + state.m_FailOp = STENCILOPERATION_KEEP; + state.m_ZFailOp = STENCILOPERATION_KEEP; + break; + case 2: + case 3: + } +} + +void EffectGlow::DrawToBuffer(IClientEntity* entity) { + +} + +void EffectGlow::DrawEntity(IClientEntity* entity) { + entity->DrawModel(1); + IClientEntity* attach = g_IEntityList->GetClientEntity(*(int*)((uintptr_t)entity + netvar.m_Collision - 24) & 0xFFF); + while (attach) { + if (attach->ShouldDraw()) { + attach->DrawModel(1); + } + attach = g_IEntityList->GetClientEntity(*(int*)((uintptr_t)entity + netvar.m_Collision - 20) & 0xFFF); + } +} void EffectGlow::RenderChams(int idx) { CMatRenderContextPtr ptr(g_IMaterialSystem->GetRenderContext()); @@ -206,13 +268,7 @@ void EffectGlow::RenderChams(int idx) { ptr->DepthRange(0.0f, 0.01f); g_IVRenderView->SetColorModulation(color_1); g_IVModelRender->ForcedMaterialOverride(mat_unlit_z); - entity->DrawModel(1); - //((DrawModelExecute_t)(hooks::hkIVModelRender->GetMethod(hooks::offDrawModelExecute)))(_this, state, info, matrix); - mat_unlit->AlphaModulate(1.0f); - g_IVRenderView->SetColorModulation(color_2); - ptr->DepthRange(0.0f, 1.0f); - g_IVModelRender->ForcedMaterialOverride(mat_unlit); - entity->DrawModel(1); + DrawEntity(entity); } } } @@ -255,6 +311,7 @@ void EffectGlow::Render(int x, int y, int w, int h) { ptr->DrawScreenSpaceRectangle(GetBlurY(), x, y, w, h, 0, 0, w - 1, h - 1, w, h); ptr->Viewport(x, y, w, h); ptr->PopRenderTargetAndViewport(); + g_IVRenderView->SetBlend(0.0f); ptr->DrawScreenSpaceRectangle(blitmat, x, y, w, h, 0, 0, w - 1, h - 1, w, h); } diff --git a/src/EffectGlow.hpp b/src/EffectGlow.hpp index 5f531b5a..f3cd001e 100644 --- a/src/EffectGlow.hpp +++ b/src/EffectGlow.hpp @@ -24,6 +24,9 @@ public: inline virtual void Enable( bool bEnable ) { enabled = bEnable; }; inline virtual bool IsEnabled( ) { return enabled; }; + void DrawEntity(IClientEntity* entity); + void DrawToStencil(IClientEntity* entity); + void DrawToBuffer(IClientEntity* entity); int ChamsColor(IClientEntity* entity); bool ShouldRenderChams(IClientEntity* entity); void RenderChams(int idx); diff --git a/src/netvars.cpp b/src/netvars.cpp index dd67b6ce..cf6c1705 100644 --- a/src/netvars.cpp +++ b/src/netvars.cpp @@ -20,6 +20,7 @@ void NetVars::Init() { this->iHitboxSet = gNetvars.get_offset("DT_BaseAnimating", "m_nHitboxSet"); this->vVelocity = gNetvars.get_offset("DT_BasePlayer", "localdata", "m_vecVelocity[0]"); this->movetype = gNetvars.get_offset("DT_BaseEntity", "movetype"); + this->m_Collision = gNetvars.get_offset("DT_BaseEntity", "m_Collision"); if (TF2) { m_angEyeAngles = gNetvars.get_offset("DT_TFPlayer", "tfnonlocaldata", "m_angEyeAngles[0]"); this->bGlowEnabled = gNetvars.get_offset("DT_TFPlayer", "m_bGlowEnabled"); diff --git a/src/netvars.h b/src/netvars.h index 66e5bf03..715f1e36 100644 --- a/src/netvars.h +++ b/src/netvars.h @@ -122,6 +122,7 @@ public: offset_t m_bDucked; offset_t m_angEyeAngles; offset_t m_bReadyToBackstab; + offset_t m_Collision; }; extern NetVars netvar;