diff --git a/Game.cpp b/Game.cpp index 0bda6a7..352cafe 100755 --- a/Game.cpp +++ b/Game.cpp @@ -631,26 +631,6 @@ namespace ZL } else if (event.type == SDL_KEYUP) { - if (event.key.keysym.sym == SDLK_a) - { - planetObject.x += 1; - } - if (event.key.keysym.sym == SDLK_s) - { - planetObject.x -= 1; - } - if (event.key.keysym.sym == SDLK_q) - { - - Environment::shipPosition = { 0, 0, 25000 }; - //Environment::shipPosition = { 50000, 50000, 50000 }; - - //planetObject.y += 1; - } - if (event.key.keysym.sym == SDLK_w) - { - planetObject.y -= 1; - } if (event.key.keysym.sym == SDLK_i) { Environment::shipVelocity += 500.f; @@ -667,40 +647,6 @@ namespace ZL { Environment::shipVelocity -= 50.f; } - - if (event.key.keysym.sym == SDLK_1) - { - planetObject.planetData.ZScale = 1000.f; - } - if (event.key.keysym.sym == SDLK_2) - { - planetObject.planetData.ZScale = 500.f; - } - if (event.key.keysym.sym == SDLK_3) - { - planetObject.planetData.ZScale = 250.f; - } - if (event.key.keysym.sym == SDLK_4) - { - planetObject.planetData.ZScale = 125.f; - } - if (event.key.keysym.sym == SDLK_5) - { - planetObject.planetData.ZScale = 65.f; - } - if (event.key.keysym.sym == SDLK_6) - { - planetObject.planetData.ZScale = 32.f; - } - if (event.key.keysym.sym == SDLK_7) - { - planetObject.planetData.ZScale = 16.f; - } - if (event.key.keysym.sym == SDLK_8) - { - planetObject.planetData.ZScale = 8.f; - } - } } render(); diff --git a/PlanetData.cpp b/PlanetData.cpp index cf0f34c..768f370 100644 --- a/PlanetData.cpp +++ b/PlanetData.cpp @@ -11,40 +11,6 @@ namespace ZL { // --- ( PlanetObject.cpp) --- - static constexpr float FAR_Z_NEAR = 2000.0f; - static constexpr float FAR_Z_FAR = 200000.0f; - - static constexpr float TRANSITION_FAR_START = 3000.0f; - static constexpr float MIDDLE_Z_NEAR = 300.f; - static constexpr float MIDDLE_Z_FAR = 100000.f; - - static constexpr float TRANSITION_MIDDLE_START = 500.f; - static constexpr float NEAR_Z_NEAR = 80.0f; - static constexpr float NEAR_Z_FAR = 20000.0f; - - static constexpr float TRANSITION_NEAR_END = 100.f; - - - //static constexpr float SUPER_NEAR_Z_NEAR = 5.0f; - //static constexpr float SUPER_NEAR_Z_FAR = 15000.f; - static constexpr float SUPER_NEAR_Z_NEAR = 100.0f; - static constexpr float SUPER_NEAR_Z_FAR = 10000.0f; - static constexpr float TRANSITION_SUPER_NEAR_END = 30.f; - - /* - static constexpr float FAR_Z_NEAR = 2000.0f; - static constexpr float FAR_Z_FAR = 200000.0f; - static constexpr float TRANSITION_FAR_START = 3000.0f; - static constexpr float MIDDLE_Z_NEAR = 300.f; - static constexpr float MIDDLE_Z_FAR = 100000.f; - static constexpr float TRANSITION_MIDDLE_START = 500.f; - static constexpr float NEAR_Z_NEAR = 80.0f; - static constexpr float NEAR_Z_FAR = 20000.0f; - static constexpr float TRANSITION_NEAR_END = 100.f; - static constexpr float SUPER_NEAR_Z_NEAR = 5.0f; - static constexpr float SUPER_NEAR_Z_FAR = 5000.0f; - static constexpr float TRANSITION_SUPER_NEAR_END = 30.f; - */ VertexID generateEdgeID(const VertexID& id1, const VertexID& id2) { return id1 < id2 ? id1 + "_" + id2 : id2 + "_" + id1; } @@ -83,6 +49,12 @@ namespace ZL { planetMeshLods[i].Move(PLANET_CENTER_OFFSET); } + for (int i = 0; i < planetMeshLodsNoDist.size(); i++) { + planetMeshLodsNoDist[i] = generateSphere(i, 0); + planetMeshLodsNoDist[i].Scale(PLANET_RADIUS); + planetMeshLodsNoDist[i].Move(PLANET_CENTER_OFFSET); + } + planetAtmosphereLod = generateSphere(5, 0); planetAtmosphereLod.Scale(PLANET_RADIUS * 1.03); planetAtmosphereLod.Move(PLANET_CENTER_OFFSET); @@ -92,6 +64,10 @@ namespace ZL { return planetMeshLods.at(level); } + const LodLevel& PlanetData::getLodLevelNoDist(int level) const { + return planetMeshLodsNoDist.at(level); + } + const LodLevel& PlanetData::getAtmosphereLod() const { return planetAtmosphereLod; } @@ -147,39 +123,6 @@ namespace ZL { currentZFar = 5000.f; } - - /* - if (dToPlanetSurface >= TRANSITION_FAR_START) { - currentZNear = FAR_Z_NEAR; - currentZFar = FAR_Z_FAR; - } - else if (dToPlanetSurface > TRANSITION_MIDDLE_START) { - const float transitionLength = TRANSITION_FAR_START - TRANSITION_MIDDLE_START; - float normalizedDist = (dToPlanetSurface - TRANSITION_MIDDLE_START) / transitionLength; - alpha = 1.0f - normalizedDist; - currentZNear = FAR_Z_NEAR * (1.0f - alpha) + MIDDLE_Z_NEAR * alpha; - currentZFar = FAR_Z_FAR * (1.0f - alpha) + MIDDLE_Z_FAR * alpha; - } - - else if (dToPlanetSurface > TRANSITION_NEAR_END) { - const float transitionLength = TRANSITION_MIDDLE_START - TRANSITION_NEAR_END; - float normalizedDist = (dToPlanetSurface - TRANSITION_NEAR_END) / transitionLength; - alpha = 1.0f - normalizedDist; - currentZNear = MIDDLE_Z_NEAR * (1.0f - alpha) + NEAR_Z_NEAR * alpha; - currentZFar = MIDDLE_Z_FAR * (1.0f - alpha) + NEAR_Z_FAR * alpha; - } - else if (dToPlanetSurface > TRANSITION_SUPER_NEAR_END) { - const float transitionLength = TRANSITION_NEAR_END - TRANSITION_SUPER_NEAR_END; - float normalizedDist = (dToPlanetSurface - TRANSITION_SUPER_NEAR_END) / transitionLength; - alpha = 1.0f - normalizedDist; - currentZNear = NEAR_Z_NEAR * (1.0f - alpha) + SUPER_NEAR_Z_NEAR * alpha; - currentZFar = NEAR_Z_FAR * (1.0f - alpha) + SUPER_NEAR_Z_FAR * alpha; - } - else { - currentZNear = SUPER_NEAR_Z_NEAR; - currentZFar = SUPER_NEAR_Z_FAR; - } - */ return { currentZNear, currentZFar }; } @@ -340,10 +283,6 @@ namespace ZL { return result; } - // ... subdivideTriangles, calculateSurfaceNormal, trianglesToVertices, generateSphere, findNeighbors - // PlanetObject.cpp " ", PlanetData:: . - // , perlin planetMeshLods this. - std::vector PlanetData::subdivideTriangles(const std::vector& input, float noiseCoeff) { std::vector output; @@ -379,43 +318,6 @@ namespace ZL { return output; } - Vector3f PlanetData::calculateSurfaceNormal(Vector3f p_sphere, float noiseCoeff) { - // p_sphere - ( ) - - float theta = 0.01f; // "" (epsilon) - - // , p_sphere. - // ( UP), Cross Product, . - // p_sphere UP, RIGHT. - Vector3f up = Vector3f(0.0f, 1.0f, 0.0f); - if (abs(p_sphere.dot(up)) > 0.99f) { - up = Vector3f(1.0f, 0.0f, 0.0f); - } - - Vector3f tangentX = (up.cross(p_sphere)).normalized(); - Vector3f tangentY = (p_sphere.cross(tangentX)).normalized(); - - // - Vector3f p0_dir = p_sphere; - Vector3f p1_dir = (p_sphere + tangentX * theta).normalized(); - Vector3f p2_dir = (p_sphere + tangentY * theta).normalized(); - - // - // p = dir * height(dir) - Vector3f p0 = p0_dir * perlin.getSurfaceHeight(p0_dir, noiseCoeff); - Vector3f p1 = p1_dir * perlin.getSurfaceHeight(p1_dir, noiseCoeff); - Vector3f p2 = p2_dir * perlin.getSurfaceHeight(p2_dir, noiseCoeff); - - // - Vector3f v1 = p1 - p0; - Vector3f v2 = p2 - p0; - - // - - // (v2, v1) (v1, v2) , - // , . - return (-v2.cross(v1)).normalized(); - } - LodLevel PlanetData::trianglesToVertices(const std::vector& geometry) { LodLevel result; result.triangles = geometry; @@ -492,16 +394,6 @@ namespace ZL { t.ids[i] = initialVertexMap[t.data[i].normalized()]; } } - - // 2. - // : , . - // , , - // 3. , . - // **:** , L>0 - // (m_ab = (a_noisy + b_noisy)*0.5). - // , , . - // , VertexID. - // 3. N ( subdivideTriangles ID ) for (int i = 0; i < subdivisions; i++) { geometry = subdivideTriangles(geometry, noiseCoeff); @@ -533,8 +425,6 @@ namespace ZL { for (size_t i = 0; i < lodLevel.vertexData.PositionData.size(); i++) { Vector3f dir = lodLevel.vertexData.PositionData[i].normalized(); lodLevel.vertexData.PositionData[i] = dir * perlin.getSurfaceHeight(dir, noiseCoeff); - // : NormalData (dir), - //lodLevel.vertexData.NormalData[i] = dir; } @@ -572,7 +462,6 @@ namespace ZL { }; Vector3f finalColor = baseColor + colorOffset; - // ... ( ) lodLevel.vertexData.ColorData.push_back(finalColor); } @@ -601,7 +490,4 @@ namespace ZL { } return std::vector(neighbors.begin(), neighbors.end()); } - - // ... ... - } \ No newline at end of file diff --git a/PlanetData.h b/PlanetData.h index 2bc52d0..6578eeb 100644 --- a/PlanetData.h +++ b/PlanetData.h @@ -68,13 +68,12 @@ namespace ZL { static const float PLANET_RADIUS; static const Vector3f PLANET_CENTER_OFFSET; - float ZScale = 1000.f; - private: PerlinNoise perlin; PerlinNoise colorPerlin; std::array planetMeshLods; + std::array planetMeshLodsNoDist; LodLevel planetAtmosphereLod; int currentLod; // @@ -83,7 +82,6 @@ namespace ZL { // std::vector subdivideTriangles(const std::vector& inputTriangles, float noiseCoeff); - Vector3f calculateSurfaceNormal(Vector3f p_sphere, float noiseCoeff); LodLevel trianglesToVertices(const std::vector& triangles); LodLevel generateSphere(int subdivisions, float noiseCoeff); @@ -98,6 +96,7 @@ namespace ZL { // ( ) const LodLevel& getLodLevel(int level) const; + const LodLevel& getLodLevelNoDist(int level) const; const LodLevel& getAtmosphereLod() const; int getCurrentLodIndex() const; int getMaxLodIndex() const; diff --git a/PlanetObject.cpp b/PlanetObject.cpp index ebc54df..1566ab9 100644 --- a/PlanetObject.cpp +++ b/PlanetObject.cpp @@ -34,12 +34,6 @@ namespace ZL { Vector3f y_axis = z_axis.cross(x_axis).normalized(); // 4. Формируем прямую матрицу поворота (Rotation/World Matrix). - // Векторы базиса записываются в СТОЛБЦЫ. - // В памяти Matrix3f m (std::array): - // m[0]=X.x, m[1]=Y.x, m[2]=Z.x - // m[3]=X.y, m[4]=Y.y, m[5]=Z.y - // m[6]=X.z, m[7]=Y.z, m[8]=Z.z - Matrix3f rot; // Столбец 0: Ось X @@ -73,17 +67,9 @@ namespace ZL { // Берем максимальный LOD для начальной отрисовки int lodIndex = planetData.getMaxLodIndex(); planetRenderStruct.data = planetData.getLodLevel(lodIndex).vertexData; - /*planetRenderStruct.data.PositionData[0] = planetRenderStruct.data.PositionData[6 * 3]; - planetRenderStruct.data.PositionData[0+1] = planetRenderStruct.data.PositionData[6 * 3+1]; - planetRenderStruct.data.PositionData[0+2] = planetRenderStruct.data.PositionData[6 * 3+2]; - */ - //planetRenderStruct.data.PositionData.resize(3); - /*planetRenderStruct.data.NormalData[0] = Vector3f{1.0,1.0,1.0}.normalized(); - planetRenderStruct.data.NormalData[1] = Vector3f{ 1.0,1.0,1.0 }.normalized(); - planetRenderStruct.data.NormalData[2] = Vector3f{ 1.0,1.0,1.0 }.normalized();*/ planetRenderStruct.RefreshVBO(); - planetRenderStructCut.data = planetData.getLodLevel(lodIndex).vertexData; + planetRenderStructCut.data = planetData.getLodLevelNoDist(lodIndex).vertexData; planetRenderStructCut.data.PositionData.resize(3); @@ -202,7 +188,7 @@ namespace ZL { - Triangle tr = planetData.getLodLevel(planetData.getCurrentLodIndex()).triangles[0]; + Triangle tr = planetData.getLodLevelNoDist(planetData.getCurrentLodIndex()).triangles[0]; // 1. Получаем матрицу вращения (оси в столбцах) Matrix3f mr = GetRotationForTriangle(tr); @@ -227,44 +213,38 @@ namespace ZL { float centerX = (minX + maxX) * 0.5f; float centerY = (minY + maxY) * 0.5f; - //float size = max(width, height); - //float hSize = size * 0.5f; + width = width * 0.995; + height = height * 0.995; renderer.PushProjectionMatrix( centerX - width*0.5, centerX + width * 0.5, centerY - height * 0.5, centerY + height * 0.5, - //currentZNear, currentZFar); 150, 200000); renderer.PushMatrix(); renderer.LoadIdentity(); - - // Сдвигаем камеру по Z renderer.TranslateMatrix(Vector3f{ 0, 0, -45000 }); // Применяем вращение renderer.RotateMatrix(mr); - + // Извлекаем нормаль треугольника (это 3-й столбец нашей матрицы вращения) Vector3f planeNormal = { mr.m[2], mr.m[5], mr.m[8] }; - //Vector3f planeNormal = { 0,0,1 }; - renderer.RenderUniform3fv("uPlanePoint", &tr.data[0].v[0]); renderer.RenderUniform3fv("uPlaneNormal", &planeNormal.v[0]); renderer.RenderUniform1f("uMaxHeight", StoneParams::BASE_SCALE * 1.1f); // Соответствует BASE_SCALE + perturbation - glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, sandTexture->getTexID()); - + renderer.PushMatrix(); + renderer.DrawVertexRenderStruct(planetRenderStructCut); - - //glClear(GL_DEPTH_BUFFER_BIT); - + renderer.PopMatrix(); + glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // Отсекаем задние грани if (planetStonesToBakeRenderStruct.data.PositionData.size() > 0) @@ -311,7 +291,7 @@ namespace ZL { //drawYellowZone(renderer); drawStones(renderer); - //drawAtmosphere(renderer); + drawAtmosphere(renderer); } void PlanetObject::drawPlanet(Renderer& renderer) @@ -322,8 +302,6 @@ namespace ZL { static const std::string vColorName = "vColor"; static const std::string vNormalName = "vNormal"; static const std::string vTexCoordName = "vTexCoord"; - static const std::string vTexCoord2Name = "vTexCoord2"; - //static const std::string vTexCoord3Name = "vTexCoord3"; static const std::string textureUniformName = "Texture"; renderer.shaderManager.PushShader(defaultShaderName); @@ -334,7 +312,6 @@ namespace ZL { renderer.EnableVertexAttribArray("vTangent"); renderer.EnableVertexAttribArray("vBinormal"); renderer.EnableVertexAttribArray(vTexCoordName); - //renderer.EnableVertexAttribArray(vTexCoord3Name); float dist = planetData.distanceToPlanetSurface(Environment::shipPosition); auto zRange = planetData.calculateZRange(dist); @@ -351,36 +328,12 @@ namespace ZL { renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom }); renderer.RotateMatrix(Environment::inverseShipMatrix); - //renderer.RotateMatrix(QuatToMatrix(QuatFromRotateAroundX(M_PI / 4.0))); - //renderer.RotateMatrix(QuatToMatrix(QuatFromRotateAroundY(-M_PI / 4.0))); - - //Environment::shipPosition.v[0] = -1130; - //Environment::shipPosition.v[1] = 9693; - //Environment::shipPosition.v[2] = -20500; - renderer.TranslateMatrix(-Environment::shipPosition); const Matrix4f viewMatrix = renderer.GetCurrentModelViewMatrix(); - /* - Vector3f lightDir_World = Vector3f(1.0f, 0.0f, -1.0f).normalized(); - // В OpenGL/шейдерах удобнее работать с вектором, указывающим ОТ источника к поверхности. - Vector3f lightDirection_World = -lightDir_World; // Вектор, направленный от источника - Vector3f lightDirection_View; - - lightDirection_View.v[0] = viewMatrix.m[0] * lightDirection_World.v[0] + viewMatrix.m[4] * lightDirection_World.v[1] + viewMatrix.m[8] * lightDirection_World.v[2]; - lightDirection_View.v[1] = viewMatrix.m[1] * lightDirection_World.v[0] + viewMatrix.m[5] * lightDirection_World.v[1] + viewMatrix.m[9] * lightDirection_World.v[2]; - lightDirection_View.v[2] = viewMatrix.m[2] * lightDirection_World.v[0] + viewMatrix.m[6] * lightDirection_World.v[1] + viewMatrix.m[10] * lightDirection_World.v[2]; - lightDirection_View = lightDirection_View.normalized(); // Нормализуем на всякий случай - - // Установка uniform-переменной - // Предполагается, что RenderUniform3fv определена в Renderer.h - renderer.RenderUniform3fv("uLightDirection", &lightDirection_View.v[0]); - renderer.RenderUniformMatrix4fv("ModelViewMatrix", false, &viewMatrix.m[0]); - - renderer.RenderUniform1f("uDistanceToPlanetSurface", dist); - renderer.RenderUniform1f("uCurrentZFar", currentZFar); - */ + renderer.RenderUniform1i("Texture", 0); + renderer.RenderUniform1i("BakedTexture", 1); Triangle tr = planetData.getLodLevel(planetData.getCurrentLodIndex()).triangles[0]; // Берем базовый треугольник @@ -389,29 +342,23 @@ namespace ZL { // Позиция камеры (корабля) в мире renderer.RenderUniform3fv("uViewPos", &Environment::shipPosition.v[0]); - // Передаем матрицу вращения треугольника для перехода в Tangent Space - renderer.RenderUniformMatrix3fv("uShipRotation", false, &Environment::inverseShipMatrix.m[0]); - renderer.RenderUniformMatrix4fv("ModelViewMatrix", false, &viewMatrix.m[0]); - - // Не забудьте масштаб эффекта (глубина камней) //renderer.RenderUniform1f("uHeightScale", 0.03f); - //renderer.RenderUniform1f("uHeightScale", -0.01f); - //renderer.RenderUniform1f("uHeightScale", 0.0f + x / 1000.f); renderer.RenderUniform1f("uHeightScale", 0.0f); - - renderer.RenderUniform1f("uDistanceToPlanetSurface", dist); renderer.RenderUniform1f("uCurrentZFar", currentZFar); + + + glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, stoneMapFB->getTextureID()); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, sandTexture->getTexID()); renderer.DrawVertexRenderStruct(planetRenderStruct); CheckGlError(); renderer.PopMatrix(); renderer.PopProjectionMatrix(); - //renderer.DisableVertexAttribArray(vTexCoord3Name); - //renderer.DisableVertexAttribArray(vTexCoord2Name); renderer.DisableVertexAttribArray(vTexCoordName); renderer.DisableVertexAttribArray(vNormalName); renderer.DisableVertexAttribArray("vTangent"); @@ -426,13 +373,11 @@ namespace ZL { void PlanetObject::drawStones(Renderer& renderer) { - //static const std::string defaultShaderName = "defaultColor"; static const std::string defaultShaderName2 = "planetStone"; static const std::string vPositionName = "vPosition"; static const std::string vColorName = "vColor"; static const std::string vNormalName = "vNormal"; static const std::string vTexCoordName = "vTexCoord"; - //static const std::string vTexCoord3Name = "vTexCoord3"; static const std::string textureUniformName = "Texture"; renderer.shaderManager.PushShader(defaultShaderName2); @@ -441,7 +386,6 @@ namespace ZL { renderer.EnableVertexAttribArray(vColorName); renderer.EnableVertexAttribArray(vNormalName); renderer.EnableVertexAttribArray(vTexCoordName); - //renderer.EnableVertexAttribArray(vTexCoord3Name); float dist = planetData.distanceToPlanetSurface(Environment::shipPosition); auto zRange = planetData.calculateZRange(dist); @@ -459,44 +403,27 @@ namespace ZL { renderer.RotateMatrix(Environment::inverseShipMatrix); renderer.TranslateMatrix(-Environment::shipPosition); - const Matrix4f viewMatrix = renderer.GetCurrentModelViewMatrix(); - - Vector3f lightDir_World = Vector3f(1.0f, 0.0f, -1.0f).normalized(); - // В OpenGL/шейдерах удобнее работать с вектором, указывающим ОТ источника к поверхности. - Vector3f lightDirection_World = -lightDir_World; // Вектор, направленный от источника - Vector3f lightDirection_View; - - lightDirection_View.v[0] = viewMatrix.m[0] * lightDirection_World.v[0] + viewMatrix.m[4] * lightDirection_World.v[1] + viewMatrix.m[8] * lightDirection_World.v[2]; - lightDirection_View.v[1] = viewMatrix.m[1] * lightDirection_World.v[0] + viewMatrix.m[5] * lightDirection_World.v[1] + viewMatrix.m[9] * lightDirection_World.v[2]; - lightDirection_View.v[2] = viewMatrix.m[2] * lightDirection_World.v[0] + viewMatrix.m[6] * lightDirection_World.v[1] + viewMatrix.m[10] * lightDirection_World.v[2]; - lightDirection_View = lightDirection_View.normalized(); // Нормализуем на всякий случай - - // Установка uniform-переменной - // Предполагается, что RenderUniform3fv определена в Renderer.h - renderer.RenderUniform3fv("uLightDirection", &lightDirection_View.v[0]); - renderer.RenderUniformMatrix4fv("ModelViewMatrix", false, &viewMatrix.m[0]); - + renderer.RenderUniform1f("uDistanceToPlanetSurface", dist); renderer.RenderUniform1f("uCurrentZFar", currentZFar); - Vector3f color2 = { 1.0, 1.0, 1.0 }; - - renderer.RenderUniform3fv("uColor", &color2.v[0]); - renderer.RenderUniform3fv("uViewPos", &Environment::shipPosition.v[0]); glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); // Отсекаем задние грани + glCullFace(GL_BACK); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (planetStonesRenderStruct.data.PositionData.size() > 0) { glBindTexture(GL_TEXTURE_2D, stoneTexture->getTexID()); renderer.DrawVertexRenderStruct(planetStonesRenderStruct); CheckGlError(); } + glDisable(GL_BLEND); glDisable(GL_CULL_FACE); renderer.PopMatrix(); renderer.PopProjectionMatrix(); - //renderer.DisableVertexAttribArray(vTexCoord3Name); renderer.DisableVertexAttribArray(vTexCoordName); renderer.DisableVertexAttribArray(vNormalName); renderer.DisableVertexAttribArray(vColorName); diff --git a/PlanetObject.h b/PlanetObject.h index 3ca9d9c..c45875f 100644 --- a/PlanetObject.h +++ b/PlanetObject.h @@ -47,9 +47,6 @@ namespace ZL { public: PlanetObject(); - int x = 0; - int y = 0; - void init(); void update(float deltaTimeMs); void bakeStoneTexture(Renderer& renderer); diff --git a/Renderer.cpp b/Renderer.cpp index 0b335d8..1bfc118 100755 --- a/Renderer.cpp +++ b/Renderer.cpp @@ -294,31 +294,6 @@ namespace ZL { glBufferData(GL_ARRAY_BUFFER, data.TexCoordData.size() * 8, &data.TexCoordData[0], GL_STATIC_DRAW); } - /*if (data.TexCoord2Data.size() > 0) - { - if (!texCoord2VBO) - { - texCoord2VBO = std::make_shared(); - } - - glBindBuffer(GL_ARRAY_BUFFER, texCoord2VBO->getBuffer()); - - glBufferData(GL_ARRAY_BUFFER, data.TexCoord2Data.size() * 8, &data.TexCoord2Data[0], GL_STATIC_DRAW); - }*/ - - if (data.TexCoord3Data.size() > 0) - { - if (!texCoord3VBO) - { - texCoord3VBO = std::make_shared(); - } - - glBindBuffer(GL_ARRAY_BUFFER, texCoord3VBO->getBuffer()); - - glBufferData(GL_ARRAY_BUFFER, data.TexCoord3Data.size() * 12, &data.TexCoord3Data[0], GL_STATIC_DRAW); - } - - if (data.NormalData.size() > 0) { if (!normalVBO) @@ -800,8 +775,6 @@ namespace ZL { static const std::string vBinormal("vBinormal"); static const std::string vColor("vColor"); static const std::string vTexCoord("vTexCoord"); - //static const std::string vTexCoord2("vTexCoord2"); - static const std::string vTexCoord3("vTexCoord3"); static const std::string vPosition("vPosition"); //glBindVertexArray(VertexRenderStruct.vao->getBuffer()); @@ -832,11 +805,6 @@ namespace ZL { glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.texCoordVBO->getBuffer()); VertexAttribPointer2fv(vTexCoord, 0, NULL); } - if (VertexRenderStruct.data.TexCoord3Data.size() > 0) - { - glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.texCoord3VBO->getBuffer()); - VertexAttribPointer3fv(vTexCoord3, 0, NULL); - } glBindBuffer(GL_ARRAY_BUFFER, VertexRenderStruct.positionVBO->getBuffer()); VertexAttribPointer3fv(vPosition, 0, NULL); diff --git a/Renderer.h b/Renderer.h index 2ea2ac4..08a0582 100755 --- a/Renderer.h +++ b/Renderer.h @@ -44,8 +44,6 @@ namespace ZL { { std::vector PositionData; std::vector TexCoordData; - //std::vector TexCoord2Data; - std::vector TexCoord3Data; std::vector NormalData; std::vector TangentData; std::vector BinormalData; @@ -65,8 +63,6 @@ namespace ZL { std::shared_ptr vao; std::shared_ptr positionVBO; std::shared_ptr texCoordVBO; - //std::shared_ptr texCoord2VBO; - std::shared_ptr texCoord3VBO; std::shared_ptr normalVBO; std::shared_ptr tangentVBO; std::shared_ptr binormalVBO; diff --git a/shaders/planet_land.vertex b/shaders/planet_land.vertex index 15caf5e..9715a1f 100644 --- a/shaders/planet_land.vertex +++ b/shaders/planet_land.vertex @@ -6,7 +6,6 @@ attribute vec3 vBinormal; varying vec2 TexCoord; varying vec3 vViewDirTangent; -//varying float realDist; varying vec3 worldPosition; uniform mat4 ProjectionModelViewMatrix; diff --git a/shaders/planet_land_desktop.fragment b/shaders/planet_land_desktop.fragment index a876f81..117e5bd 100644 --- a/shaders/planet_land_desktop.fragment +++ b/shaders/planet_land_desktop.fragment @@ -2,10 +2,10 @@ varying vec2 TexCoord; varying vec3 vViewDirTangent; uniform sampler2D Texture; +uniform sampler2D BakedTexture; uniform float uHeightScale; uniform float uDistanceToPlanetSurface; uniform float uCurrentZFar; -//varying float realDist; varying vec3 worldPosition; uniform vec3 uViewPos; @@ -25,8 +25,14 @@ void main() { vec2 finalTexCoord = TexCoord + p; float realDist = distance(worldPosition, uViewPos); + + + float textureMixFactor = clamp((2000 - realDist) / 500.0, 0.0, 1.0); + + vec4 bakedTextureColor = texture2D(BakedTexture, finalTexCoord); + vec4 textureColor = texture2D(Texture, TexCoord); - vec4 finalColor = texture2D(Texture, finalTexCoord); + vec4 finalColor = textureMixFactor*textureColor + (1 - textureMixFactor) * bakedTextureColor; float fogFactor; if (uDistanceToPlanetSurface > 1000) @@ -61,30 +67,4 @@ void main() { gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, fogFactor); } - -/* - if (realDist < 500) - { - gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0); - } - else if (realDist < 1000) - { - gl_FragColor = vec4(1.0, 0.2, 0.0, 1.0); - } - else if (realDist < 1800) - { - gl_FragColor = vec4(1.0, 0.7, 0.0, 1.0); - } - else if (realDist < 2400) - { - gl_FragColor = vec4(1.0, 0.7, 0.5, 1.0); - } - else if (realDist < 2700) - { - gl_FragColor = vec4(1.0, 0.7, 1.0, 1.0); - } - else - { - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - }*/ } diff --git a/shaders/planet_stone_desktop.fragment b/shaders/planet_stone_desktop.fragment index 450fb51..4c3db9b 100644 --- a/shaders/planet_stone_desktop.fragment +++ b/shaders/planet_stone_desktop.fragment @@ -5,11 +5,8 @@ varying float viewZ; varying vec3 pos; uniform sampler2D Texture; -uniform float uDistanceToPlanetSurface; -uniform float uCurrentZFar; +uniform float uDistanceToPlanetSurface; -// Константы для тумана: -//const vec4 FOG_COLOR = vec4(0.0, 0.3, 0.3, 1.0); // Синий туман const vec4 FOG_COLOR = vec4(0.0, 0.5, 1.0, 1.0); // Синий туман varying vec3 worldPosition; @@ -23,6 +20,8 @@ void main() vec3 finalColor = textureColor.rgb; float realDist = distance(worldPosition, uViewPos); + + float alphaFactor = clamp((2000 - realDist) / 500.0, 0.0, 1.0); float fogFactor; if (uDistanceToPlanetSurface > 1000) @@ -35,7 +34,7 @@ void main() fogFactor = clamp((realDist - 2400) / (300.0*(1 + 10*t)), 0.0, 1.0); - gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, fogFactor*(1.0 - t)); + gl_FragColor = mix(vec4(finalColor.rgb, alphaFactor), FOG_COLOR, fogFactor*(1.0 - t)); } else if (uDistanceToPlanetSurface > 40) { @@ -48,13 +47,13 @@ void main() float fogFactor2 = clamp((realDist - 1000) / 800.0, 0.0, 1.0); - gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, max(fogFactor, fogFactor2*(1.0 - t))); + gl_FragColor = mix(vec4(finalColor.rgb, alphaFactor), FOG_COLOR, max(fogFactor, fogFactor2*(1.0 - t))); } else { fogFactor = clamp((realDist - 1000) / (800.0), 0.0, 1.0); - gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, fogFactor); + gl_FragColor = mix(vec4(finalColor.rgb, alphaFactor), FOG_COLOR, fogFactor); } } \ No newline at end of file