BVB Source Codes

CRYENGINE Show ParticleRender.cpp Source code

Return Download CRYENGINE: download ParticleRender.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  Created:     26/11/2014 by Filipe amim
  5. //  Description:
  6. // -------------------------------------------------------------------------
  7. //
  8. ////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "StdAfx.h"
  11. #include "ParticleRender.h"
  12. #include "ParticleManager.h"
  13. #include "ParticleEmitter.h"
  14.  
  15. namespace pfx2
  16. {
  17.  
  18. struct CRY_ALIGN(CRY_PFX2_PARTICLES_ALIGNMENT) SCachedRenderObject
  19. {
  20. };
  21.  
  22. CParticleRenderBase::CParticleRenderBase(gpu_pfx2::EGpuFeatureType type)
  23.         : CParticleFeature(type)
  24.         , m_renderObjectBeforeWaterId(-1)
  25.         , m_renderObjectAfterWaterId(-1)
  26.         , m_waterCulling(false)
  27. {
  28. }
  29.  
  30. EFeatureType CParticleRenderBase::GetFeatureType()
  31. {
  32.         return EFT_Render;
  33. }
  34.  
  35. void CParticleRenderBase::AddToComponent(CParticleComponent* pComponent, SComponentParams* pParams)
  36. {
  37.         CParticleEffect* pEffect = pComponent->GetEffect();
  38.         pComponent->AddToUpdateList(EUL_Render, this);
  39.         m_waterCulling = SupportsWaterCulling();
  40.         if (m_waterCulling)
  41.                 m_renderObjectBeforeWaterId = pEffect->AddRenderObjectId();
  42.         m_renderObjectAfterWaterId = pEffect->AddRenderObjectId();
  43. }
  44.  
  45. void CParticleRenderBase::PrepareRenderObjects(CParticleEmitter* pEmitter, CParticleComponent* pComponent)
  46. {
  47.         const SComponentParams& params = pComponent->GetComponentParams();
  48.  
  49.         if (!params.m_pMaterial)
  50.                 return;
  51.  
  52.         for (uint threadId = 0; threadId < RT_COMMAND_BUF_COUNT; ++threadId)
  53.         {
  54.                 const uint64 objFlags = params.m_renderObjectFlags;
  55.                 if (m_waterCulling)
  56.                         PrepareRenderObject(pEmitter, pComponent, m_renderObjectBeforeWaterId, threadId, objFlags);
  57.                 PrepareRenderObject(pEmitter, pComponent, m_renderObjectAfterWaterId, threadId, objFlags);
  58.         }
  59. }
  60.  
  61. void CParticleRenderBase::ResetRenderObjects(CParticleEmitter* pEmitter, CParticleComponent* pComponent)
  62. {
  63.         const bool isGpu = pComponent->GetRuntimeInitializationParameters().usesGpuImplementation;
  64.         if (isGpu)
  65.                 return;
  66.  
  67.         for (uint threadId = 0; threadId < RT_COMMAND_BUF_COUNT; ++threadId)
  68.         {
  69.                 ResetRenderObject(pEmitter, pComponent, m_renderObjectBeforeWaterId, threadId);
  70.                 ResetRenderObject(pEmitter, pComponent, m_renderObjectAfterWaterId, threadId);
  71.         }
  72. }
  73.  
  74. void CParticleRenderBase::Render(CParticleEmitter* pEmitter, ICommonParticleComponentRuntime* pComponentRuntime, CParticleComponent* pComponent, const SRenderContext& renderContext)
  75. {
  76.         FUNCTION_PROFILER(GetISystem(), PROFILE_PARTICLE);
  77.  
  78.         const SComponentParams& params = pComponent->GetComponentParams();
  79.         const uint threadId = renderContext.m_passInfo.ThreadID();
  80.  
  81.         if (!params.m_pMaterial)
  82.                 return;
  83.  
  84.         const bool isIndoors = pEmitter->GetVisEnv().OriginIndoors();
  85.         const bool renderIndoor = params.m_visibility.m_indoorVisibility != EIndoorVisibility::OutdoorOnly;
  86.         const bool renderOutdoors = params.m_visibility.m_indoorVisibility != EIndoorVisibility::IndoorOnly;
  87.         if ((isIndoors && !renderIndoor) || (!isIndoors && !renderOutdoors))
  88.                 return;
  89.  
  90.         uint64 objFlags = params.m_renderObjectFlags;
  91.         if (!renderContext.m_lightVolumeId)
  92.                 objFlags &= ~FOB_LIGHTVOLUME;
  93.  
  94.         const bool isCameraUnderWater = renderContext.m_passInfo.IsCameraUnderWater();;
  95.         const bool renderBelowWater = params.m_visibility.m_waterVisibility != EWaterVisibility::AboveWaterOnly;
  96.         const bool renderAboveWater = params.m_visibility.m_waterVisibility != EWaterVisibility::BelowWaterOnly;
  97.  
  98.         if (m_waterCulling && ((isCameraUnderWater && renderAboveWater) || (!isCameraUnderWater && renderBelowWater)))
  99.                 AddRenderObject(pEmitter, pComponentRuntime, pComponent, renderContext, m_renderObjectBeforeWaterId, threadId, objFlags);
  100.         if ((isCameraUnderWater && renderBelowWater) || (!isCameraUnderWater && renderAboveWater))
  101.                 AddRenderObject(pEmitter, pComponentRuntime, pComponent, renderContext, m_renderObjectAfterWaterId, threadId, objFlags | FOB_AFTER_WATER);
  102. }
  103.  
  104. void CParticleRenderBase::PrepareRenderObject(CParticleEmitter* pEmitter, CParticleComponent* pComponent, uint renderObjectId, uint threadId, uint64 objFlags)
  105. {
  106.         const bool isGpu = pComponent->GetRuntimeInitializationParameters().usesGpuImplementation;
  107.         CRenderObject* pRenderObject = gEnv->pRenderer->EF_GetObject();
  108.         pEmitter->SetRenderObject(pRenderObject, threadId, renderObjectId);
  109.  
  110.         const SComponentParams& params = pComponent->GetComponentParams();
  111.         const SParticleShaderData& rData = params.m_shaderData;
  112.  
  113.         pRenderObject->m_II.m_Matrix.SetIdentity();
  114.         pRenderObject->m_fAlpha = 1.0f;
  115.         pRenderObject->m_pCurrMaterial = params.m_pMaterial;
  116.         pRenderObject->m_pRenderNode = pEmitter;
  117.         pRenderObject->m_RState = params.m_renderStateFlags | OS_ENVIRONMENT_CUBEMAP;
  118.         pRenderObject->m_fSort = 0;
  119.         pRenderObject->m_ParticleObjFlags = params.m_particleObjFlags;
  120.         pRenderObject->m_pRE = isGpu ? nullptr : gEnv->pRenderer->EF_CreateRE(eDATA_Particle);
  121.  
  122.         SRenderObjData* pObjData = pRenderObject->GetObjData();
  123.         pObjData->m_pParticleShaderData = &params.m_shaderData;
  124. }
  125.  
  126. void CParticleRenderBase::ResetRenderObject(CParticleEmitter* pEmitter, CParticleComponent* pComponent, uint renderObjectId, uint threadId)
  127. {
  128.         const bool isGpu = pComponent->GetRuntimeInitializationParameters().usesGpuImplementation;
  129.  
  130.         if (renderObjectId == -1)
  131.                 return;
  132.         CRenderObject* pRenderObject = pEmitter->GetRenderObject(threadId, renderObjectId);
  133.         if (!pRenderObject)
  134.                 return;
  135.  
  136.         if (!isGpu && pRenderObject->m_pRE != nullptr)
  137.                 pRenderObject->m_pRE->Release();
  138.         gEnv->pRenderer->EF_FreeObject(pRenderObject);
  139.         pEmitter->SetRenderObject(nullptr, threadId, renderObjectId);
  140. }
  141.  
  142. void CParticleRenderBase::AddRenderObject(CParticleEmitter* pEmitter, ICommonParticleComponentRuntime* pComponentRuntime, CParticleComponent* pComponent, const SRenderContext& renderContext, uint renderObjectId, uint threadId, uint64 objFlags)
  143. {
  144.         const SComponentParams& params = pComponent->GetComponentParams();
  145.         CRenderObject* pRenderObject = pEmitter->GetRenderObject(threadId, renderObjectId);
  146.         SRenderObjData* pObjData = pRenderObject->GetObjData();
  147.  
  148.         const float sortBiasSize = 1.0f / 1024.0f;
  149.         const float sortBias = renderContext.m_distance * params.m_renderObjectSortBias * sortBiasSize;
  150.  
  151.         pRenderObject->m_ObjFlags = objFlags;
  152.         pRenderObject->m_fDistance = renderContext.m_distance - sortBias;
  153.         pObjData->m_FogVolumeContribIdx = renderContext.m_fogVolumeId;
  154.         pObjData->m_LightVolumeId = renderContext.m_lightVolumeId;
  155.         if (pEmitter->m_pTempData)
  156.                 *((Vec4*)&pObjData->m_fTempVars[0]) = pEmitter->m_pTempData->userData.vEnvironmentProbeMults;
  157.         else
  158.                 *((Vec4*)&pObjData->m_fTempVars[0]) = Vec4(1.0f, 1.0f, 1.0f, 1.0f);
  159.  
  160.         if (auto pGpuRuntime = pComponentRuntime->GetGpuRuntime())
  161.         {
  162.                 pGpuRuntime->Render(pRenderObject, renderContext.m_passInfo, renderContext.m_renderParams);
  163.         }
  164.         else
  165.         {
  166.                 CParticleJobManager& kernel = GetPSystem()->GetJobManager();
  167.                 kernel.ScheduleComputeVertices(
  168.                         pComponentRuntime->GetCpuRuntime(),
  169.                         pRenderObject, renderContext);
  170.         }
  171.         renderContext.m_passInfo.GetIRenderView()->AddPermanentObject(
  172.                 pRenderObject,
  173.                 renderContext.m_passInfo);
  174. }
  175.  
  176. }
  177.  
downloadParticleRender.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top