From 12923669214ba73a809f4e221a634244888b0146 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Thu, 15 Dec 2022 15:53:56 +0500 Subject: Added liquid rendering pass --- .../altcraft/shaders/frag/fwd_liquid_face.fs | 38 ++++++++++++ cwd/assets/altcraft/shaders/frag/liquid_face.fs | 22 +++++++ cwd/assets/altcraft/shaders/vert/liquid_face.vs | 38 ++++++++++++ src/RendererSection.cpp | 54 ++++++++++++----- src/RendererSection.hpp | 25 ++++++-- src/RendererSectionData.cpp | 36 +++++------ src/RendererSectionData.hpp | 3 +- src/RendererWorld.cpp | 69 ++++++++++++++++------ src/RendererWorld.hpp | 6 +- 9 files changed, 232 insertions(+), 59 deletions(-) create mode 100644 cwd/assets/altcraft/shaders/frag/fwd_liquid_face.fs create mode 100644 cwd/assets/altcraft/shaders/frag/liquid_face.fs create mode 100644 cwd/assets/altcraft/shaders/vert/liquid_face.vs diff --git a/cwd/assets/altcraft/shaders/frag/fwd_liquid_face.fs b/cwd/assets/altcraft/shaders/frag/fwd_liquid_face.fs new file mode 100644 index 0000000..f8d9376 --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/fwd_liquid_face.fs @@ -0,0 +1,38 @@ +#version 330 core + +in vec4 faceWorldPos; +in vec3 faceTextureUv; +in vec3 faceAddColor; +in vec3 faceNormal; +in vec2 faceLight; + +out vec4 fragColor; + +uniform sampler2DArray textureAtlas; + +layout (std140) uniform Globals { + mat4 projView; + mat4 proj; + mat4 invProj; + mat4 view; + uvec2 viewportSize; + vec4 ssaoKernels[64]; + float globalTime; + float dayTime; + float gamma; +}; + +void main() { + vec4 col = texture(textureAtlas, faceTextureUv); + + float localLight = faceLight.r / 15.0f; + float skyLight = faceLight.g / 15.0f; + float lightLevel = clamp(localLight + skyLight * dayTime, 0.01f, 1.0f); + lightLevel = pow(lightLevel, 3); + lightLevel = clamp(lightLevel, 0.005f, 1.0f); + + fragColor = vec4(col.rgb * faceAddColor.rgb * lightLevel, 1.0f); + + fragColor.rgb = pow(fragColor.rgb, vec3(1.0f / gamma)); + fragColor.a = col.a; +} diff --git a/cwd/assets/altcraft/shaders/frag/liquid_face.fs b/cwd/assets/altcraft/shaders/frag/liquid_face.fs new file mode 100644 index 0000000..3e5c0d4 --- /dev/null +++ b/cwd/assets/altcraft/shaders/frag/liquid_face.fs @@ -0,0 +1,22 @@ +#version 330 core + +in vec3 faceTextureUv; +in vec3 faceAddColor; +in vec3 faceNormal; +in vec2 faceLight; +in float faceAmbientOcclusion; + +layout (location = 0) out vec4 color; +layout (location = 1) out vec4 normal; +layout (location = 2) out vec4 light; + +uniform sampler2DArray textureAtlas; + +void main() { + vec4 col = texture(textureAtlas, faceTextureUv); + + color = vec4(col.rgb * faceAddColor.rgb, 1.0f); + normal = vec4(faceNormal, 1.0f); + light = vec4(faceLight / 15.0f, faceAmbientOcclusion, 1.0f); + color.a = col.a; +} diff --git a/cwd/assets/altcraft/shaders/vert/liquid_face.vs b/cwd/assets/altcraft/shaders/vert/liquid_face.vs new file mode 100644 index 0000000..101e4d0 --- /dev/null +++ b/cwd/assets/altcraft/shaders/vert/liquid_face.vs @@ -0,0 +1,38 @@ +#version 330 core + +in vec3 pos[4]; +in vec2 uv[4]; +in vec2 light[4]; +in vec3 normal; +in vec3 color; +in vec3 layerAnimationAo; + +out vec3 faceTextureUv; +out vec3 faceNormal; +out vec3 faceAddColor; +out vec2 faceLight; +out float faceAmbientOcclusion; + +layout (std140) uniform Globals { + mat4 projView; + mat4 proj; + mat4 invProj; + mat4 view; + uvec2 viewportSize; + vec4 ssaoKernels[64]; + float globalTime; + float dayTime; + float gamma; +}; + +void main() { + gl_Position = projView * vec4(pos[gl_VertexID], 1.0f); + + faceTextureUv = vec3(uv[gl_VertexID], layerAnimationAo.r); + faceTextureUv.y -= (uv[2].y - uv[0].y) * trunc(mod(globalTime * 4.0f, layerAnimationAo.g)); + + faceNormal = (view * vec4(normal, 0.0f)).xyz; + faceAddColor = color; + faceLight = light[gl_VertexID]; + faceAmbientOcclusion = layerAnimationAo.b; +} diff --git a/src/RendererSection.cpp b/src/RendererSection.cpp index 429a8bd..7ea74df 100644 --- a/src/RendererSection.cpp +++ b/src/RendererSection.cpp @@ -9,16 +9,26 @@ #include "RendererSectionData.hpp" -RendererSection::RendererSection(const RendererSectionData& data, std::shared_ptr pipeline, std::shared_ptr bufferBinding) { +RendererSection::RendererSection(const RendererSectionData& data, + std::shared_ptr solidPipeline, + std::shared_ptr solidBufferBinding, + std::shared_ptr liquidPipeline, + std::shared_ptr liquidBufferBinding) { OPTICK_EVENT(); auto gal = Gal::GetImplementation(); - buffer = gal->CreateBuffer(); - pipelineInstance = pipeline->CreateInstance({ - {bufferBinding, buffer} + solidBuffer = gal->CreateBuffer(); + solidPipelineInstance = solidPipeline->CreateInstance({ + {solidBufferBinding, solidBuffer} }); - pipelineInstance->SetInstancesCount(4); + solidPipelineInstance->SetInstancesCount(4); + + liquidBuffer = gal->CreateBuffer(); + liquidPipelineInstance = liquidPipeline->CreateInstance({ + {liquidBufferBinding, liquidBuffer} + }); + liquidPipelineInstance->SetInstancesCount(4); UpdateData(data); } @@ -32,18 +42,27 @@ RendererSection::~RendererSection() { } -void swap(RendererSection & lhs, RendererSection & rhs) { - std::swap(lhs.pipelineInstance, rhs.pipelineInstance); - std::swap(lhs.buffer, rhs.buffer); - std::swap(lhs.hash, rhs.hash); - std::swap(lhs.numOfFaces, rhs.numOfFaces); - std::swap(lhs.sectionPos, rhs.sectionPos); +void RendererSection::RenderSolid() { + OPTICK_EVENT(); + solidPipelineInstance->Activate(); + solidPipelineInstance->Render(0, solidFacesCount); } -void RendererSection::Render() { +void RendererSection::RenderLiquid() { OPTICK_EVENT(); - pipelineInstance->Activate(); - pipelineInstance->Render(0, numOfFaces); + liquidPipelineInstance->Activate(); + liquidPipelineInstance->Render(0, liquidFacesCount); +} + +void swap(RendererSection & lhs, RendererSection & rhs) { + std::swap(lhs.solidPipelineInstance, rhs.solidPipelineInstance); + std::swap(lhs.solidBuffer, rhs.solidBuffer); + std::swap(lhs.liquidPipelineInstance, rhs.liquidPipelineInstance); + std::swap(lhs.liquidBuffer, rhs.liquidBuffer); + std::swap(lhs.hash, rhs.hash); + std::swap(lhs.solidFacesCount, rhs.solidFacesCount); + std::swap(lhs.liquidFacesCount, rhs.liquidFacesCount); + std::swap(lhs.sectionPos, rhs.sectionPos); } Vector RendererSection::GetPosition() { @@ -57,9 +76,12 @@ size_t RendererSection::GetHash() { void RendererSection::UpdateData(const RendererSectionData & data) { OPTICK_EVENT(); - buffer->SetData({ reinterpret_cast(data.vertices.data()), reinterpret_cast(data.vertices.data() + data.vertices.size())}); + solidBuffer->SetData({ reinterpret_cast(data.solidVertices.data()), reinterpret_cast(data.solidVertices.data() + data.solidVertices.size())}); + solidFacesCount = data.solidVertices.size(); + + liquidBuffer->SetData({ reinterpret_cast(data.liquidVertices.data()), reinterpret_cast(data.liquidVertices.data() + data.liquidVertices.size()) }); + liquidFacesCount = data.liquidVertices.size(); - numOfFaces = data.vertices.size(); sectionPos = data.sectionPos; hash = data.hash; } diff --git a/src/RendererSection.hpp b/src/RendererSection.hpp index 0a03f44..8125e4e 100644 --- a/src/RendererSection.hpp +++ b/src/RendererSection.hpp @@ -7,26 +7,39 @@ class RenderState; class RendererSectionData; class RendererSection { - std::shared_ptr pipelineInstance; - std::shared_ptr buffer; - size_t hash; + std::shared_ptr solidPipelineInstance; + std::shared_ptr solidBuffer; + std::shared_ptr liquidPipelineInstance; + std::shared_ptr liquidBuffer; Vector sectionPos; + size_t hash = 0; + size_t solidFacesCount = 0; + size_t liquidFacesCount = 0; RendererSection(const RendererSection &other) = delete; public: - RendererSection(const RendererSectionData& data, std::shared_ptr pipeline, std::shared_ptr bufferBinding); + RendererSection( + const RendererSectionData& data, + std::shared_ptr solidPipeline, + std::shared_ptr solidBufferBinding, + std::shared_ptr liquidPipeline, + std::shared_ptr liquidBufferBinding); RendererSection(RendererSection &&other); ~RendererSection(); - void Render(); + void RenderSolid(); + + void RenderLiquid(); Vector GetPosition(); size_t GetHash(); - size_t numOfFaces; + inline size_t GetSolidFacesCount() { return solidFacesCount; } + + inline size_t GetLiquidFacesCount() { return liquidFacesCount; } friend void swap(RendererSection &lhs, RendererSection &rhs); diff --git a/src/RendererSectionData.cpp b/src/RendererSectionData.cpp index 255f40f..fdd961d 100644 --- a/src/RendererSectionData.cpp +++ b/src/RendererSectionData.cpp @@ -79,8 +79,8 @@ void AddFacesByBlockModel(RendererSectionData& data, const BlockFaces& model, co continue; } - data.vertices.emplace_back(); - VertexData& vertexData = data.vertices.back(); + data.solidVertices.emplace_back(); + VertexData& vertexData = data.solidVertices.back(); glm::mat4 transformed = transform * model.transform * face.transform; vertexData.positions[0] = transformed * glm::vec4(0, 0, 0, 1); @@ -161,7 +161,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (liquidFalling) { if (!neighborsLiquids[FaceDirection::down]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[2] = transform * glm::vec4(1, 0, 1, 1); @@ -170,7 +170,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::up]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 1, 0, 1); vertex.positions[1] = transform * glm::vec4(0, 1, 1, 1); vertex.positions[2] = transform * glm::vec4(1, 1, 1, 1); @@ -179,7 +179,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::north]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[2] = transform * glm::vec4(0, 1, 0, 1); @@ -188,7 +188,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::south]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 1, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 1, 1); vertex.positions[2] = transform * glm::vec4(1, 1, 1, 1); @@ -197,7 +197,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::west]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(0, 0, 1, 1); vertex.positions[2] = transform * glm::vec4(0, 1, 1, 1); @@ -206,7 +206,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::east]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(1, 0, 1, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[2] = transform * glm::vec4(1, 1, 0, 1); @@ -231,7 +231,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::down]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[2] = transform * glm::vec4(1, 0, 1, 1); @@ -267,7 +267,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI break; } - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * flowMat * nwCorner; vertex.positions[1] = transform * flowMat * swCorner; vertex.positions[2] = transform * flowMat * seCorner; @@ -292,7 +292,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::north]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[2] = transform * nwCorner; @@ -301,7 +301,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::south]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 1, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 1, 1); vertex.positions[2] = transform * seCorner; @@ -310,7 +310,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::west]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(0, 0, 0, 1); vertex.positions[1] = transform * glm::vec4(0, 0, 1, 1); vertex.positions[2] = transform * swCorner; @@ -319,7 +319,7 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI if (!neighborsLiquids[FaceDirection::east]) { addedFaces++; - VertexData& vertex = data.vertices.emplace_back(); + VertexData& vertex = data.liquidVertices.emplace_back(); vertex.positions[0] = transform * glm::vec4(1, 0, 1, 1); vertex.positions[1] = transform * glm::vec4(1, 0, 0, 1); vertex.positions[2] = transform * neCorner; @@ -334,8 +334,8 @@ void AddLiquidFacesByBlockModel(RendererSectionData& data, const BlockId& blockI glm::vec2 lightness; lightness.x = light.self; lightness.y = skyLight.self; - for (size_t i = data.vertices.size() - addedFaces; i < data.vertices.size(); i++) { - VertexData& vertex = data.vertices[i]; + for (size_t i = data.liquidVertices.size() - addedFaces; i < data.liquidVertices.size(); i++) { + VertexData& vertex = data.liquidVertices[i]; if (glm::length(vertex.normal) < 0.5f) { vertex.uvs[0] = TransformTextureCoord(flowData.texture, glm::vec2(0, 0), flowData.frames); @@ -462,7 +462,9 @@ RendererSectionData ParseSection(const SectionsData §ions, bool smoothLighti } } } - data.vertices.shrink_to_fit(); + + data.solidVertices.shrink_to_fit(); + data.liquidVertices.shrink_to_fit(); return data; } diff --git a/src/RendererSectionData.hpp b/src/RendererSectionData.hpp index 0f9ade6..ac69bff 100644 --- a/src/RendererSectionData.hpp +++ b/src/RendererSectionData.hpp @@ -68,7 +68,8 @@ struct VertexData { }; struct RendererSectionData { - std::vector vertices; + std::vector solidVertices; + std::vector liquidVertices; size_t hash = 0; Vector sectionPos; bool forced = false; diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index af177d7..26c1f69 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -189,7 +189,7 @@ RendererWorld::RendererWorld(std::shared_ptr target, bool deff } it->second.UpdateData(parsing[id].renderer); } else - sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(parsing[id].renderer, sectionsPipeline, sectionsBufferBinding))); + sections.emplace(std::make_pair(parsing[id].renderer.sectionPos, RendererSection(parsing[id].renderer, solidSectionsPipeline, solidSectionsBufferBinding, liquidSectionsPipeline, liquidSectionsBufferBinding))); parsing[id] = RendererWorld::SectionParsing(); }); @@ -267,7 +267,8 @@ RendererWorld::RendererWorld(std::shared_ptr target, bool deff RendererWorld::~RendererWorld() { size_t faces = 0; for (auto& it : sections) { - faces += it.second.numOfFaces; + faces += it.second.GetSolidFacesCount(); + faces += it.second.GetLiquidFacesCount(); } LOG(INFO) << "Total faces to render: " << faces; isRunning = false; @@ -342,7 +343,6 @@ void RendererWorld::Render(float screenRatio) { auto rawGlobalTime = (std::chrono::high_resolution_clock::now() - globalTimeStart); float globalTime = rawGlobalTime.count() / 1000000000.0f; globalSpb->Get()->globalTime = globalTime; - sectionsPipeline->Activate(); Frustum frustum(projView); renderList.clear(); @@ -362,14 +362,20 @@ void RendererWorld::Render(float screenRatio) { continue; } renderList.push_back(section.first); - renderedFaces += section.second.numOfFaces; + renderedFaces += section.second.GetSolidFacesCount(); + renderedFaces += section.second.GetLiquidFacesCount(); } glm::vec3 playerChunk(GetGameState()->GetPlayer()->pos / 16); std::sort(renderList.begin(), renderList.end(), [playerChunk](const Vector& lhs, const Vector& rhs) { return glm::distance2(lhs.glm(), playerChunk) < glm::distance2(rhs.glm(), playerChunk); }); + solidSectionsPipeline->Activate(); for (const auto& renderPos : renderList) { - sections.at(renderPos).Render(); + sections.at(renderPos).RenderSolid(); + } + liquidSectionsPipeline->Activate(); + for (const auto& renderPos : renderList) { + sections.at(renderPos).RenderLiquid(); } DebugInfo::culledSections = culledSections; DebugInfo::renderFaces = renderedFaces; @@ -418,14 +424,24 @@ void RendererWorld::Render(float screenRatio) { } void RendererWorld::PrepareRender(std::shared_ptr target, bool defferedShading) { - std::string sectionVertexSource, sectionPixelSource; + std::string solidSectionVertexSource, solidSectionPixelSource; { auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/face"); - sectionVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size()); + solidSectionVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size()); auto pixelAsset = defferedShading ? AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/face") : AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/fwd_face"); - sectionPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size()); + solidSectionPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size()); + } + + std::string liquidSectionVertexSource, liquidSectionPixelSource; + { + auto vertAsset = AssetManager::GetAssetByAssetName("/altcraft/shaders/vert/liquid_face"); + liquidSectionVertexSource = std::string((char*)vertAsset->data.data(), (char*)vertAsset->data.data() + vertAsset->data.size()); + + auto pixelAsset = defferedShading ? AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/liquid_face") : + AssetManager::GetAssetByAssetName("/altcraft/shaders/frag/fwd_liquid_face"); + liquidSectionPixelSource = std::string((char*)pixelAsset->data.data(), (char*)pixelAsset->data.data() + pixelAsset->data.size()); } std::string entitiesVertexSource, entitiesPixelSource; @@ -450,13 +466,13 @@ void RendererWorld::PrepareRender(std::shared_ptr target, bool auto gal = Gal::GetImplementation(); { - auto sectionsPLC = gal->CreatePipelineConfig(); - sectionsPLC->SetTarget(target); - sectionsPLC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas()); - sectionsPLC->SetVertexShader(gal->LoadVertexShader(sectionVertexSource)); - sectionsPLC->SetPixelShader(gal->LoadPixelShader(sectionPixelSource)); - sectionsPLC->SetPrimitive(Gal::Primitive::TriangleFan); - sectionsBufferBinding = sectionsPLC->BindVertexBuffer({ + auto solidSectionPLC = gal->CreatePipelineConfig(); + solidSectionPLC->SetTarget(target); + solidSectionPLC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas()); + solidSectionPLC->SetVertexShader(gal->LoadVertexShader(solidSectionVertexSource)); + solidSectionPLC->SetPixelShader(gal->LoadPixelShader(solidSectionPixelSource)); + solidSectionPLC->SetPrimitive(Gal::Primitive::TriangleFan); + solidSectionsBufferBinding = solidSectionPLC->BindVertexBuffer({ {"pos", Gal::Type::Vec3, 4, 1}, {"uv", Gal::Type::Vec2, 4, 1}, {"light", Gal::Type::Vec2, 4, 1}, @@ -464,9 +480,28 @@ void RendererWorld::PrepareRender(std::shared_ptr target, bool {"color", Gal::Type::Vec3, 1, 1}, {"layerAnimationAo", Gal::Type::Vec3, 1, 1}, }); - sectionsPipeline = gal->BuildPipeline(sectionsPLC); + solidSectionsPipeline = gal->BuildPipeline(solidSectionPLC); } - + + { + auto liquidSectionPLC = gal->CreatePipelineConfig(); + liquidSectionPLC->SetTarget(target); + liquidSectionPLC->AddStaticTexture("textureAtlas", AssetManager::GetTextureAtlas()); + liquidSectionPLC->SetVertexShader(gal->LoadVertexShader(liquidSectionVertexSource)); + liquidSectionPLC->SetPixelShader(gal->LoadPixelShader(liquidSectionPixelSource)); + liquidSectionPLC->SetPrimitive(Gal::Primitive::TriangleFan); + liquidSectionPLC->SetBlending(Gal::Blending::Additive); + liquidSectionsBufferBinding = liquidSectionPLC->BindVertexBuffer({ + {"pos", Gal::Type::Vec3, 4, 1}, + {"uv", Gal::Type::Vec2, 4, 1}, + {"light", Gal::Type::Vec2, 4, 1}, + {"normal", Gal::Type::Vec3, 1, 1}, + {"color", Gal::Type::Vec3, 1, 1}, + {"layerAnimationAo", Gal::Type::Vec3, 1, 1}, + }); + liquidSectionsPipeline = gal->BuildPipeline(liquidSectionPLC); + } + { auto entitiesPLC = gal->CreatePipelineConfig(); entitiesPLC->SetTarget(target); diff --git a/src/RendererWorld.hpp b/src/RendererWorld.hpp index 438c022..13d9739 100644 --- a/src/RendererWorld.hpp +++ b/src/RendererWorld.hpp @@ -43,8 +43,10 @@ class RendererWorld { std::map sections; void UpdateAllSections(VectorF playerPos); std::chrono::time_point globalTimeStart; - std::shared_ptr sectionsPipeline; - std::shared_ptr sectionsBufferBinding; + std::shared_ptr solidSectionsPipeline; + std::shared_ptr solidSectionsBufferBinding; + std::shared_ptr liquidSectionsPipeline; + std::shared_ptr liquidSectionsBufferBinding; //Entities std::vector entities; std::shared_ptr entitiesPipeline; -- cgit v1.2.3