Skip to content
Snippets Groups Projects
Select Git revision
  • fe1a0e71c948a96028f53911e25c6929c19032fe
  • branchX default protected
  • Inventory
  • UIControls
  • fsv2
  • tonetest
  • from_nb
  • tonemapping
  • opt-shadows
  • BX-634
  • xCSG
  • hc
  • gizmos
  • gui2CSSLexer
  • msExporter
  • gui2
  • gui2Fix
  • master protected
  • pk
  • mesh_optimize
  • light_wip
  • version_X.11.2 protected
  • version_X.11.1 protected
  • version_X.11.1-dev protected
  • version_X.11.0-dev protected
  • version_X.10.1 protected
  • version_X.10.1-dev protected
  • version_X.10.0-dev protected
  • version_X.9.5 protected
  • version_X.9.4 protected
  • version_X.9.3 protected
  • version_X.9.3-dev protected
  • version_X.9.2-dev protected
  • version_X.9.1-dev protected
  • version_X.9.0-dev protected
  • version_X.8.2 protected
  • version_X.8.2-dev protected
  • version_X.8.1-dev protected
  • version_X.8.0-dev protected
  • version_X.7.1 protected
  • version_X.7.0 protected
41 results

LightSystem.cpp

Blame
  • LightSystem.cpp 32.03 KiB
    #include "LightSystem.h"
    
    class CLevelLoadListener: public IEventListener<XEventLevel>
    {
    public:
    	CLevelLoadListener(CLightSystem *pLightSystem, IXCore *pCore):
    		m_pLightSystem(pLightSystem)
    	{
    		m_pLevelSizeChannel = pCore->getEventChannel<XEventLevelSize>(EVENT_LEVEL_GET_SIZE_GUID);
    	}
    
    	void onEvent(const XEventLevel *pEvent) override
    	{
    		switch(pEvent->type)
    		{
    		case XEventLevel::TYPE_LOAD_END:
    			XEventLevelSize levelSize;
    			m_pLevelSizeChannel->broadcastEvent(&levelSize);
    
    			m_pLightSystem->setLevelSize(levelSize.vMin, levelSize.vMax);
    			break;
    		}
    	}
    
    private:
    	CLightSystem *m_pLightSystem;
    	IEventChannel<XEventLevelSize> *m_pLevelSizeChannel = NULL;
    };
    
    //##########################################################################
    
    CLightSystem::CLightSystem(IXCore *pCore):
    	m_pCore(pCore)
    {
    	Core_0RegisterCVarFloat("lpv_size_0", 1.0f, "Коэфициент размера первого каскада LPV");
    	Core_0RegisterCVarFloat("lpv_size_1", 2.0f, "Коэфициент размера второго каскада LPV");
    	Core_0RegisterCVarFloat("lpv_size_2", 4.0f, "Коэфициент размера третьего каскада LPV");
    	Core_0RegisterCVarInt("lpv_cascades_count", 3, "Количество активных каскадов LPV [0;3]");
    
    	m_pLevelListener = new CLevelLoadListener(this, pCore);
    
    	m_pLevelChannel = pCore->getEventChannel<XEventLevel>(EVENT_LEVEL_GUID);
    	m_pLevelChannel->addListener(m_pLevelListener);
    
    	m_pDevice = SGCore_GetDXDevice();
    
    	m_pMaterialSystem = (IXMaterialSystem*)pCore->getPluginManager()->getInterface(IXMATERIALSYSTEM_GUID);
    
    	if(m_pDevice)
    	{
    		{
    			const UINT uSize = 32;
    			m_uGICubesCount = uSize * uSize * uSize;
    			float3_t *pData = new float3_t[m_uGICubesCount];
    			float fHalf = (float)uSize / 2.0f;
    			for(UINT x = 0; x < uSize; ++x)
    			{
    				for(UINT y = 0; y < uSize; ++y)
    				{
    					for(UINT z = 0; z < uSize; ++z)
    					{
    						pData[x + y * uSize + z * uSize * uSize] = (float3)(float3((float)x, (float)y, (float)z) - float3(fHalf));
    					}
    				}
    			}
    			IGXVertexBuffer *pVB = m_pDevice->createVertexBuffer(sizeof(float3_t) * m_uGICubesCount, GXBUFFER_USAGE_STATIC, pData);
    			mem_delete_a(pData);
    
    			GXVertexElement oLayout[] =
    			{