|
| 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 |
0 commit comments