summaryrefslogtreecommitdiffstats
path: root/src/RendererWorld.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/RendererWorld.cpp')
-rw-r--r--src/RendererWorld.cpp505
1 files changed, 382 insertions, 123 deletions
diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp
index 6996762..cb4551f 100644
--- a/src/RendererWorld.cpp
+++ b/src/RendererWorld.cpp
@@ -8,8 +8,6 @@
#include "Frustum.hpp"
#include "Event.hpp"
#include "AssetManager.hpp"
-#include "Renderer.hpp"
-#include "Shader.hpp"
#include "GameState.hpp"
#include "Section.hpp"
#include "RendererSectionData.hpp"
@@ -153,7 +151,7 @@ void RendererWorld::UpdateAllSections(VectorF playerPos) {
}
}
-RendererWorld::RendererWorld() {
+RendererWorld::RendererWorld(std::shared_ptr<Gal::Framebuffer> target) {
OPTICK_EVENT();
MaxRenderingDistance = 2;
numOfWorkers = _max(1, (signed int) std::thread::hardware_concurrency() - 2);
@@ -162,7 +160,7 @@ RendererWorld::RendererWorld() {
globalTimeStart = std::chrono::high_resolution_clock::now();
- PrepareRender();
+ PrepareRender(target);
listener->RegisterHandler("DeleteSectionRender", [this](const Event& eventData) {
OPTICK_EVENT("EV_DeleteSectionRender");
@@ -188,7 +186,7 @@ RendererWorld::RendererWorld() {
}
it->second.UpdateData(parsing[id].renderer);
} else
- sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(parsing[id].renderer)));
+ sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(parsing[id].renderer, sectionsPipeline, sectionsBufferBinding)));
parsing[id] = RendererWorld::SectionParsing();
});
@@ -259,8 +257,7 @@ RendererWorld::RendererWorld() {
listener->RegisterHandler("SetMinLightLevel", [this](const Event& eventData) {
auto value = eventData.get<float>();
- AssetManager::GetAsset<AssetShader>("/altcraft/shaders/face")->shader->Activate();
- AssetManager::GetAsset<AssetShader>("/altcraft/shaders/face")->shader->SetUniform("MinLightLevel", value);
+ sectionsPipeline->SetShaderParameter("MinLightLevel", value);
});
for (int i = 0; i < numOfWorkers; i++)
@@ -282,175 +279,437 @@ RendererWorld::~RendererWorld() {
DebugInfo::readyRenderer = 0;
}
-void RendererWorld::Render(RenderState & renderState) {
+void RendererWorld::Render(float screenRatio) {
OPTICK_EVENT();
//Common
glm::mat4 projection = glm::perspective(
- glm::radians(70.0f), (float) renderState.WindowWidth / (float) renderState.WindowHeight,
+ glm::radians(70.0f), screenRatio,
0.1f, 10000000.0f
);
glm::mat4 view = GetGameState()->GetViewMatrix();
glm::mat4 projView = projection * view;
//Render Entities
-#ifndef __APPLE__
- glLineWidth(3.0);
-#endif
- Shader *entityShader = AssetManager::GetAsset<AssetShader>("/altcraft/shaders/entity")->shader.get();
- entityShader->Activate();
- entityShader->SetUniform("projection", projection);
- entityShader->SetUniform("view", view);
- glCheckError();
-
- renderState.SetActiveVao(RendererEntity::GetVao());
+ constexpr size_t entitiesVerticesCount = 240;
+ entitiesPipeline->Activate();
+ entitiesPipeline->SetShaderParameter("projView", projView);
+
+ entitiesPipelineInstance->Activate();
for (auto& it : entities) {
- it.Render(renderState, &GetGameState()->GetWorld());
+ it.Render(entitiesPipeline, &GetGameState()->GetWorld());
+ entitiesPipelineInstance->Render(0, entitiesVerticesCount);
}
//Render selected block
Vector selectedBlock = GetGameState()->GetSelectionStatus().selectedBlock;
if (selectedBlock != Vector()) {
-#ifndef __APPLE__
- glLineWidth(2.0f);
-#endif
{
glm::mat4 model = glm::mat4(1.0);
model = glm::translate(model, selectedBlock.glm());
model = glm::translate(model,glm::vec3(0.5f,0.5f,0.5f));
model = glm::scale(model,glm::vec3(1.01f,1.01f,1.01f));
- entityShader->SetUniform("model", model);
- entityShader->SetUniform("color", glm::vec3(0, 0, 0));
- glCheckError();
- glDrawArrays(GL_LINES, 0, 24);
+ entitiesPipeline->SetShaderParameter("model", model);
+ entitiesPipeline->SetShaderParameter("color", glm::vec3(0, 0, 0));
+ entitiesPipelineInstance->Render(0, entitiesVerticesCount);
}
}
//Render raycast hit
const bool renderHit = false;
if (renderHit) {
- VectorF hit = GetGameState()->GetSelectionStatus().raycastHit;
-#ifndef __APPLE__
- glLineWidth(2.0f);
-#endif
+ VectorF hit = GetGameState()->GetSelectionStatus().raycastHit;
{
glm::mat4 model;
model = glm::translate(model, hit.glm());
- model = glm::scale(model,glm::vec3(0.3f,0.3f,0.3f));
- entityShader->SetUniform("model", model);
+ model = glm::scale(model, glm::vec3(0.3f, 0.3f, 0.3f));
+ //entityShader->SetUniform("model", model);
+ entitiesPipeline->SetShaderParameter("model", model);
if (selectedBlock == Vector())
- entityShader->SetUniform("color", glm::vec3(0.7f, 0, 0));
+ entitiesPipeline->SetShaderParameter("color", glm::vec3(0.7f, 0.0f, 0.0f));
else
- entityShader->SetUniform("color", glm::vec3(0, 0, 0.7f));
- glCheckError();
- glDrawArrays(GL_LINE_STRIP, 0, 36);
+ entitiesPipeline->SetShaderParameter("color", glm::vec3(0.0f, 0.0f, 0.7f));
+ entitiesPipelineInstance->Render(0, entitiesVerticesCount);
}
}
-#ifndef __APPLE__
- glLineWidth(1.0);
-#endif
- glCheckError();
//Render sky
- renderState.TimeOfDay = GetGameState()->GetTimeStatus().timeOfDay;
- Shader *skyShader = AssetManager::GetAsset<AssetShader>("/altcraft/shaders/sky")->shader.get();
- skyShader->Activate();
- skyShader->SetUniform("projection", projection);
- skyShader->SetUniform("view", view);
- glm::mat4 model = glm::mat4(1.0);
- model = glm::translate(model, GetGameState()->GetPlayer()->pos.glm());
- const float scale = 1000000.0f;
- model = glm::scale(model, glm::vec3(scale, scale, scale));
- float shift = GetGameState()->GetTimeStatus().interpolatedTimeOfDay / 24000.0f;
- if (shift < 0)
- shift *= -1.0f;
- model = glm::rotate(model, glm::radians(90.0f), glm::vec3(0, 1.0f, 0.0f));
- model = glm::rotate(model, glm::radians(360.0f * shift), glm::vec3(-1.0f, 0.0f, 0.0f));
- skyShader->SetUniform("model", model);
-
- glCheckError();
-
- const int sunriseMin = 22000;
- const int sunriseMax = 23500;
- const int moonriseMin = 12000;
- const int moonriseMax = 13500;
- const float sunriseLength = sunriseMax - sunriseMin;
- const float moonriseLength = moonriseMax - moonriseMin;
-
- float mixLevel = 0;
- float dayTime = GetGameState()->GetTimeStatus().interpolatedTimeOfDay;
- if (dayTime < 0)
- dayTime *= -1;
- while (dayTime > 24000)
- dayTime -= 24000;
- if (dayTime > 0 && dayTime < moonriseMin || dayTime > sunriseMax) //day
- mixLevel = 1.0;
- if (dayTime > moonriseMax && dayTime < sunriseMin) //night
- mixLevel = 0.0;
- if (dayTime >= sunriseMin && dayTime <= sunriseMax) //sunrise
- mixLevel = (dayTime - sunriseMin) / sunriseLength;
- if (dayTime >= moonriseMin && dayTime <= moonriseMax) { //moonrise
- float timePassed = (dayTime - moonriseMin);
- mixLevel = 1.0 - (timePassed / moonriseLength);
- }
+ glm::mat4 model = glm::mat4(1.0);
+ model = glm::translate(model, GetGameState()->GetPlayer()->pos.glm());
+ const float scale = 1000000.0f;
+ model = glm::scale(model, glm::vec3(scale, scale, scale));
+ float shift = GetGameState()->GetTimeStatus().interpolatedTimeOfDay / 24000.0f;
+ if (shift < 0)
+ shift *= -1.0f;
+ model = glm::rotate(model, glm::radians(90.0f), glm::vec3(0, 1.0f, 0.0f));
+ model = glm::rotate(model, glm::radians(360.0f * shift), glm::vec3(-1.0f, 0.0f, 0.0f));
+
+ const int sunriseMin = 22000;
+ const int sunriseMax = 23500;
+ const int moonriseMin = 12000;
+ const int moonriseMax = 13500;
+ const float sunriseLength = sunriseMax - sunriseMin;
+ const float moonriseLength = moonriseMax - moonriseMin;
+
+ float mixLevel = 0;
+ float dayTime = GetGameState()->GetTimeStatus().interpolatedTimeOfDay;
+ if (dayTime < 0)
+ dayTime *= -1;
+ while (dayTime > 24000)
+ dayTime -= 24000;
+ if (dayTime > 0 && dayTime < moonriseMin || dayTime > sunriseMax) //day
+ mixLevel = 1.0;
+ if (dayTime > moonriseMax && dayTime < sunriseMin) //night
+ mixLevel = 0.0;
+ if (dayTime >= sunriseMin && dayTime <= sunriseMax) //sunrise
+ mixLevel = (dayTime - sunriseMin) / sunriseLength;
+ if (dayTime >= moonriseMin && dayTime <= moonriseMax) { //moonrise
+ float timePassed = (dayTime - moonriseMin);
+ mixLevel = 1.0 - (timePassed / moonriseLength);
+ }
- skyShader->SetUniform("DayTime", mixLevel);
+ skyPipeline->Activate();
+ skyPipeline->SetShaderParameter("projView", projView);
+ skyPipeline->SetShaderParameter("model", model);
+ skyPipeline->SetShaderParameter("DayTime", mixLevel);
+ skyPipelineInstance->Activate();
+ skyPipelineInstance->Render(0, 36);
- rendererSky.Render(renderState);
- glCheckError();
//Render sections
- auto rawGlobalTime = (std::chrono::high_resolution_clock::now() - globalTimeStart);
- float globalTime = rawGlobalTime.count() / 1000000000.0f;
- Shader *blockShader = AssetManager::GetAsset<AssetShader>("/altcraft/shaders/face")->shader.get();
- blockShader->Activate();
- blockShader->SetUniform("DayTime", mixLevel);
- blockShader->SetUniform("projView", projView);
- blockShader->SetUniform("GlobalTime", globalTime);
- glCheckError();
+ auto rawGlobalTime = (std::chrono::high_resolution_clock::now() - globalTimeStart);
+ float globalTime = rawGlobalTime.count() / 1000000000.0f;
+ sectionsPipeline->Activate();
+ sectionsPipeline->SetShaderParameter("DayTime", mixLevel);
+ sectionsPipeline->SetShaderParameter("projView", projView);
- Frustum frustum(projView);
+ Frustum frustum(projView);
size_t culledSections = sections.size();
- unsigned int renderedFaces = 0;
+ unsigned int renderedFaces = 0;
for (auto& section : sections) {
- glm::vec3 point{
- section.second.GetPosition().x * 16 + 8,
- section.second.GetPosition().y * 16 + 8,
- section.second.GetPosition().z * 16 + 8
- };
+ glm::vec3 point{
+ section.second.GetPosition().x * 16 + 8,
+ section.second.GetPosition().y * 16 + 8,
+ section.second.GetPosition().z * 16 + 8
+ };
- bool isVisible = frustum.TestSphere(point, 16.0f);
+ bool isVisible = frustum.TestSphere(point, 16.0f);
if (!isVisible) {
culledSections--;
continue;
}
- section.second.Render(renderState);
- renderedFaces += section.second.numOfFaces;
+ section.second.Render();
+ renderedFaces += section.second.numOfFaces;
}
DebugInfo::culledSections = culledSections;
- DebugInfo::renderFaces = renderedFaces;
- glCheckError();
+ DebugInfo::renderFaces = renderedFaces;
}
-void RendererWorld::PrepareRender() {
- Shader *blockShader = AssetManager::GetAsset<AssetShader>("/altcraft/shaders/face")->shader.get();
- blockShader->Activate();
- blockShader->SetUniform("textureAtlas", 0);
- blockShader->SetUniform("MinLightLevel", 0.2f);
-
- TextureCoord sunTexture = AssetManager::GetTexture("/minecraft/textures/environment/sun");
- TextureCoord moonTexture = AssetManager::GetTexture("/minecraft/textures/environment/moon_phases");
- moonTexture.w /= 4.0f; //First phase will be fine for now
- moonTexture.h /= 2.0f;
-
- Shader *sky = AssetManager::GetAsset<AssetShader>("/altcraft/shaders/sky")->shader.get();
- sky->Activate();
- sky->SetUniform("textureAtlas", 0);
- sky->SetUniform("sunTexture", glm::vec4(sunTexture.x, sunTexture.y, sunTexture.w, sunTexture.h));
- sky->SetUniform("sunTextureLayer", (float)sunTexture.layer);
- sky->SetUniform("moonTexture", glm::vec4(moonTexture.x, moonTexture.y, moonTexture.w, moonTexture.h));
- sky->SetUniform("moonTextureLayer", (float)moonTexture.layer);
+void RendererWorld::PrepareRender(std::shared_ptr<Gal::Framebuffer> target) {
+ std::string sectionVertexSource, sectionPixelSource;
+ {
+ auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/face");
+ sectionVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size());
+
+ auto pixelAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/face");
+ sectionPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size());
+ }
+
+ std::string entitiesVertexSource, entitiesPixelSource;
+ {
+ auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/entity");
+ entitiesVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size());
+
+ auto pixelAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/entity");
+ entitiesPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size());
+ }
+
+ std::string skyVertexSource, skyPixelSource;
+ {
+ auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/sky");
+ skyVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size());
+
+ auto pixelAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/sky");
+ skyPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size());
+ }
+
+ auto gal = Gal::GetImplementation();
+ {
+ auto sectionsPLC = gal->CreatePipelineConfig();
+ sectionsPLC->SetTarget(target);
+ sectionsPLC->AddShaderParameter("projView", Gal::Type::Mat4);
+ sectionsPLC->AddShaderParameter("DayTime", Gal::Type::Float);
+ sectionsPLC->AddShaderParameter("GlobalTime", Gal::Type::Float);
+ sectionsPLC->AddShaderParameter("MinLightLevel", Gal::Type::Float);
+ sectionsPLC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas());
+ sectionsPLC->SetVertexShader(gal->LoadVertexShader(sectionVertexSource));
+ sectionsPLC->SetPixelShader(gal->LoadPixelShader(sectionPixelSource));
+ sectionsPLC->SetPrimitive(Gal::Primitive::TriangleFan);
+ sectionsBufferBinding = sectionsPLC->BindVertexBuffer({
+ {"position", Gal::Type::Vec3, 4, 1},
+ {"uv", Gal::Type::Vec2, 4, 1},
+ {"uvLayer", Gal::Type::Float, 1, 1},
+ {"animation", Gal::Type::Float, 1, 1},
+ {"color", Gal::Type::Vec3, 1, 1},
+ {"light", Gal::Type::Vec2, 1, 1},
+ {"", Gal::Type::Uint8, 20, 1}
+ });
+ sectionsPipeline = gal->BuildPipeline(sectionsPLC);
+ sectionsPipeline->SetShaderParameter("MinLightLevel", 0.2f);
+ }
+
+ {
+ auto entitiesPLC = gal->CreatePipelineConfig();
+ entitiesPLC->SetTarget(target);
+ entitiesPLC->AddShaderParameter("projView", Gal::Type::Mat4);
+ entitiesPLC->AddShaderParameter("model", Gal::Type::Mat4);
+ entitiesPLC->AddShaderParameter("color", Gal::Type::Vec3);
+ entitiesPLC->SetVertexShader(gal->LoadVertexShader(entitiesVertexSource));
+ entitiesPLC->SetPixelShader(gal->LoadPixelShader(entitiesPixelSource));
+ entitiesPLC->SetPrimitive(Gal::Primitive::Triangle);
+ auto entitiesPosBB = entitiesPLC->BindVertexBuffer({
+ {"position", Gal::Type::Vec3},
+ });
+ auto entitiesIndicesBB = entitiesPLC->BindIndexBuffer();
+
+ entitiesPipeline = gal->BuildPipeline(entitiesPLC);
+
+ constexpr float lw = 0.485f; // line width
+
+ constexpr float vertices[] = {
+ 0.0f, 0.0f, 0.0f,
+ 0.5f, 0.5f, -0.5f,
+ 0.5f, -0.5f, -0.5f,
+ 0.5f, 0.5f, 0.5f,
+ 0.5f, -0.5f, 0.5f,
+ -0.5f, 0.5f, -0.5f,
+ -0.5f, -0.5f, -0.5f,
+ -0.5f, 0.5f, 0.5f,
+ -0.5f, -0.5f, 0.5f,
+ -0.5f, lw, 0.5f,
+ 0.5f, lw, -0.5f,
+ 0.5f, lw, 0.5f,
+ -0.5f, lw, -0.5f,
+ 0.5f, -lw, -0.5f,
+ 0.5f, -lw, 0.5f,
+ -0.5f, -lw, -0.5f,
+ -0.5f, -lw, 0.5f,
+ -0.5f, -0.5f, lw,
+ 0.5f, 0.5f, lw,
+ 0.5f, lw, lw,
+ 0.5f, -lw, lw,
+ -0.5f, 0.5f, lw,
+ 0.5f, -0.5f, lw,
+ -0.5f, lw, lw,
+ -0.5f, -lw, lw,
+ -0.5f, 0.5f, -lw,
+ 0.5f, -0.5f, -lw,
+ -0.5f, lw, -lw,
+ -0.5f, -lw, -lw,
+ -0.5f, -0.5f, -lw,
+ 0.5f, 0.5f, -lw,
+ 0.5f, lw, -lw,
+ 0.5f, -lw, -lw,
+ -lw, lw, 0.5f,
+ -lw, -lw, 0.5f,
+ -lw, lw, -0.5f,
+ -lw, -0.5f, lw,
+ -lw, -0.5f, -lw,
+ -lw, -lw, -0.5f,
+ -lw, 0.5f, lw,
+ -lw, 0.5f, -lw,
+ lw, lw, -0.5f,
+ lw, -lw, -0.5f,
+ lw, lw, 0.5f,
+ lw, 0.5f, lw,
+ lw, 0.5f, -lw,
+ lw, -lw, 0.5f,
+ lw, -0.5f, lw,
+ lw, -0.5f, -lw,
+ };
+
+ constexpr int indices[] = {
+ 47, 26, 22,
+ 7, 33, 43,
+ 18, 11, 19,
+ 12, 28, 27,
+ 31, 13, 10,
+ 43, 14, 11,
+ 25, 12, 27,
+ 20, 4, 22,
+ 1, 41, 35,
+ 3, 18, 44,
+ 9, 24, 16,
+ 28, 6, 29,
+ 45, 30, 1,
+ 11, 20, 19,
+ 35, 15, 12,
+ 39, 25, 21,
+ 2, 6, 38,
+ 45, 18, 30,
+ 37, 29, 6,
+ 8, 4, 46,
+ 10, 42, 41,
+ 8, 17, 36,
+ 9, 34, 33,
+ 37, 17, 29,
+ 47, 48, 26,
+ 11, 3, 43,
+ 3, 7, 43,
+ 7, 9, 33,
+ 1, 30, 10,
+ 30, 18, 31,
+ 10, 30, 31,
+ 18, 3, 11,
+ 19, 31, 18,
+ 12, 15, 28,
+ 31, 32, 13,
+ 43, 46, 14,
+ 7, 21, 9,
+ 21, 25, 23,
+ 9, 21, 23,
+ 25, 5, 12,
+ 27, 23, 25,
+ 13, 32, 2,
+ 32, 20, 26,
+ 2, 32, 26,
+ 20, 14, 4,
+ 22, 26, 20,
+ 12, 5, 35,
+ 5, 1, 35,
+ 1, 10, 41,
+ 44, 39, 3,
+ 39, 21, 7,
+ 3, 39, 7,
+ 9, 23, 24,
+ 16, 24, 8,
+ 24, 28, 17,
+ 8, 24, 17,
+ 28, 15, 6,
+ 29, 17, 28,
+ 1, 5, 40,
+ 5, 25, 40,
+ 40, 45, 1,
+ 11, 14, 20,
+ 35, 38, 15,
+ 39, 40, 25,
+ 15, 38, 6,
+ 38, 42, 2,
+ 42, 13, 2,
+ 45, 44, 18,
+ 6, 2, 48,
+ 2, 26, 48,
+ 48, 37, 6,
+ 14, 46, 4,
+ 46, 34, 8,
+ 34, 16, 8,
+ 10, 13, 42,
+ 36, 47, 8,
+ 47, 22, 4,
+ 8, 47, 4,
+ 9, 16, 34,
+ 37, 36, 17,
+ };
+
+ entitiesPosBuffer = gal->CreateBuffer();
+ entitiesPosBuffer->SetData({ reinterpret_cast<const std::byte*>(vertices), reinterpret_cast<const std::byte*>(vertices) + sizeof(vertices) });
+ entitiesIndexBuffer = gal->CreateBuffer();
+ entitiesIndexBuffer->SetData({ reinterpret_cast<const std::byte*>(indices), reinterpret_cast<const std::byte*>(indices) + sizeof(indices) });
+
+ entitiesPipelineInstance = entitiesPipeline->CreateInstance({
+ {entitiesPosBB, entitiesPosBuffer},
+ {entitiesIndicesBB, entitiesIndexBuffer}
+ });
+ }
+
+ {
+ auto skyPPC = gal->CreatePipelineConfig();
+ skyPPC->SetTarget(target);
+ skyPPC->AddShaderParameter("sunTexture", Gal::Type::Vec4);
+ skyPPC->AddShaderParameter("sunTextureLayer", Gal::Type::Float);
+ skyPPC->AddShaderParameter("moonTexture", Gal::Type::Vec4);
+ skyPPC->AddShaderParameter("moonTextureLayer", Gal::Type::Float);
+ skyPPC->AddShaderParameter("DayTime", Gal::Type::Float);
+ skyPPC->AddShaderParameter("projView", Gal::Type::Mat4);
+ skyPPC->AddShaderParameter("model", Gal::Type::Mat4);
+ skyPPC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas());
+ skyPPC->SetVertexShader(gal->LoadVertexShader(skyVertexSource));
+ skyPPC->SetPixelShader(gal->LoadPixelShader(skyPixelSource));
+ auto skyPosUvBB = skyPPC->BindVertexBuffer({
+ {"position", Gal::Type::Vec3},
+ {"", Gal::Type::Vec2},
+ });
+
+ constexpr float vertices[] = {
+ //Z+ Positions UVs
+ -0.5f, -0.5f, 0.5f, 0.0f, 1.0f,
+ -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
+ 0.5f, -0.5f, 0.5f, 0.0f, 1.0f,
+ -0.5f, 0.5f, 0.5f, 1.0f, 0.0f,
+ 0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
+
+ //Z-
+ -0.5f, 0.5f, -0.5f, 1.0f, 0.0f,
+ -0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
+ 0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
+ -0.5f, 0.5f, -0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
+ 0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
+
+ //X+
+ -0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
+ -0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
+ -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.5f, 0.0f, 1.0f,
+ -0.5f, 0.5f, -0.5f, 1.0f, 0.0f,
+ -0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
+
+ //X-
+ 0.5f, 0.5f, -0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.5f, 1.0f, 1.0f,
+ 0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
+ 0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
+ 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
+
+ //Y+
+ -0.5f, 0.5f, 0.5f, 0.0f, 0.0f,
+ 0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
+ 0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
+ -0.5f, 0.5f, -0.5f, 0.0f, 0.0f,
+ 0.5f, 0.5f, -0.5f, 1.0f, 0.0f,
+ -0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
+
+ //Y-
+ 0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
+ -0.5f, -0.5f, 0.5f, 0.0f, 1.0f,
+ 0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
+ 0.5f, -0.5f, -0.5f, 1.0f, 1.0f,
+ -0.5f, -0.5f, -0.5f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
+ };
+
+ TextureCoord sunTexture = AssetManager::GetTexture("/minecraft/textures/environment/sun");
+ TextureCoord moonTexture = AssetManager::GetTexture("/minecraft/textures/environment/moon_phases");
+ moonTexture.w /= 4.0f; // First phase will be fine for now
+ moonTexture.h /= 2.0f;
+
+ skyPipeline = gal->BuildPipeline(skyPPC);
+ skyPipeline->Activate();
+ skyPipeline->SetShaderParameter("sunTexture", glm::vec4(sunTexture.x, sunTexture.y, sunTexture.w, sunTexture.h));
+ skyPipeline->SetShaderParameter("sunTextureLayer", static_cast<float>(sunTexture.layer));
+ skyPipeline->SetShaderParameter("moonTexture", glm::vec4(moonTexture.x, moonTexture.y, moonTexture.w, moonTexture.h));
+ skyPipeline->SetShaderParameter("moonTextureLayer", static_cast<float>(moonTexture.layer));
+
+ skyBuffer = gal->CreateBuffer();
+ skyBuffer->SetData({ reinterpret_cast<const std::byte*>(vertices), reinterpret_cast<const std::byte*>(vertices) + sizeof(vertices) });
+
+ skyPipelineInstance = skyPipeline->CreateInstance({
+ {skyPosUvBB, skyBuffer}
+ });
+ }
}
void RendererWorld::Update(double timeToUpdate) {