MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / drawRay

Method drawRay

source/rendering/StarEnvironmentPainter.cpp:373–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373void EnvironmentPainter::drawRay(float pixelRatio,
374 SkyRenderData const& sky,
375 Vec2F start,
376 float width,
377 float length,
378 float angle,
379 double time,
380 Vec3B color,
381 float alpha) {
382 // All magic constants are arbritrary to allow the Perlin to act as a PRNG
383
384 float currentTime = sky.timeOfDay / sky.dayLength;
385 float timeSinceSunEvent = std::min(std::abs(currentTime - SunriseTime), std::abs(currentTime - SunsetTime));
386 float percentFaded = MaxFade * (1.0f - std::min(1.0f, std::pow(timeSinceSunEvent / SunFadeRate, 2.0f)));
387 // Gets the current average sky color
388 color = (Vec3B)((Vec3F)color * (1 - percentFaded) + (Vec3F)sky.mainSkyColor.toRgb() * percentFaded);
389 // Sum is used to vary the ray intensity based on sky color
390 // Rays show up more on darker backgrounds, so this scales to remove that
391 float sum = std::pow((color[0] + color[1]) * RayColorDependenceScale, RayColorDependenceLevel);
392 Vec3B rayColor;
393 if (sky.settings.queryBool("sun.dynamicImage.enabled", false) && !sky.skyParameters.sunType.empty())
394 rayColor = jsonToVec3B(sky.settings.query("sun.dynamicImage.rayColors." + sky.skyParameters.sunType, sky.settings.query("sun.rayColor", JsonArray{RayColor[0], RayColor[1], RayColor[2]})));
395 else
396 rayColor = jsonToVec3B(sky.settings.query("sun.rayColor", JsonArray{RayColor[0], RayColor[1], RayColor[2]}));
397 float sunScale = sky.settings.queryFloat("sun.scale", 1.0f);
398 m_renderer->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), TexturePtr(),
399 RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * length, {}, Vec4B(rayColor, 0), 0.0f},
400 RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * SunRadius * sunScale * pixelRatio,
401 {},
402 Vec4B(rayColor,
403 (int)(RayMinUnscaledAlpha + std::abs(m_rayPerlin.get(angle * 896 + time * 30) * RayUnscaledAlphaVariance))
404 * sum
405 * alpha), 0.0f},
406 RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * SunRadius * sunScale * pixelRatio,
407 {},
408 Vec4B(rayColor,
409 (int)(RayMinUnscaledAlpha + std::abs(m_rayPerlin.get(angle * 626 + time * 30) * RayUnscaledAlphaVariance))
410 * sum
411 * alpha), 0.0f},
412 RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * length, {}, Vec4B(rayColor, 0), 0.0f});
413}
414
415void EnvironmentPainter::drawOrbiter(float pixelRatio, Vec2F const& screenSize, SkyRenderData const& sky, SkyOrbiter const& orbiter) {
416 float alpha = 1.0f;

Callers

nothing calls this directly

Calls 8

jsonToVec3BFunction · 0.85
toRgbMethod · 0.80
queryBoolMethod · 0.80
queryFloatMethod · 0.80
emptyMethod · 0.45
queryMethod · 0.45
emplace_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected