fix stars and skybox render
This commit is contained in:
parent
ac9772cd67
commit
8a3306ed41
@ -12,6 +12,8 @@
|
||||
#include <stdexcept>
|
||||
#include <random>
|
||||
|
||||
// TODO: REFACTOR WHOLE RENDER ENGINE
|
||||
|
||||
using namespace advanced_pipeline;
|
||||
|
||||
PostProcessing::PostProcessing(size_t effectSlotsCount)
|
||||
|
||||
@ -91,20 +91,29 @@ void Skybox::drawBackground(
|
||||
void Skybox::drawStars(float angle, float opacity) {
|
||||
batch3d->texture(nullptr);
|
||||
random.setSeed(STARS_SEED);
|
||||
|
||||
glm::mat4 rotation = glm::rotate(
|
||||
glm::mat4(1.0f),
|
||||
-angle + glm::pi<float>() * 0.5f,
|
||||
glm::vec3(0, 0, -1)
|
||||
);
|
||||
rotation = glm::rotate(rotation, sunAltitude, glm::vec3(1, 0, 0));
|
||||
|
||||
float depth = 1e3;
|
||||
for (int i = 0; i < STARS_COUNT; i++) {
|
||||
float rx = (random.randFloat()) - 0.5f;
|
||||
float ry = (random.randFloat()) - 0.5f;
|
||||
float z = (random.randFloat()) - 0.5f;
|
||||
float x = rx * std::sin(angle) + ry * -std::cos(angle);
|
||||
float y = rx * std::cos(angle) + ry * std::sin(angle);
|
||||
float rz = (random.randFloat()) - 0.5f;
|
||||
|
||||
glm::vec3 pos = glm::vec4(rx, ry, rz, 1) * rotation;
|
||||
|
||||
float sopacity = random.randFloat();
|
||||
if (y < 0.0f)
|
||||
if (pos.y < 0.0f)
|
||||
continue;
|
||||
|
||||
sopacity *= (0.2f+std::sqrt(std::cos(angle))*0.5f) - 0.05f;
|
||||
sopacity *= (0.2f + std::sqrt(std::cos(angle)) * 0.5f) - 0.05f;
|
||||
glm::vec4 tint (1,1,1, sopacity * opacity);
|
||||
batch3d->point(glm::vec3(x, y, z), tint);
|
||||
batch3d->point(pos * depth, tint);
|
||||
}
|
||||
batch3d->flushPoints();
|
||||
}
|
||||
@ -158,7 +167,7 @@ void Skybox::draw(
|
||||
up, 1, 1, UVRegion(), tint);
|
||||
}
|
||||
batch3d->flush();
|
||||
//drawStars(angle, opacity);
|
||||
drawStars(angle, opacity);
|
||||
}
|
||||
|
||||
void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality) {
|
||||
@ -180,6 +189,16 @@ void Skybox::refresh(const DrawContext& pctx, float t, float mie, uint quality)
|
||||
t *= glm::two_pi<float>();
|
||||
|
||||
lightDir = glm::normalize(glm::vec3(sin(t), -cos(t), 0.0f));
|
||||
|
||||
float sunAngle = glm::radians((t / glm::two_pi<float>() - 0.25f) * 360.0f);
|
||||
float x = -glm::cos(sunAngle + glm::pi<float>() * 0.5f) * glm::radians(sunAltitude);
|
||||
float y = sunAngle - glm::pi<float>() * 0.5f;
|
||||
float z = glm::radians(0.0f);
|
||||
rotation = glm::rotate(glm::mat4(1.0f), y, glm::vec3(0, 1, 0));
|
||||
rotation = glm::rotate(rotation, x, glm::vec3(1, 0, 0));
|
||||
rotation = glm::rotate(rotation, z, glm::vec3(0, 0, 1));
|
||||
lightDir = glm::vec3(rotation * glm::vec4(0, 0, -1, 1));
|
||||
|
||||
shader.uniform1i("u_quality", quality);
|
||||
shader.uniform1f("u_mie", mie);
|
||||
shader.uniform1f("u_fog", mie - 1.0f);
|
||||
|
||||
@ -48,6 +48,8 @@ class Skybox {
|
||||
|
||||
float prevMie = -1.0f;
|
||||
float prevT = -1.0f;
|
||||
float sunAltitude = 45.0f;
|
||||
glm::mat4 rotation;
|
||||
|
||||
void drawStars(float angle, float opacity);
|
||||
void drawBackground(
|
||||
|
||||
@ -60,6 +60,7 @@ using namespace advanced_pipeline;
|
||||
inline constexpr size_t BATCH3D_CAPACITY = 4096;
|
||||
inline constexpr size_t MODEL_BATCH_CAPACITY = 20'000;
|
||||
inline constexpr GLenum TEXTURE_MAIN = GL_TEXTURE0;
|
||||
inline constexpr int MIN_SHADOW_MAP_RES = 512;
|
||||
|
||||
bool WorldRenderer::showChunkBorders = false;
|
||||
bool WorldRenderer::showEntitiesDebug = false;
|
||||
@ -246,7 +247,7 @@ void WorldRenderer::renderBlockSelection() {
|
||||
const glm::vec3 center = glm::vec3(pos) + hitbox.center();
|
||||
const glm::vec3 size = hitbox.size();
|
||||
lineBatch->box(
|
||||
center, size + glm::vec3(0.01), glm::vec4(0.f, 0.f, 0.f, 0.5f)
|
||||
center, size + glm::vec3(0.01), glm::vec4(0.f, 0.f, 0.f, 1.0f)
|
||||
);
|
||||
if (debug) {
|
||||
lineBatch->line(
|
||||
@ -380,7 +381,6 @@ void WorldRenderer::generateShadowsMap(
|
||||
sunAngle - glm::pi<float>() * 0.5f,
|
||||
glm::radians(0.0f)
|
||||
);
|
||||
shadowCamera.updateVectors();
|
||||
|
||||
shadowCamera.position -= shadowCamera.front * 500.0f;
|
||||
shadowCamera.position += shadowCamera.up * 0.0f;
|
||||
@ -433,7 +433,7 @@ void WorldRenderer::draw(
|
||||
|
||||
gbufferPipeline = settings.graphics.advancedRender.get();
|
||||
int shadowsQuality = settings.graphics.shadowsQuality.get() * gbufferPipeline;
|
||||
int resolution = 512 << shadowsQuality;
|
||||
int resolution = MIN_SHADOW_MAP_RES << shadowsQuality;
|
||||
if (shadowsQuality > 0 && !shadows) {
|
||||
shadowMap = std::make_unique<ShadowMap>(resolution);
|
||||
wideShadowMap = std::make_unique<ShadowMap>(resolution);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user