MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / DrawFlare

Method DrawFlare

engine/Poseidon/World/Scene/SceneDraw.cpp:142–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140 }
141 return 0;
142}
143
144void Scene::EndObjects()
145{
146 // sort by screen size
147}
148
149void Scene::DrawFlare(ColorVal color, Vector3Par lightPos, bool secondary)
150{
151 Color lightColor = color * GEngine->GetAccomodateEye();
152 float oldA = lightColor.A();
153 // we can draw flares now
154 // flare positions between posLight (0) and screen center (1)
155 static const float flarePos[FlareLast + 1 - Flare0] = {0.0f, -0.2f, -0.1f, +0.25f, +0.275f, +0.3f,
156 +0.4f, +0.5f, +0.65f, +0.7f, +0.725f, +0.75f,
157 +0.875f, +0.885f, +1.0f, +1.1f};
158 // note - z is ignored when doing 2D draw
159 // but is significant for decal draw
160 float w = GLOB_ENGINE->Width();
161 float h = GLOB_ENGINE->Height();
162 // calculate screen position of light
163 Vector3Val pos = ScaledInvTransform() * lightPos;
164 // apply perspective
165 Matrix4Val project = GetCamera()->Projection();
166 const float thold = 0.6f;
167 if (pos[2] < thold)
168 {
169 return; // no flares
170 }
171 float vis = (pos[2] - thold) * (1.0f / (1 - thold));
172 saturateMin(vis, 1);
173 float a = 0.9f * vis * vis;
174 if (a > 0.01)
175 {
176 float invW = 1 / pos[2];
177 Vector3 lightPos(project(0, 2) + project(0, 0) * pos[0] * invW, project(1, 2) + project(1, 1) * pos[1] * invW,
178 1);
179
180 float size = 0.1f;
181 float sizeX = +project(0, 0) * size * GetCamera()->InvLeft();
182 float sizeY = -project(1, 1) * size * GetCamera()->InvTop();
183
184 Vector3 center(0.5f * w, 0.5f * h, 1);
185 const int special = NoZBuf | IsLight | ClampU | ClampV | IsAlphaFog;
186 // Flare0 is handled specially
187 {
188 lightColor.SetA(oldA * a * 2);
189 PackedColor color = PackedColor(lightColor);
190 Texture* texture = Preloaded(PreloadedTexture(Flare0));
191 if (texture)
192 {
193 MipInfo mip = GLOB_ENGINE->TextBank()->UseMipmap(texture, 0, 0);
194 if (mip.IsOK())
195 {
196 float sizeCoef = texture->AWidth() * (1.0f / 64);
197 GEngine->DrawDecal(lightPos, 1, sizeX * sizeCoef, sizeY * sizeCoef, color, mip, special);
198 }
199 }

Callers

nothing calls this directly

Calls 14

saturateMinFunction · 0.85
GetAccomodateEyeMethod · 0.80
InvLeftMethod · 0.80
InvTopMethod · 0.80
IsOKMethod · 0.80
AWidthMethod · 0.80
PackedColorClass · 0.50
AMethod · 0.45
WidthMethod · 0.45
HeightMethod · 0.45
SetAMethod · 0.45
UseMipmapMethod · 0.45

Tested by

no test coverage detected