//==================================================================== //==================================================================== void DoModPostProcessing( IMatRenderContext *pRenderContext, int x, int y, int w, int h ) { ConVarRef mat_postprocess_enable( "mat_postprocess_enable" ); // No queremos estos efectos if ( !mat_postprocess_enable.GetBool() ) return; C_IN_Player *pPlayer = C_IN_Player::GetLocalInPlayer(); if ( !pPlayer ) return; C_BaseInWeapon *pWeapon = pPlayer->GetActiveInWeapon(); // // FXAA // if ( mat_fxaa_enable.GetBool() ) { static IMaterial *pMatFXAA = materials->FindMaterial( "shaders/postproc_fxaa", TEXTURE_GROUP_OTHER ); if ( pMatFXAA ) { UpdateScreenEffectTexture(); pRenderContext->DrawScreenSpaceRectangle( pMatFXAA, 0, 0, w, h, 0, 0, w - 1, h - 1, w, h ); } } // // Sun Rays // if ( mat_sunrays_enable.GetBool() ) { static IMaterial *pMatSunRays = materials->FindMaterial( "shaders/postproc_sunrays", TEXTURE_GROUP_OTHER ); if ( pMatSunRays ) { UpdateScreenEffectTexture(); pRenderContext->DrawScreenSpaceRectangle( pMatSunRays, 0, 0, w, h, 0, 0, w - 1, h - 1, w, h ); } } // Tenemos un arma if ( pWeapon ) { // Tenemos la mira de acero /*if ( pWeapon->IsIronsighted() ) { static IMaterial *pGaussian = materials->FindMaterial( "shaders/ppe_gaussian_blur", TEXTURE_GROUP_OTHER ); if ( pGaussian ) { UpdateScreenEffectTexture(); pRenderContext->DrawScreenSpaceRectangle( pGaussian, 0, 0, w, h, 0, 0, w - 1, h - 1, w, h ); } }*/ } }
//------------------------------------------------------------------------------ // CExampleEffect render //------------------------------------------------------------------------------ void CExampleEffect::Render( int x, int y, int w, int h ) { if ( !IsEnabled() ) return; // Render Effect Rect_t actualRect; UpdateScreenEffectTexture( 0, x, y, w, h, false, &actualRect ); ITexture *pTexture = GetFullFrameFrameBufferTexture( 0 ); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->DrawScreenSpaceRectangle( m_Material, x, y, w, h, actualRect.x, actualRect.y, actualRect.x+actualRect.width-1, actualRect.y+actualRect.height-1, pTexture->GetActualWidth(), pTexture->GetActualHeight() ); }
void draw_pp_shader( const CViewSetup &view, IMaterial *pMaterial) { int x = view.x; int y = view.y; int w = view.width; int h = view.height; Rect_t actualRect; UpdateScreenEffectTexture( 0, x, y, w, h, false, &actualRect); int u1 = actualRect.x; int v1 = actualRect.y; int u2 = actualRect.x+actualRect.width-1; int v2 = actualRect.y+actualRect.height-1; ITexture *pTexture = GetFullFrameFrameBufferTexture( 0 ); int aw = pTexture->GetActualWidth(); int ah = pTexture->GetActualHeight(); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->DrawScreenSpaceRectangle( pMaterial, x, y, w, h, u1, v1, u2, v2, aw, ah ); pRenderContext.SafeRelease(); }
void CASWViewRender::DoMotionBlur( const CViewSetup &view ) { if ( asw_motionblur.GetInt() == 0 && g_fMarinePoisonDuration <= 0) { g_bBlurredLastTime = false; return; } static float fNextDrawTime = 0.0f; bool found; IMaterialVar* mv = NULL; IMaterial *pMatScreen = NULL; ITexture *pMotionBlur = NULL; ITexture *pOriginalTexture = NULL; // Get the front buffer material pMatScreen = materials->FindMaterial( "swarm/effects/frontbuffer", TEXTURE_GROUP_OTHER, true ); // Get our custom render target pMotionBlur = g_pASWRenderTargets->GetASWMotionBlurTexture(); // Store the current render target CMatRenderContextPtr pRenderContext( materials ); ITexture *pOriginalRenderTarget = pRenderContext->GetRenderTarget(); // Set the camera up so we can draw the overlay int oldX, oldY, oldW, oldH; pRenderContext->GetViewport( oldX, oldY, oldW, oldH ); pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->PushMatrix(); pRenderContext->LoadIdentity(); pRenderContext->MatrixMode( MATERIAL_VIEW ); pRenderContext->PushMatrix(); pRenderContext->LoadIdentity(); // set our blur parameters, based on convars or the poison duration float add_alpha = asw_motionblur_addalpha.GetFloat(); float blur_time = asw_motionblur_time.GetFloat(); float draw_alpha = asw_motionblur_drawalpha.GetFloat(); if (g_fMarinePoisonDuration > 0) { if (g_fMarinePoisonDuration < 1.0f) { draw_alpha = g_fMarinePoisonDuration; add_alpha = 0.3f; } else { draw_alpha = 1.0f; float over_time = g_fMarinePoisonDuration - 1.0f; over_time = -MIN(4.0f, over_time); // map 0 to -4, to 0.3 to 0.05 add_alpha = (over_time + 4) * 0.0625 + 0.05f; } blur_time = 0.05f; } if (!g_bBlurredLastTime) add_alpha = 1.0f; // add the whole buffer if this is the first time we're blurring after a while, so we don't end up with images from ages ago if ( fNextDrawTime - gpGlobals->curtime > 1.0f) { fNextDrawTime = 0.0f; } if( gpGlobals->curtime >= fNextDrawTime ) { UpdateScreenEffectTexture( 0, view.x, view.y, view.width, view.height ); // Set the alpha to whatever our console variable is mv = pMatScreen->FindVar( "$alpha", &found, false ); if (found) { if ( fNextDrawTime == 0 ) { mv->SetFloatValue( 1.0f ); } else { mv->SetFloatValue( add_alpha ); } } pRenderContext->SetRenderTarget( pMotionBlur ); pRenderContext->DrawScreenSpaceQuad( pMatScreen ); // Set the next draw time according to the convar fNextDrawTime = gpGlobals->curtime + blur_time; } // Set the alpha mv = pMatScreen->FindVar( "$alpha", &found, false ); if (found) { mv->SetFloatValue( draw_alpha ); } // Set the texture to our buffer mv = pMatScreen->FindVar( "$basetexture", &found, false ); if (found) { pOriginalTexture = mv->GetTextureValue(); mv->SetTextureValue( pMotionBlur ); } // Pretend we were never here, set everything back pRenderContext->SetRenderTarget( pOriginalRenderTarget ); pRenderContext->DrawScreenSpaceQuad( pMatScreen ); // Set our texture back to _rt_FullFrameFB if (found) { mv->SetTextureValue( pOriginalTexture ); } pRenderContext->DepthRange( 0.0f, 1.0f ); pRenderContext->MatrixMode( MATERIAL_PROJECTION ); pRenderContext->PopMatrix(); pRenderContext->MatrixMode( MATERIAL_VIEW ); pRenderContext->PopMatrix(); g_bBlurredLastTime = true; }
void CASWViewRender::PerformNightVisionEffect( const CViewSetup &view ) { C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( !pPlayer ) return; C_ASW_Marine *pMarine = pPlayer->GetMarine(); if ( !pMarine ) return; float flVisionAlpha = 0.0f; float flFlashAlpha = 0.0f; C_BaseCombatWeapon* pExtraItem = pMarine->GetWeapon( 2 ); if ( pExtraItem && pExtraItem->Classify() == CLASS_ASW_NIGHT_VISION ) { C_ASW_Weapon_Night_Vision *pVision = assert_cast<CASW_Weapon_Night_Vision*>( pExtraItem ); flVisionAlpha = pVision->UpdateVisionAlpha(); flFlashAlpha = pVision->UpdateFlashAlpha(); } if ( flVisionAlpha > 0 ) { IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision", TEXTURE_GROUP_CLIENT_EFFECTS, true ); if ( pMaterial ) { byte overlaycolor[4] = { 0, 255, 0, 255 }; UpdateScreenEffectTexture( 0, view.x, view.y, view.width, view.height ); overlaycolor[3] = flVisionAlpha; render->ViewDrawFade( overlaycolor, pMaterial ); CMatRenderContextPtr pRenderContext( materials ); pRenderContext->DrawScreenSpaceQuad( pMaterial ); render->ViewDrawFade( overlaycolor, pMaterial ); pRenderContext->DrawScreenSpaceQuad( pMaterial ); } IMaterial *pNoiseMaterial = materials->FindMaterial( "effects/nightvision_noise", TEXTURE_GROUP_CLIENT_EFFECTS, true ); if ( pNoiseMaterial ) { byte overlaycolor[4] = { 255, 255, 255, 255 }; overlaycolor[3] = MAX( flFlashAlpha, 16.0f ); CMatRenderContextPtr pRenderContext( materials ); render->ViewDrawFade( overlaycolor, pNoiseMaterial ); } } if ( flFlashAlpha > 0 ) { IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision_flash", TEXTURE_GROUP_CLIENT_EFFECTS, true ); if ( pMaterial ) { byte overlaycolor[4] = { 255, 255, 255, 255 }; overlaycolor[3] = flFlashAlpha; CMatRenderContextPtr pRenderContext( materials ); render->ViewDrawFade( overlaycolor, pMaterial ); } } }
void CGodRaysEffect::Render( int x, int y, int w, int h ) { CMatRenderContextPtr pRenderContext( materials ); // Save off the current render target and put the occlusion // mask on the top of the rt stack. pRenderContext->PushRenderTargetAndViewport( m_OcclusionMask ); // Create the god rays rendering view. CViewRender* pViewRender = CViewRender::GetMainView(); CRefPtr<CGodRaysView> pGodRaysView = new CGodRaysView( pViewRender ); // Set the sun instance. pGodRaysView->m_pSun = m_pSun; // Draw the occlusion mask. pViewRender->AddViewToScene( pGodRaysView ); // Restore original render targets. pRenderContext->PopRenderTargetAndViewport(); // Now, downsample the occlusion mask. Start by setting the quarter // sized render target as the texture to render to. pRenderContext->PushRenderTargetAndViewport( m_SmallRT0 ); // Get the dimensions of the god rays texture. ITexture* pMaskTexture = m_OcclusionMask; const int nSrcWidth = pMaskTexture->GetActualWidth(); const int nSrcHeight = pMaskTexture->GetActualHeight(); const int nQtrWidth = nSrcWidth / 4; const int nQtrHeight = nSrcHeight / 4; // Blit the data from the occlusion mask texture to the quarter sized one // and use the downsample shader to do it with. pRenderContext->DrawScreenSpaceRectangle( m_DownsampleMaterial, 0, 0, nQtrWidth, nQtrHeight, 0, 0, nSrcWidth - 2, nSrcHeight - 2, nSrcWidth, nSrcHeight ); // Restore the original render target. pRenderContext->PopRenderTargetAndViewport(); Vector vLightPos; GetLightPosition( vLightPos ); if( SetMaterialParms( vLightPos ) ) { // Apply godrays on _rt_SmallFB0 -> _rt_SmallFB1. pRenderContext->PushRenderTargetAndViewport( m_SmallRT1 ); pRenderContext->DrawScreenSpaceRectangle( m_GodRaysMaterial, 0, 0, nQtrWidth, nQtrHeight, 0, 0, nQtrWidth - 2, nQtrHeight - 2, nQtrWidth, nQtrHeight ); pRenderContext->PopRenderTargetAndViewport(); // Now blur _rt_SmallFB1 -> _rt_SmallFB0. pRenderContext->PushRenderTargetAndViewport( m_SmallRT0 ); pRenderContext->DrawScreenSpaceRectangle( m_BlurYMaterial, 0, 0, nQtrWidth, nQtrHeight, 0, 0, nQtrWidth - 2, nQtrHeight - 2, nQtrWidth, nQtrHeight ); pRenderContext->PopRenderTargetAndViewport(); // Now blur _rt_SmallFB0 -> _rt_SmallFB1. pRenderContext->PushRenderTargetAndViewport( m_SmallRT1 ); pRenderContext->DrawScreenSpaceRectangle( m_BlurXMaterial, 0, 0, nQtrWidth, nQtrHeight, 0, 0, nQtrWidth - 2, nQtrHeight - 2, nQtrWidth, nQtrHeight ); // Restore old render target and viewport. pRenderContext->PopRenderTargetAndViewport(); // This forces the framebuffer to update with the latest scene. UpdateScreenEffectTexture( 0, x, y, w, h, true ); // Now combine the godrays results with the main frame buffer. pRenderContext->DrawScreenSpaceQuad( m_GodRaysCombineMaterial ); } // Release the render context. pRenderContext->Release(); }