Skip to content

Commit 8719cec

Browse files
committed
Bring back С++ PLC functions
Currently not used, I'm testing if SSE function working on x64 This was deleted with commit cdd6c53
1 parent f1bbc91 commit 8719cec

File tree

6 files changed

+94
-7
lines changed

6 files changed

+94
-7
lines changed

src/xrCore/Math/MathUtil.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
#include "xrEngine/Render.h"
1313
#include "Layers/xrRender/light.h"
1414
#endif
15+
#include "PLC_SSE.hpp"
1516
#ifdef XR_X86
1617
#include "SkinXW_SSE.hpp"
1718
#else
1819
#include "SkinXW_CPP.hpp"
20+
#include "PLC_CPP.hpp"
1921
#endif
2022
#include "Skin4W_MT.hpp"
21-
#include "PLC_SSE.hpp"
23+
2224
#include "_math.h"
2325

2426
namespace XRay
@@ -43,14 +45,16 @@ void Initialize()
4345
Skin3W = Skin3W_SSE;
4446
Skin4W = Skin4W_SSE;
4547
Skin4W_MTs = Skin4W_SSE;
48+
PLCCalc = PLCCalc_SSE;
4649
#else
4750
Skin1W = Skin1W_CPP;
4851
Skin2W = Skin2W_CPP;
4952
Skin3W = Skin3W_CPP;
5053
Skin4W = Skin4W_CPP;
5154
Skin4W_MTs = Skin4W_CPP;
52-
#endif
5355
PLCCalc = PLCCalc_SSE;
56+
//PLCCalc = PLCCalc_CPP;
57+
#endif
5458

5559
if (ttapi_GetWorkerCount() > 1)
5660
Skin4W = Skin4W_MT;

src/xrCore/Math/PLC_CPP.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "stdafx.h"
2+
#include "_bitwise.h"
3+
#ifndef _EDITOR
4+
#define RENDER 1
5+
#include "xrEngine/Render.h"
6+
#include "Layers/xrRender/light.h"
7+
#endif
8+
9+
namespace XRay
10+
{
11+
namespace Math
12+
{
13+
static constexpr float S_distance = 48;
14+
static constexpr float S_distance2 = S_distance * S_distance;
15+
static constexpr float S_fade = 4.5;
16+
static constexpr float S_fade2 = S_fade * S_fade;
17+
18+
IC float PLC_energy_CPP(const Fvector& p, const Fvector& n, const light* L, float e)
19+
{
20+
Fvector Ldir;
21+
if (L->flags.type == IRender_Light::DIRECT)
22+
{
23+
// Cos
24+
Ldir.invert(L->direction);
25+
float D = Ldir.dotproduct(n);
26+
if (D <= 0) return 0;
27+
return e;
28+
}
29+
// Distance
30+
float sqD = p.distance_to_sqr(L->position);
31+
if (sqD > (L->range * L->range)) return 0;
32+
33+
// Dir
34+
Ldir.sub(L->position, p);
35+
Ldir.normalize_safe();
36+
float D = Ldir.dotproduct(n);
37+
if (D <= 0) return 0;
38+
39+
// Trace Light
40+
float R = _sqrt(sqD);
41+
float att = 1 - (1 / (1 + R));
42+
return (e * att);
43+
}
44+
45+
void PLCCalc_CPP(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector* ps, const Fvector& n, const light* l,
46+
float energy, const Fvector& obj)
47+
{
48+
float E = PLC_energy_CPP(ps[0], n, l, energy);
49+
float C1 = clampr(camPos.distance_to_sqr(ps[0]) / S_distance2, 0.f, 1.f);
50+
float C2 = clampr(obj.distance_to_sqr(ps[0]) / S_fade2, 0.f, 1.f);
51+
float A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
52+
c0 = iCeil(255.f * A);
53+
E = PLC_energy_CPP(ps[1], n, l, energy);
54+
C1 = clampr(camPos.distance_to_sqr(ps[1]) / S_distance2, 0.f, 1.f);
55+
C2 = clampr(obj.distance_to_sqr(ps[1]) / S_fade2, 0.f, 1.f);
56+
A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
57+
c1 = iCeil(255.f * A);
58+
E = PLC_energy_CPP(ps[2], n, l, energy);
59+
C1 = clampr(camPos.distance_to_sqr(ps[2]) / S_distance2, 0.f, 1.f);
60+
C2 = clampr(obj.distance_to_sqr(ps[2]) / S_fade2, 0.f, 1.f);
61+
A = 1.f - 1.5f * E * (1.f - C1) * (1.f - C2);
62+
c2 = iCeil(255.f * A);
63+
}
64+
} // namespace Math
65+
} // namespace XRay

src/xrCore/Math/PLC_CPP.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
#include "MathUtil.hpp"
3+
4+
namespace XRay
5+
{
6+
namespace Math
7+
{
8+
void PLCCalc_CPP(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector* ps, const Fvector& n, const light* l,
9+
float energy, const Fvector& obj);
10+
} // namespace Math
11+
} // namespace XRay

src/xrCore/Math/PLC_SSE.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace XRay
99
{
1010
namespace Math
1111
{
12-
static const float S_distance = 48;
13-
static const float S_distance2 = S_distance * S_distance;
14-
static const float S_fade = 4.5;
15-
static const float S_fade2 = S_fade * S_fade;
12+
static constexpr float S_distance = 48;
13+
static constexpr float S_distance2 = S_distance * S_distance;
14+
static constexpr float S_fade = 4.5;
15+
static constexpr float S_fade2 = S_fade * S_fade;
1616

1717
static ICF float PLC_energy_SSE(const Fvector& p, const Fvector& n, const light* L, float e)
1818
{
@@ -67,6 +67,5 @@ void PLCCalc_SSE(int& c0, int& c1, int& c2, const Fvector& camPos, const Fvector
6767
a = 1.f - 1.5f * e * (1.f - nc1) * (1.f - nc2);
6868
c2 = iCeil_SSE(255.f * a);
6969
}
70-
7170
} // namespace Math
7271
} // namespace XRay

src/xrCore/xrCore.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
<ClCompile Include="LocatorAPI_defs.cpp" />
334334
<ClCompile Include="log.cpp" />
335335
<ClCompile Include="LzHuf.cpp" />
336+
<ClCompile Include="Math\PLC_CPP.cpp" />
336337
<ClCompile Include="Math\PLC_SSE.cpp" />
337338
<ClCompile Include="Math\SkinXW_CPP.cpp" />
338339
<ClCompile Include="Math\Skin4W_MT.cpp" />
@@ -501,6 +502,7 @@
501502
<ClInclude Include="LocatorAPI_defs.h" />
502503
<ClInclude Include="log.h" />
503504
<ClInclude Include="lzhuf.h" />
505+
<ClInclude Include="Math\PLC_CPP.hpp" />
504506
<ClInclude Include="Math\PLC_SSE.hpp" />
505507
<ClInclude Include="Math\Random32.hpp" />
506508
<ClInclude Include="Math\Skin4W_MT.hpp" />

src/xrCore/xrCore.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
<ClCompile Include="Math\SkinXW_CPP.cpp">
361361
<Filter>Math</Filter>
362362
</ClCompile>
363+
<ClCompile Include="Math\PLC_CPP.cpp">
364+
<Filter>Math</Filter>
365+
</ClCompile>
363366
</ItemGroup>
364367
<ItemGroup>
365368
<ClInclude Include="FTimer.h">
@@ -758,6 +761,9 @@
758761
<ClInclude Include="Math\SkinXW_CPP.hpp">
759762
<Filter>Math</Filter>
760763
</ClInclude>
764+
<ClInclude Include="Math\PLC_CPP.hpp">
765+
<Filter>Math</Filter>
766+
</ClInclude>
761767
</ItemGroup>
762768
<ItemGroup>
763769
<ResourceCompile Include="xrCore.rc">

0 commit comments

Comments
 (0)