Implementing Deferred lighting into Source 2013: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 29: Line 29:
}
}
#endif // DEFERRED_ENABLED
#endif // DEFERRED_ENABLED
</source>
Now open '''viewrender.h''' and around lines 19 paste the following code. 
<source lang=cpp>
#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
#include "../../materialsystem/stdshaders/deferred_global_common.h"
#endif
</source>
And around lines 39 paste this too.
<source lang=cpp>
#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
struct def_light_t;
#endif
</source>
Now around lines 96, but the following code into enum view_id_t.
<source lang=cpp>
        // @Deferred - Biohazard
VIEW_DEFERRED_GBUFFER = 8,
VIEW_DEFERRED_SHADOW = 9,
</source>
And around lines 263, but the following code into class CRendering3dView : public CBase3dView.
<source lang=cpp>
#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
void PushComposite();
void PopComposite();
static void PushGBuffer( bool bInitial, float zScale = 1.0f, bool bClearDepth = true );
static void PopGBuffer();
#endif
</source>
And around lines 505, paste the following code, and we should be done with viewrender.h.
<source lang=cpp>
#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
void ProcessDeferredGlobals( const CViewSetup &view );
void ViewDrawGBuffer( const CViewSetup &view, bool &bDrew3dSkybox, SkyboxVisibility_t &nSkyboxVisible,
bool bDrawViewModel );
void BeginRadiosity( const CViewSetup &view );
void UpdateRadiosityPosition();
void PerformRadiosityGlobal( const int iRadiosityCascade, const CViewSetup &view );
void EndRadiosity( const CViewSetup &view );
void DebugRadiosity( const CViewSetup &view );
IMesh *GetRadiosityScreenGrid( const int iCascade );
IMesh *CreateRadiosityScreenGrid( const Vector2D &vecViewportBase, const float flWorldStepSize );
void PerformLighting( const CViewSetup &view );
void ResetCascadeDelay();
void RenderCascadedShadows( const CViewSetup &view, const bool bEnableRadiosity );
public:
virtual void DrawLightShadowView( const CViewSetup &view, int iDesiredShadowmap, def_light_t *l );
protected:
float m_flRenderDelay[SHADOW_NUM_CASCADES];
Vector m_vecRadiosityOrigin[2];
IMesh *m_pMesh_RadiosityScreenGrid[2];
CUtlVector< IMesh* > m_hRadiosityDebugMeshList[2];
#endif
</source>
</source>



Revision as of 04:18, 13 April 2024

English (en)Translate (Translate)

Having deferred lighting in your mod comes with quite a lot of upsides as with it, you can have volumetric lighting, realtime shadows and lighting from the sun and from other light sources, while still keeping the performance steady which is something that Source's regular dynamic light entities would be incapable of (aka projected textures).

Implementing into your Source 2013SP mod

Now we are going to use Lambda Wars's implementation for it as its an enhanced/upgraded version of Alien Swarm Deferred's, but beware implementing deferred lighting in your mod is extremely complex requiring you to modify client and server side code, and even add new shaders to your game. Among other things source's default shaders are also needed to be modified.

Clientside

Firstly we are going to modify cdll_client_int.cpp. Now put the following code at the top of the file around lines 175 but it must be before #include "tier0/memdbgon.h".

 #ifdef DEFERRED_ENABLED // @Deferred - Biohazard
 #include "deferred/deferred_shared_common.h"
 #endif

Now aound lines 1816 in void CHLClient::ResetStringTablePointers() place the following code.

 #ifdef DEFERRED_ENABLED // @Deferred - Biohazard
 g_pStringTable_LightCookies = NULL;
 #endif

Now around lines 2058 put the following code inside void CHLClient::InstallStringTableCallback( const char *tableName ). And after that we should be done with cdll_client_int.cpp.

#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
	else if ( !Q_strcasecmp( tableName, COOKIE_STRINGTBL_NAME ) )
	{
		g_pStringTable_LightCookies = networkstringtable->FindTable( tableName );

		g_pStringTable_LightCookies->SetStringChangedCallback( NULL, OnCookieTableChanged );
	}
#endif // DEFERRED_ENABLED

Now open viewrender.h and around lines 19 paste the following code.

#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
#include "../../materialsystem/stdshaders/deferred_global_common.h"
#endif

And around lines 39 paste this too.

#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
	struct def_light_t;
#endif

Now around lines 96, but the following code into enum view_id_t.

        // @Deferred - Biohazard
	VIEW_DEFERRED_GBUFFER = 8,
	VIEW_DEFERRED_SHADOW = 9,

And around lines 263, but the following code into class CRendering3dView : public CBase3dView.

#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
	void			PushComposite();
	void			PopComposite();

	static void PushGBuffer( bool bInitial, float zScale = 1.0f, bool bClearDepth = true );
	static void PopGBuffer();
#endif

And around lines 505, paste the following code, and we should be done with viewrender.h.

#ifdef DEFERRED_ENABLED // @Deferred - Biohazard
	void			ProcessDeferredGlobals( const CViewSetup &view );

	void			ViewDrawGBuffer( const CViewSetup &view, bool &bDrew3dSkybox, SkyboxVisibility_t &nSkyboxVisible,
									 bool bDrawViewModel );

	void BeginRadiosity( const CViewSetup &view );
	void UpdateRadiosityPosition();
	void PerformRadiosityGlobal( const int iRadiosityCascade, const CViewSetup &view );
	void EndRadiosity( const CViewSetup &view );
	void DebugRadiosity( const CViewSetup &view );

	IMesh *GetRadiosityScreenGrid( const int iCascade );
	IMesh *CreateRadiosityScreenGrid( const Vector2D &vecViewportBase, const float flWorldStepSize );

	void			PerformLighting( const CViewSetup &view );

	void			ResetCascadeDelay();
	void			RenderCascadedShadows( const CViewSetup &view, const bool bEnableRadiosity );

public:
	virtual void	DrawLightShadowView( const CViewSetup &view, int iDesiredShadowmap, def_light_t *l );

protected:
	float m_flRenderDelay[SHADOW_NUM_CASCADES];

	Vector m_vecRadiosityOrigin[2];
	IMesh *m_pMesh_RadiosityScreenGrid[2];
	CUtlVector< IMesh* > m_hRadiosityDebugMeshList[2];
#endif

Serverside

Shaders

Broom icon.png
This article or section needs to be cleaned up to conform to a higher standard of quality because:
Actually properly research what is needed for this implementation. Until someone actually decides to the hard work this section should be dedicated to the stuff that is most definietly needed for this implementation to work. And when thats done this notice should be deleted.

Lamba War's source code Reference project : Source 2013MP deferred this project uses the older Alien swarm deferred's version but it still should give us some idea what needs to be changed.

Cpp files and header files needed to be modified or added

  • Client
    • cdll_client_int.cpp ,modification needed
    • viewrender.h ,modification needed
    • viewrender.cpp ,modification needed
    • flashlighteffect.h ,modification needed
    • flashlighteffect.cpp ,modification needed
    • c_entityflame.cpp ,modification needed although it's not necessary it's still a quality of life feature
    • deferred ,This folder contents are needed which are:
      • cascade_t.cpp
      • cascade_t.h
      • DefCookieProjectable.cpp
      • DefCookieProjectable.h
      • DefCookieTexture.cpp
      • DefCookieTexture.h
      • IDefCookie.h
      • IDeferredExtClient.cpp
      • cdeferred_manager_client.cpp
      • cdeferred_manager_client.h
      • clight_editor.cpp
      • clight_editor.h
      • clight_manager.cpp
      • clight_manager.h
      • def_light_t.cpp
      • def_light_t.h
      • deferred_client_common.cpp
      • deferred_client_common.h
      • deferred_rt.cpp
      • deferred_rt.h
      • flashlighteffect_deferred.cpp
      • flashlighteffect_deferred.h
      • viewrender_deferred.cpp
      • viewrender_deferred.h
      • vgui ,This folder is also needed
        • projectable_factory.cpp
        • projectable_factory.h
        • vgui_deferred.h
        • vgui_editor_controls.cpp
        • vgui_editor_controls.h
        • vgui_editor_props.cpp
        • vgui_editor_props.h
        • vgui_editor_root.cpp
        • vgui_marquee.cpp
        • vgui_marquee.h
        • vgui_particles.cpp
        • vgui_particles.h
        • vgui_particles.cpp
        • vgui_projectable.cpp
        • vgui_projectable.h
  • Server
    • gameinterface.cpp ,modification needed
    • lights.cpp ,modification needed
    • EntityFlame.h ,modification needed although it's not necessary it's still a quality of life feature
    • deferred ,This folder contents are needed which are:
      • cdeferred_manager_server.cpp
      • deferred_server_common.h
      • cdeferred_manager_server.h
  • Shared
    • deferred ,This folder contents are needed which are:
      • CDefLight.cpp
      • CDefLight.h
      • CDefLightContainer.cpp
      • CDefLightContainer.h
      • CDefLightGlobal.cpp
      • CDefLightGlobal.h
      • deferred_shared_common.cpp
      • deferred_shared_common.h
      • ssemath_ext.h
  • Public
    • renderparm.h ,modification needed

Shaders

  • common_deferred_fxc.h
  • deferred_context.h
  • deferred_global_common.h
  • deferred_includes.h
  • deferred_utility.h
  • defpass_composite.h
  • defpass_gbuffer.h
  • defpass_shadow.h
  • IDeferredExt.h
  • lighting_helper.h
  • lighting_pass_basic.h
  • lighting_pass_volum.h
  • lightshafts_helper.h
  • vertexlitgeneric_dx9_helper.h
  • lightmappedgeneric_deferred_ps30.h
  • lightmappedgeneric_dx9_helper.h
  • debug_lightingctrl.cpp
  • debug_radiosity_grid.cpp
  • deferred_decalModulate.cpp
  • deferred_model.cpp
  • deferred_brush.cpp
  • defpass_composite.cpp
  • deferred_utility.cpp
  • defpass_gbuffer.cpp
  • defpass_shadow.cpp
  • GlobalLitGeneric.cpp
  • IDeferredExt.cpp
  • lighting_global.cpp
  • lighting_pass_basic.cpp
  • lighting_pass_volum.cpp
  • lighting_volume.cpp
  • lighting_world.cpp
  • radiosity_blend.cpp
  • radiosity_global.cpp
  • radiosity_propagate.cpp
  • volume_prepass.cpp
  • volume_blend.cpp
  • unlitgeneric_dx9.cpp
  • vertexlitgeneric_dx9.cpp
  • vertexlitgeneric_dx9_helper.cpp
  • lightmappedgeneric_dx9.cpp
  • lightmappedgeneric_dx9_helper.cpp
  • lightmappedgeneric_dx9_deferred_helper.cpp
  • phong_dx9_helper.cpp
  • gbuffer_vs30.fxc
  • gbuffer_ps30.fxc
  • gbuffer_defshading_ps30.fxc
  • shadowpass_vs30.fxc
  • shadowpass_ps30.fxc
  • composite_vs30.fxc
  • composite_ps30.fxc
  • defconstruct_vs30.fxc
  • decalmodulate_vs20.fxc
  • decalmodulate_ps2x.fxc
  • lightingpass_global_ps30.fxc
  • lightingpass_point_ps30.fxc
  • lightingpass_spot_ps30.fxc
  • screenspace_shading_ps30.fxc
  • screenspace_combine_ps30.fxc
  • volume_blend_ps30.fxc
  • volume_prepass_vs30.fxc
  • volume_prepass_ps30.fxc
  • volumpass_point_ps30.fxc
  • volumpass_spot_ps30.fxc
  • radiosity_gen_global_ps30.fxc
  • radiosity_gen_vs30.fxc
  • radiosity_propagate_ps30.fxc
  • radiosity_propagate_vs30.fxc
  • radiosity_blend_ps30.fxc
  • screenspace_vs20.fxc
  • gaussianblur_6_ps30.fxc
  • debug_shadow_ortho_ps30.fxc
  • debug_lighting_ctrl_ps30.fxc
  • debug_radiosity_grid_ps30.fxc
  • debug_radiosity_grid_vs30.fxc
  • globallitgeneric_ps30.fxc
  • globallitgeneric_vs30.fxc
  • phong_deferred_ps30.fxc
  • lightmappedgeneric_deferred_vs30.fxc
  • lightmappedgeneric_deferred_ps30.fxc
  • vertexlit_and_unlit_generic_bump_deferred_ps30.fxc
For help, see the VDC Editing Help and Wikipedia cleanup process. Also, remember to check for any notes left by the tagger at this article's talk page.

External links