Skip to content

Commit

Permalink
Bring back С++ PLC functions
Browse files Browse the repository at this point in the history
Currently not used, I'm testing if SSE function working on x64
This was deleted with commit cdd6c53
  • Loading branch information
Xottab-DUTY committed Aug 11, 2017
1 parent f1bbc91 commit 8719cec
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/xrCore/Math/MathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
#include "xrEngine/Render.h"
#include "Layers/xrRender/light.h"
#endif
#include "PLC_SSE.hpp"
#ifdef XR_X86
#include "SkinXW_SSE.hpp"
#else
#include "SkinXW_CPP.hpp"
#include "PLC_CPP.hpp"
#endif
#include "Skin4W_MT.hpp"
#include "PLC_SSE.hpp"

#include "_math.h"

namespace XRay
Expand All @@ -43,14 +45,16 @@ void Initialize()
Skin3W = Skin3W_SSE;
Skin4W = Skin4W_SSE;
Skin4W_MTs = Skin4W_SSE;
PLCCalc = PLCCalc_SSE;
#else
Skin1W = Skin1W_CPP;
Skin2W = Skin2W_CPP;
Skin3W = Skin3W_CPP;
Skin4W = Skin4W_CPP;
Skin4W_MTs = Skin4W_CPP;
#endif
PLCCalc = PLCCalc_SSE;
//PLCCalc = PLCCalc_CPP;
#endif

if (ttapi_GetWorkerCount() > 1)
Skin4W = Skin4W_MT;
Expand Down
65 changes: 65 additions & 0 deletions src/xrCore/Math/PLC_CPP.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "stdafx.h"
#include "_bitwise.h"
#ifndef _EDITOR
#define RENDER 1
#include "xrEngine/Render.h"
#include "Layers/xrRender/light.h"
#endif

namespace XRay
{
namespace Math
{
static constexpr float S_distance = 48;
static constexpr float S_distance2 = S_distance * S_distance;
static constexpr float S_fade = 4.5;
static constexpr float S_fade2 = S_fade * S_fade;

IC float PLC_energy_CPP(const Fvector& p, const Fvector& n, const light* L, float e)
{
Fvector Ldir;
if (L->flags.type == IRender_Light::DIRECT)
{
// Cos
Ldir.invert(L->direction);
float D = Ldir.dotproduct(n);
if (D <= 0) return 0;
return e;
}
// Distance
float sqD = p.distance_to_sqr(L->position);
if (sqD > (L->range * L->range)) return 0;

// Dir
Ldir.sub(L->position, p);
Ldir.normalize_safe();
float D = Ldir.dotproduct(n);
if (D <= 0) return 0;

// Trace Light
float R = _sqrt(sqD);
float att = 1 - (1 / (1 + R));
return (e * att);
}

void PLCCalc_CPP(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector* ps, const Fvector& n, const light* l,
float energy, const Fvector& obj)
{
float E = PLC_energy_CPP(ps[0], n, l, energy);
float C1 = clampr(camPos.distance_to_sqr(ps[0]) / S_distance2, 0.f, 1.f);
float C2 = clampr(obj.distance_to_sqr(ps[0]) / S_fade2, 0.f, 1.f);
float A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
c0 = iCeil(255.f * A);
E = PLC_energy_CPP(ps[1], n, l, energy);
C1 = clampr(camPos.distance_to_sqr(ps[1]) / S_distance2, 0.f, 1.f);
C2 = clampr(obj.distance_to_sqr(ps[1]) / S_fade2, 0.f, 1.f);
A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
c1 = iCeil(255.f * A);
E = PLC_energy_CPP(ps[2], n, l, energy);
C1 = clampr(camPos.distance_to_sqr(ps[2]) / S_distance2, 0.f, 1.f);
C2 = clampr(obj.distance_to_sqr(ps[2]) / S_fade2, 0.f, 1.f);
A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
c2 = iCeil(255.f * A);
}
} // namespace Math
} // namespace XRay
11 changes: 11 additions & 0 deletions src/xrCore/Math/PLC_CPP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "MathUtil.hpp"

namespace XRay
{
namespace Math
{
void PLCCalc_CPP(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector* ps, const Fvector& n, const light* l,
float energy, const Fvector& obj);
} // namespace Math
} // namespace XRay
9 changes: 4 additions & 5 deletions src/xrCore/Math/PLC_SSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace XRay
{
namespace Math
{
static const float S_distance = 48;
static const float S_distance2 = S_distance * S_distance;
static const float S_fade = 4.5;
static const float S_fade2 = S_fade * S_fade;
static constexpr float S_distance = 48;
static constexpr float S_distance2 = S_distance * S_distance;
static constexpr float S_fade = 4.5;
static constexpr float S_fade2 = S_fade * S_fade;

static ICF float PLC_energy_SSE(const Fvector& p, const Fvector& n, const light* L, float e)
{
Expand Down Expand Up @@ -67,6 +67,5 @@ void PLCCalc_SSE(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector
a = 1.f - 1.5f * e * (1.f - nc1) * (1.f - nc2);
c2 = iCeil_SSE(255.f * a);
}

} // namespace Math
} // namespace XRay
2 changes: 2 additions & 0 deletions src/xrCore/xrCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
<ClCompile Include="LocatorAPI_defs.cpp" />
<ClCompile Include="log.cpp" />
<ClCompile Include="LzHuf.cpp" />
<ClCompile Include="Math\PLC_CPP.cpp" />
<ClCompile Include="Math\PLC_SSE.cpp" />
<ClCompile Include="Math\SkinXW_CPP.cpp" />
<ClCompile Include="Math\Skin4W_MT.cpp" />
Expand Down Expand Up @@ -501,6 +502,7 @@
<ClInclude Include="LocatorAPI_defs.h" />
<ClInclude Include="log.h" />
<ClInclude Include="lzhuf.h" />
<ClInclude Include="Math\PLC_CPP.hpp" />
<ClInclude Include="Math\PLC_SSE.hpp" />
<ClInclude Include="Math\Random32.hpp" />
<ClInclude Include="Math\Skin4W_MT.hpp" />
Expand Down
6 changes: 6 additions & 0 deletions src/xrCore/xrCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@
<ClCompile Include="Math\SkinXW_CPP.cpp">
<Filter>Math</Filter>
</ClCompile>
<ClCompile Include="Math\PLC_CPP.cpp">
<Filter>Math</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="FTimer.h">
Expand Down Expand Up @@ -758,6 +761,9 @@
<ClInclude Include="Math\SkinXW_CPP.hpp">
<Filter>Math</Filter>
</ClInclude>
<ClInclude Include="Math\PLC_CPP.hpp">
<Filter>Math</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="xrCore.rc">
Expand Down

0 comments on commit 8719cec

Please sign in to comment.