BVB Source Codes

CRYENGINE Show FeatureLightSource.cpp Source code

Return Download CRYENGINE: download FeatureLightSource.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "ParticleSystem/ParticleFeature.h"
  5. #include "ClipVolumeManager.h"
  6. #include "ParamMod.h"
  7.  
  8. CRY_PFX2_DBG
  9.  
  10. namespace pfx2
  11. {
  12.  
  13. extern EParticleDataType
  14.   EPDT_Color,
  15.   EPDT_Alpha;
  16.  
  17. SERIALIZATION_DECLARE_ENUM(ELightAffectsFog,
  18.         No,
  19.         FogOnly,
  20.         Both
  21.         )
  22.  
  23. class CFeatureLightSource : public CParticleFeature, public Cry3DEngineBase
  24. {
  25. public:
  26.         CRY_PFX2_DECLARE_FEATURE
  27.  
  28.         CFeatureLightSource()
  29.                 : m_intensity(1.0f)
  30.                 , m_radius(1.0f)
  31.                 , m_affectsFog(ELightAffectsFog::Both)
  32.                 , m_affectsThisAreaOnly(false) {}
  33.  
  34.         virtual void AddToComponent(CParticleComponent* pComponent, SComponentParams* pParams) override
  35.         {
  36.                 pComponent->AddToUpdateList(EUL_RenderDeferred, this);
  37.                 pComponent->AddParticleData(EPVF_Position);
  38.         }
  39.  
  40.         virtual void Serialize(Serialization::IArchive& ar) override
  41.         {
  42.                 CParticleFeature::Serialize(ar);
  43.                 ar(m_intensity, "Intensity", "Intensity");
  44.                 ar(m_radius, "Radius", "Radius");
  45.                 ar(m_affectsFog, "Affectsfog", "Affects Fog");
  46.                 ar(m_affectsThisAreaOnly, "AffectsThisAreaOnly", "Affects This Area Only");
  47.         }
  48.  
  49.         virtual void Render(CParticleEmitter* pEmitter, ICommonParticleComponentRuntime* pCommonComponentRuntime, CParticleComponent* pComponent, const SRenderContext& renderContext) override
  50.         {
  51.                 CRY_PROFILE_FUNCTION(PROFILE_PARTICLE);
  52.  
  53.                 if (!GetCVars()->e_DynamicLights || renderContext.m_passInfo.IsRecursivePass())
  54.                         return;
  55.  
  56.                 CParticleComponentRuntime* pComponentRuntime = pCommonComponentRuntime->GetCpuRuntime();
  57.                 if (!pComponentRuntime)
  58.                         return;
  59.                 auto context = SUpdateContext(pComponentRuntime);
  60.                 auto& passInfo = renderContext.m_passInfo;
  61.  
  62.                 const CParticleContainer& container = context.m_container;
  63.                 const bool hasColors = container.HasData(EPDT_Color);
  64.                 const IVec3Stream positions = container.GetIVec3Stream(EPVF_Position);
  65.                 const IColorStream colors = container.GetIColorStream(EPDT_Color);
  66.                 const IFStream alphas = container.GetIFStream(EPDT_Alpha, 1.0f);
  67.                 const TIStream<uint8> states = container.GetTIStream<uint8>(EPDT_State);
  68.  
  69.                 CDLight light;
  70.                 light.m_nStencilRef[0] = m_affectsThisAreaOnly ? renderContext.m_renderParams.nClipVolumeStencilRef : CClipVolumeManager::AffectsEverythingStencilRef;
  71.                 light.m_nStencilRef[1] = CClipVolumeManager::InactiveVolumeStencilRef;
  72.                 light.m_Flags |= DLF_DEFERRED_LIGHT;
  73.                 if (m_affectsFog == ELightAffectsFog::Both)
  74.                         light.m_Flags |= DLF_VOLUMETRIC_FOG;
  75.                 else if (m_affectsFog == ELightAffectsFog::FogOnly)
  76.                         light.m_Flags |= DLF_VOLUMETRIC_FOG | DLF_VOLUMETRIC_FOG_ONLY;
  77.  
  78.                 CRY_PFX2_FOR_ACTIVE_PARTICLES(context)
  79.                 {
  80.                         const uint8 state = states.Load(particleId);
  81.                         if (state == ES_Expired)
  82.                                 continue;
  83.  
  84.                         const Vec3 position = positions.Load(particleId);
  85.                         UCol color;
  86.                         if (hasColors)
  87.                                 color = colors.Load(particleId);
  88.                         else
  89.                                 color.dcolor = ~0;
  90.                         const float alpha = alphas.SafeLoad(particleId);
  91.                         const float lightIntensity = alpha * m_intensity;
  92.                         const float lightRadius = m_radius;
  93.  
  94.                         light.SetPosition(position);
  95.                         light.m_Color = ToColorF(color) * ColorF(lightIntensity);
  96.                         light.m_fRadius = lightRadius;
  97.  
  98.                         const float minColorThreshold = GetFloatCVar(e_ParticlesLightMinColorThreshold);
  99.                         const float minRadiusThreshold = GetFloatCVar(e_ParticlesLightMinRadiusThreshold);
  100.  
  101.                         const ColorF& cColor = light.m_Color;
  102.                         const float spectralIntensity = cColor.r * 0.299f + cColor.g * 0.587f + cColor.b * 0.114f;
  103.                         const Vec4* vLight = (Vec4*)&light.m_Origin.x;
  104.                         if (spectralIntensity > minColorThreshold && vLight->w > minRadiusThreshold)
  105.                         {
  106.                                 Get3DEngine()->SetupLightScissors(&light, passInfo);
  107.                                 light.m_n3DEngineUpdateFrameID = passInfo.GetMainFrameID();
  108.                                 Get3DEngine()->AddLightToRenderer(light, 1.0f, passInfo);
  109.                         }
  110.                 }
  111.                 CRY_PFX2_FOR_END;
  112.         }
  113.  
  114. private:
  115.         UFloat10         m_intensity;
  116.         UFloat10         m_radius;
  117.         ELightAffectsFog m_affectsFog;
  118.         bool             m_affectsThisAreaOnly;
  119. };
  120.  
  121. static const ColorB lightColor = ColorB(230, 216, 0);
  122. CRY_PFX2_IMPLEMENT_FEATURE(CParticleFeature, CFeatureLightSource, "Light", "Light", colorLight);
  123.  
  124. }
  125.  
downloadFeatureLightSource.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