/
LightFlare.cpp
154 lines (114 loc) · 3.88 KB
/
LightFlare.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* Copyright 2016-2017 Arx Libertatis Team (see the AUTHORS file)
*
* This file is part of Arx Libertatis.
*
* Arx Libertatis is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Arx Libertatis is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Arx Libertatis. If not, see <http://www.gnu.org/licenses/>.
*/
#include "graphics/effects/LightFlare.h"
#include "core/Core.h"
#include "core/GameTime.h"
#include "game/Player.h"
#include "graphics/Draw.h"
#include "graphics/GlobalFog.h"
#include "graphics/Raycast.h"
#include "graphics/Renderer.h"
#include "graphics/effects/Fade.h"
#include "gui/CinematicBorder.h"
#include "platform/profiler/Profiler.h"
#include "scene/Interactive.h"
#include "scene/Light.h"
static TextureContainer * tflare = NULL;
void init2DFX() {
tflare = TextureContainer::LoadUI("graph/particles/flare");
}
void update2DFX() {
RaycastDebugClear();
ARX_PROFILE_FUNC();
Entity * pTableIO[256];
size_t nNbInTableIO = 0;
float temp_increase = toMs(g_platformTime.lastFrameDuration()) * 0.004f;
const Vec3f camPos = g_camera->m_pos;
bool bComputeIO = false;
Vec4f zFar = g_preparedCamera.m_viewToScreen * Vec4f(0.f, 0.f, g_camera->cdepth * fZFogEnd, 1.f);
float fZFar = zFar.z / zFar.w;
for(size_t i = 0; i < g_culledDynamicLightsCount; i++) {
EERIE_LIGHT * el = g_culledDynamicLights[i];
BackgroundTileData * bkgData = getFastBackgroundData(el->pos.x, el->pos.z);
if(!bkgData || !bkgData->treat) {
el->m_isVisible = false;
continue;
}
if(el->extras & EXTRAS_FLARE) {
Vec3f lv = el->pos;
Vec4f p = worldToClipSpace(lv);
Vec3f pos2d = Vec3f(p) / p.w;
el->m_flareFader -= temp_increase;
if(!(player.Interface & INTER_COMBATMODE) && (player.Interface & INTER_PLAYERBOOK))
continue;
if(p.w > 0.f && pos2d.x > 0.f && pos2d.x < g_size.width()
&& pos2d.y > (cinematicBorder.CINEMA_DECAL * g_sizeRatio.y)
&& pos2d.y < (g_size.height() - (cinematicBorder.CINEMA_DECAL * g_sizeRatio.y))) {
Vec3f vector = lv - camPos;
lv -= vector * (50.f / glm::length(vector));
Vec2s ees2dlv;
Vec3f ee3dlv = lv;
ees2dlv.x = checked_range_cast<short>(pos2d.x);
ees2dlv.y = checked_range_cast<short>(pos2d.y);
if(!bComputeIO) {
GetFirstInterAtPos(ees2dlv, 2, &ee3dlv, pTableIO, &nNbInTableIO);
bComputeIO = true;
}
if( pos2d.z > fZFar
|| RaycastLightFlare(camPos, el->pos)
|| GetFirstInterAtPos(ees2dlv, 3, &ee3dlv, pTableIO, &nNbInTableIO)
) {
el->m_flareFader -= temp_increase * 2.f;
} else {
el->m_flareFader += temp_increase * 2.f;
}
}
el->m_flareFader = glm::clamp(el->m_flareFader, 0.f, .8f);
}
}
}
void goFor2DFX() {
ARX_PROFILE_FUNC();
if(g_debugToggles[6]) {
RaycastDebugDraw();
}
GRenderer->SetFogColor(Color::none);
UseRenderState state(render3D().blend(BlendOne, BlendOne).depthWrite(false).depthTest(false));
for(size_t i = 0; i < g_culledDynamicLightsCount; i++) {
const EERIE_LIGHT & el = *g_culledDynamicLights[i];
if(!el.m_exists || !el.m_isVisible) {
continue;
}
if(el.extras & EXTRAS_FLARE) {
if(el.m_flareFader > 0.f) {
Vec3f ltvv = EE_RT(el.pos);
float v = el.m_flareFader;
if(FADEDIR) {
v *= 1.f - LAST_FADEVALUE;
}
float siz;
if(el.extras & EXTRAS_FIXFLARESIZE)
siz = el.ex_flaresize;
else
siz = -el.ex_flaresize;
EERIEDrawSprite(el.pos, siz, tflare, (el.rgb * v).to<u8>(), ltvv.z);
}
}
}
}