Skip to content
Permalink
Browse files

add /{Min,Max}ViewRange commands; include PR #471 for testing

let gl.GetViewRange return the global {min,max}ViewRange values
  • Loading branch information...
rtri
rtri committed Aug 18, 2019
1 parent 92144aa commit 18f2c2241ae2cd00f638ddfeea23f7cc55f54499
@@ -5,6 +5,7 @@
#include "Camera.h"
#include "CameraHandler.h"
#include "UI/MouseHandler.h"
#include "Map/Ground.h"
#include "Map/ReadMap.h"
#include "Rendering/GL/myGL.h"
#include "Rendering/GlobalRendering.h"
@@ -35,7 +36,7 @@ CCamera::CCamera(unsigned int cameraType, unsigned int projectionType)
memset(movState, 0, sizeof(movState));
memset(rotState, 0, sizeof(rotState));

frustum.scales.z = CGlobalRendering::NEAR_PLANE;
frustum.scales.z = CGlobalRendering::MIN_ZNEAR_DIST;
frustum.scales.w = CGlobalRendering::MAX_VIEW_RANGE;

SetVFOV(45.0f);
@@ -248,25 +249,47 @@ void CCamera::LoadViewPort() const

void CCamera::UpdateViewRange()
{
const float maxDistToBorderX = std::max(pos.x, float3::maxxpos - pos.x);
const float maxDistToBorderZ = std::max(pos.z, float3::maxzpos - pos.z);
const float maxDistToBorder = math::sqrt(Square(maxDistToBorderX) + Square(maxDistToBorderZ));
#if 0
// horizon-probe direction
const float3 hpPixelDir = (forward * XZVector + UpVector * -0.01f).Normalize();

const float3 tlPixelDir = CalcPixelDir( 0, 0);
const float3 trPixelDir = CalcPixelDir(globalRendering->viewSizeX, 0);
const float3 brPixelDir = CalcPixelDir(globalRendering->viewSizeX, globalRendering->viewSizeY);
const float3 blPixelDir = CalcPixelDir( 0, globalRendering->viewSizeY);
#endif

const float angleViewRange = (1.0f - forward.dot(UpVector)) * maxDistToBorder;
const float heightViewRange = (pos.y - std::max(0.0f, readMap->GetCurrMinHeight())) * 2.4f;
constexpr float SQ_MAX_VIEW_RANGE = Square(CGlobalRendering::MAX_VIEW_RANGE);
constexpr float ZFAR_ZNEAR_FACTOR = 0.001f;

float wantedViewRange = CGlobalRendering::MAX_VIEW_RANGE;
const float maxEdgeDistX = std::max(pos.x, float3::maxxpos - pos.x);
const float maxEdgeDistZ = std::max(pos.z, float3::maxzpos - pos.z);
const float maxEdgeDist = math::sqrt(Square(maxEdgeDistX) + Square(maxEdgeDistZ));
const float mapMinHeight = readMap->GetCurrMinHeight();

// camera-height dependent (i.e. TAB-view)
wantedViewRange = std::max(wantedViewRange, heightViewRange);
// view-angle dependent (i.e. FPS-view)
wantedViewRange = std::max(wantedViewRange, angleViewRange);
float wantedViewRange = 0.0f;

// NOTE: factor is always >= 1, not what we want when near ground
const float factor = wantedViewRange / CGlobalRendering::MAX_VIEW_RANGE;
#if 0
// only pick horizon probe-dir if between bottom and top planes
if (hpPixelDir.y >= (blPixelDir.y + brPixelDir.y) * 0.5f && hpPixelDir.y <= (tlPixelDir.y + trPixelDir.y) * 0.5f)
wantedViewRange = CGround::LinePlaneCol(pos, hpPixelDir, SQ_MAX_VIEW_RANGE, mapMinHeight);
#endif

// camera-height dependence (i.e. TAB-view)
wantedViewRange = std::max(wantedViewRange, (pos.y - std::max(0.0f, mapMinHeight)) * 2.0f);
// view-angle dependence (i.e. FPS-view)
wantedViewRange = std::max(wantedViewRange, (1.0f - std::max(0.0f, forward.dot(UpVector))) * maxEdgeDist);

#if 0
wantedViewRange = std::max(wantedViewRange, CGround::LinePlaneCol(pos, tlPixelDir, SQ_MAX_VIEW_RANGE, mapMinHeight));
wantedViewRange = std::max(wantedViewRange, CGround::LinePlaneCol(pos, trPixelDir, SQ_MAX_VIEW_RANGE, mapMinHeight));
wantedViewRange = std::max(wantedViewRange, CGround::LinePlaneCol(pos, brPixelDir, SQ_MAX_VIEW_RANGE, mapMinHeight));
wantedViewRange = std::max(wantedViewRange, CGround::LinePlaneCol(pos, blPixelDir, SQ_MAX_VIEW_RANGE, mapMinHeight));
wantedViewRange = Clamp(wantedViewRange, CGlobalRendering::MIN_ZNEAR_DIST, CGlobalRendering::MAX_VIEW_RANGE);
#endif

frustum.scales.z = CGlobalRendering::NEAR_PLANE * factor;
frustum.scales.w = CGlobalRendering::MAX_VIEW_RANGE * factor;
frustum.scales.z = std::max(wantedViewRange * ZFAR_ZNEAR_FACTOR, globalRendering->minViewRange);
frustum.scales.w = std::min(wantedViewRange , globalRendering->maxViewRange);
}


@@ -2533,6 +2533,44 @@ class MaxNanoParticlesActionExecutor : public IUnsyncedActionExecutor {



class MinViewRangeActionExecutor : public IUnsyncedActionExecutor {
public:
MinViewRangeActionExecutor() : IUnsyncedActionExecutor("MinViewRange", "Set minimum view-distance") {
}

bool Execute(const UnsyncedAction& action) const final {
const std::string& args = action.GetArgs();

if (args.empty())
return false;

globalRendering->minViewRange = std::fabs(atof(args.c_str()));
globalRendering->minViewRange = std::max(globalRendering->minViewRange, CGlobalRendering::MIN_ZNEAR_DIST);
globalRendering->minViewRange = std::min(globalRendering->minViewRange, globalRendering->maxViewRange);
return true;
}
};

class MaxViewRangeActionExecutor : public IUnsyncedActionExecutor {
public:
MaxViewRangeActionExecutor() : IUnsyncedActionExecutor("MaxViewRange", "Set maximum view-distance") {
}

bool Execute(const UnsyncedAction& action) const final {
const std::string& args = action.GetArgs();

if (args.empty())
return false;

globalRendering->maxViewRange = std::fabs(atof(args.c_str()));
globalRendering->maxViewRange = std::min(globalRendering->maxViewRange, CGlobalRendering::MAX_VIEW_RANGE);
globalRendering->maxViewRange = std::max(globalRendering->maxViewRange, globalRendering->minViewRange);
return true;
}
};



class GatherModeActionExecutor : public IUnsyncedActionExecutor {
public:
GatherModeActionExecutor() : IUnsyncedActionExecutor("GatherMode", "Enter/Leave gather-wait command mode") {
@@ -3375,6 +3413,8 @@ void UnsyncedGameCommands::AddDefaultActionExecutors()
AddActionExecutor(AllocActionExecutor<DistSortProjectilesActionExecutor>());
AddActionExecutor(AllocActionExecutor<MaxParticlesActionExecutor>());
AddActionExecutor(AllocActionExecutor<MaxNanoParticlesActionExecutor>());
AddActionExecutor(AllocActionExecutor<MinViewRangeActionExecutor>());
AddActionExecutor(AllocActionExecutor<MaxViewRangeActionExecutor>());

AddActionExecutor(AllocActionExecutor<GatherModeActionExecutor>());
AddActionExecutor(AllocActionExecutor<PasteTextActionExecutor>());
@@ -1115,7 +1115,9 @@ int LuaOpenGL::GetViewRange(lua_State* L)

lua_pushnumber(L, cam->GetNearPlaneDist());
lua_pushnumber(L, cam->GetFarPlaneDist());
return 2;
lua_pushnumber(L, globalRendering->minViewRange);
lua_pushnumber(L, globalRendering->maxViewRange);
return 4;
}


@@ -520,11 +520,17 @@ CBumpWater::CBumpWater()


// CREATE DISPLAYLIST
displayList = glGenLists(1);
CVertexArray* va = GetVertexArray();
va->Initialize();
va->CheckInitSize(4 * 33 * 2); // endless
glNewList(displayList, GL_COMPILE);

glNewList(displayList = glGenLists(1), GL_COMPILE);

#if 1
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.0f, 2.0f);
#endif

if (endlessOcean) {
DrawRadialDisc(va);
} else {
@@ -539,8 +545,13 @@ CBumpWater::CBumpWater()
}
va->DrawArray0(GL_TRIANGLE_STRIP);
}

#if 1
glDisable(GL_POLYGON_OFFSET_FILL);
#endif
glEndList();


/*
windndir = envResHandler.GetCurrentWindDir();
windStrength = (smoothstep(0.0f, 12.0f, envResHandler.GetCurrentWindStrength()) * 0.5f + 4.0f);
@@ -1110,6 +1121,7 @@ void CBumpWater::Draw()
SetUniforms();

glMultiTexCoord2f(GL_TEXTURE1, windVec.x, windVec.z);

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE * wireFrameMode + GL_FILL * (1 - wireFrameMode));
glCallList(displayList);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
@@ -1220,7 +1232,7 @@ void CBumpWater::OcclusionQuery()
glEnable(GL_DEPTH_TEST);

glPushMatrix();
glTranslatef(0.0, 10.0, 0.0);
glTranslatef(0.0f, 10.0f, 0.0f);
glBeginQuery(GL_ANY_SAMPLES_PASSED, occlusionQuery);
glCallList(displayList);
glEndQuery(GL_ANY_SAMPLES_PASSED);
@@ -106,6 +106,9 @@ CR_REG_METADATA(CGlobalRendering, (
CR_IGNORED(viewSizeY),
CR_IGNORED(pixelX),
CR_IGNORED(pixelY),

CR_IGNORED(minViewRange),
CR_IGNORED(maxViewRange),
CR_IGNORED(aspectRatio),

CR_IGNORED(forceDisableShaders),
@@ -184,6 +187,9 @@ CGlobalRendering::CGlobalRendering()
, pixelX(0.01f)
, pixelY(0.01f)

// sane defaults
, minViewRange(MIN_ZNEAR_DIST * 8.0f)
, maxViewRange(MAX_VIEW_RANGE * 0.25f)
, aspectRatio(1.0f)

, forceDisableShaders(configHandler->GetInt("ForceDisableShaders"))
@@ -1067,7 +1073,7 @@ void CGlobalRendering::InitGLState()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(viewPosX, viewPosY, viewSizeX, viewSizeY);
gluPerspective(45.0f, aspectRatio, 2.8f, MAX_VIEW_RANGE);
gluPerspective(45.0f, aspectRatio, minViewRange, maxViewRange);

// this does not accomplish much
// SwapBuffers(true, true);
@@ -133,6 +133,8 @@ class CGlobalRendering {
float pixelX;
float pixelY;

float minViewRange;
float maxViewRange;
/**
* @brief aspect ratio
*
@@ -292,12 +294,12 @@ class CGlobalRendering {
/**
* @brief max view range in elmos
*/
static constexpr float MAX_VIEW_RANGE = 8000.0f;
static constexpr float MAX_VIEW_RANGE = 65536.0f;

/**
* @brief near z-plane distance in elmos
*/
static constexpr float NEAR_PLANE = 2.8f;
static constexpr float MIN_ZNEAR_DIST = 0.5f;


/// magic constant to reduce overblending on SMF maps
@@ -1,15 +1,12 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include <cstring> // memcpy
#include <sstream>

#include <array>
#include <cstring> // memcpy

#include "ColorMap.h"
#include "Bitmap.h"
#include "System/Log/ILog.h"
#include "System/Exceptions.h"
#include "System/StringHash.h"
#include "System/StringUtil.h"
#include "System/UnorderedMap.hpp"
#include "System/creg/STL_Map.h"

0 comments on commit 18f2c22

Please sign in to comment.
You can’t perform that action at this time.