Skip to content

Commit

Permalink
increase render distance
Browse files Browse the repository at this point in the history
make shader fade distance variables directly controlled by camera far plane
  • Loading branch information
fallahn committed Sep 10, 2024
1 parent 4e68f3a commit ab3a601
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 36 deletions.
5 changes: 2 additions & 3 deletions libsocial/include/Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ namespace Progress



//10 here being the maxnumber of leagues (or greater than)
//if the league count ever increases more than this, this
//will break...
//MaxMulligans here being the max number of leagues (or greater than)
//if the league count ever increases more than this, this will break...
std::array<std::int32_t, MaxMulligans> values = {};
std::fill(values.begin(), values.end(), 0);

Expand Down
3 changes: 2 additions & 1 deletion samples/golf/src/golf/ChunkVisSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ source distribution.

#include "ChunkVisSystem.hpp"
#include "TerrainBuilder.hpp"
#include "GameConsts.hpp"

#include <crogine/graphics/Spatial.hpp>
#include <crogine/ecs/Scene.hpp>
Expand All @@ -37,7 +38,7 @@ source distribution.

namespace
{
constexpr float MaxDist = 280.f;
constexpr float MaxDist = CameraFarPlane * 0.875f;// 280.f;
constexpr float CullDist = MaxDist * MaxDist;
}

Expand Down
2 changes: 1 addition & 1 deletion samples/golf/src/golf/GameConsts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static constexpr float GreenCamRadiusMedium = 10.f;
static constexpr float GreenCamRadiusSmall = 5.7f;
static constexpr float SkyCamRadius = 80.f;

static constexpr float CameraFarPlane = 320.f;
static constexpr float CameraFarPlane = 450.f;// 360.f;// 320.f;
static constexpr float GreenCamZoomFast = 2.5f;
static constexpr float GreenCamZoomSlow = 1.8f;
static constexpr float SkyCamZoomSpeed = 1.1f;// 3.f;
Expand Down
15 changes: 8 additions & 7 deletions samples/golf/src/golf/GolfStateAssets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,7 @@ void GolfState::loadMaterials()
{
wobble = "#define WOBBLE\n";
}
const std::string FadeDistance = "#define FAR_DISTANCE " + std::to_string(CameraFarPlane) + "\n";

//load materials
std::fill(m_materialIDs.begin(), m_materialIDs.end(), -1);
Expand Down Expand Up @@ -1548,7 +1549,7 @@ void GolfState::loadMaterials()
m_materialIDs[MaterialID::ShadowMap] = m_resources.materials.add(*shader);
m_resources.materials.get(m_materialIDs[MaterialID::ShadowMap]).setProperty("u_noiseTexture", noiseTex);

m_resources.shaders.loadFromString(ShaderID::BillboardShadow, BillboardVertexShader, ShadowFragment, "#define DITHERED\n#define SHADOW_MAPPING\n#define ALPHA_CLIP\n");
m_resources.shaders.loadFromString(ShaderID::BillboardShadow, BillboardVertexShader, ShadowFragment, "#define DITHERED\n#define SHADOW_MAPPING\n#define ALPHA_CLIP\n" + FadeDistance);
shader = &m_resources.shaders.get(ShaderID::BillboardShadow);
m_windBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
Expand Down Expand Up @@ -1659,11 +1660,11 @@ void GolfState::loadMaterials()

if (m_sharedData.nightTime)
{
m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader, "#define USE_MRT\n");;
m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader, "#define USE_MRT\n" + FadeDistance);
}
else
{
m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader);
m_resources.shaders.loadFromString(ShaderID::Billboard, BillboardVertexShader, BillboardFragmentShader, FadeDistance);
}
shader = &m_resources.shaders.get(ShaderID::Billboard);
m_scaleBuffer.addShader(*shader);
Expand Down Expand Up @@ -1709,20 +1710,20 @@ void GolfState::loadMaterials()
mrt = "#define USE_MRT\n";
}

m_resources.shaders.loadFromString(ShaderID::TreesetBranch, BranchVertex, BranchFragment, "#define ALPHA_CLIP\n#define INSTANCING\n" + wobble + mrt);
m_resources.shaders.loadFromString(ShaderID::TreesetBranch, BranchVertex, BranchFragment, "#define ALPHA_CLIP\n#define INSTANCING\n" + wobble + mrt + FadeDistance);
shader = &m_resources.shaders.get(ShaderID::TreesetBranch);
m_scaleBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
m_windBuffer.addShader(*shader);

m_resources.shaders.loadFromString(ShaderID::TreesetLeaf, BushVertex, /*BushGeom,*/ BushFragment, "#define POINTS\n#define INSTANCING\n#define HQ\n" + wobble + mrt);
m_resources.shaders.loadFromString(ShaderID::TreesetLeaf, BushVertex, /*BushGeom,*/ BushFragment, "#define POINTS\n#define INSTANCING\n#define HQ\n" + wobble + mrt + FadeDistance);
shader = &m_resources.shaders.get(ShaderID::TreesetLeaf);
m_scaleBuffer.addShader(*shader);
m_resolutionBuffer.addShader(*shader);
m_windBuffer.addShader(*shader);


m_resources.shaders.loadFromString(ShaderID::TreesetShadow, ShadowVertex, ShadowFragment, "#define INSTANCING\n#define TREE_WARP\n#define ALPHA_CLIP\n" + wobble);
m_resources.shaders.loadFromString(ShaderID::TreesetShadow, ShadowVertex, ShadowFragment, "#define INSTANCING\n#define TREE_WARP\n#define ALPHA_CLIP\n" + wobble + FadeDistance);
shader = &m_resources.shaders.get(ShaderID::TreesetShadow);
m_windBuffer.addShader(*shader);

Expand All @@ -1731,7 +1732,7 @@ void GolfState::loadMaterials()
{
alphaClip = "#define ALPHA_CLIP\n";
}
m_resources.shaders.loadFromString(ShaderID::TreesetLeafShadow, ShadowVertex, /*ShadowGeom,*/ ShadowFragment, "#define POINTS\n#define INSTANCING\n#define LEAF_SIZE\n" + alphaClip + wobble);
m_resources.shaders.loadFromString(ShaderID::TreesetLeafShadow, ShadowVertex, /*ShadowGeom,*/ ShadowFragment, "#define POINTS\n#define INSTANCING\n#define LEAF_SIZE\n" + alphaClip + wobble + FadeDistance);
shader = &m_resources.shaders.get(ShaderID::TreesetLeafShadow);
m_windBuffer.addShader(*shader);

Expand Down
14 changes: 7 additions & 7 deletions samples/golf/src/golf/GolfStateCameras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void GolfState::createCameras()

//fetch this explicitly so the transition cam also gets the correct zoom
float zoom = m_cameras[CameraID::Player].getComponent<CameraFollower::ZoomData>().fov;
cam.setPerspective(m_sharedData.fov * cro::Util::Const::degToRad * zoom, texSize.x / texSize.y, 0.1f, CameraFarPlane, m_shadowQuality.cascadeCount);
cam.setPerspective(m_sharedData.fov * cro::Util::Const::degToRad * zoom, texSize.x / texSize.y, 0.1f, CameraFarPlane /** 1.25f*/, m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};

Expand Down Expand Up @@ -228,7 +228,7 @@ void GolfState::createCameras()
{
auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective((m_sharedData.fov * cro::Util::Const::degToRad) * camEnt.getComponent<CameraFollower>().zoom.fov,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.35f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane /** 1.25f*/,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };

Expand Down Expand Up @@ -269,7 +269,7 @@ void GolfState::createCameras()
{
auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective((m_sharedData.fov * cro::Util::Const::degToRad) * camEnt.getComponent<CameraFollower::ZoomData>().fov,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.25f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane /** 1.25f*/,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };

Expand Down Expand Up @@ -307,7 +307,7 @@ void GolfState::createCameras()
{
auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective((m_sharedData.fov * cro::Util::Const::degToRad) * camEnt.getComponent<CameraFollower>().zoom.fov,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.25f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane/* * 1.25f*/,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};
Expand Down Expand Up @@ -339,7 +339,7 @@ void GolfState::createCameras()

auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective((m_sharedData.fov * cro::Util::Const::degToRad) * zoomFOV * 0.7f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.25f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 0.7f,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};
Expand Down Expand Up @@ -387,7 +387,7 @@ void GolfState::createCameras()

auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective((m_sharedData.fov * cro::Util::Const::degToRad) * zoomFOV * 0.7f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.25f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 0.7f,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};
Expand Down Expand Up @@ -452,7 +452,7 @@ void GolfState::createCameras()
{
auto vpSize = glm::vec2(cro::App::getWindow().getSize());
cam.setPerspective(m_sharedData.fov * camEnt.getComponent<FpsCamera>().fov * cro::Util::Const::degToRad,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane * 1.25f,
vpSize.x / vpSize.y, 0.1f, CameraFarPlane /** 1.25f*/,
m_shadowQuality.cascadeCount);
cam.viewport = { 0.f, 0.f, 1.f, 1.f };
};
Expand Down
12 changes: 8 additions & 4 deletions samples/golf/src/golf/shaders/BillboardShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ inline const std::string BillboardVertexShader = R"(
#include WIND_CALC
#include WATER_LEVEL
#if defined(FAR_DISTANCE)
const float FarFadeDistance = FAR_DISTANCE;
#else
const float FarFadeDistance = 300.0;
#endif
void main()
{
//red low freq, green high freq, blue direction amount
Expand Down Expand Up @@ -164,15 +170,13 @@ inline const std::string BillboardVertexShader = R"(
float fadeDistance = u_nearFadeDistance * 5.0;
const float farFadeDistance = 300.f;
float distance = length(position - u_cameraWorldPosition);
v_ditherAmount = pow(clamp((distance - u_nearFadeDistance) / fadeDistance, 0.0, 1.0), 5.0);
v_ditherAmount *= 1.0 - clamp((distance - farFadeDistance) / fadeDistance, 0.0, 1.0);
v_ditherAmount *= 1.0 - clamp((distance - FarFadeDistance) / fadeDistance, 0.0, 1.0);
#if !defined(SHADOW_MAPPING)
v_colour.rgb *= (((1.0 - pow(clamp(distance / farFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
v_colour.rgb *= (((1.0 - pow(clamp(distance / FarFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
#endif
vec4 worldPos = /*u_worldMatrix **/ vec4(position, 1.0);
gl_ClipDistance[0] = dot(worldPos, u_clipPlane);
Expand Down
10 changes: 7 additions & 3 deletions samples/golf/src/golf/shaders/CelShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,14 @@ inline const std::string CelVertexShader = R"(
#include WATER_LEVEL
#include WIND_CALC
#include VAT_VEC
#if defined(FAR_DISTANCE)
const float FarFadeDistance = FAR_DISTANCE;
#else
const float FarFadeDistance = 360.f;
#endif
void main()
{
#if defined (INSTANCING)
Expand Down Expand Up @@ -228,11 +233,10 @@ inline const std::string CelVertexShader = R"(
#if defined(DITHERED)
float fadeDistance = u_nearFadeDistance * 2.0;
const float farFadeDistance = 360.f;
float distance = length(worldPosition.xyz - u_cameraWorldPosition);
v_ditherAmount = pow(clamp((distance - u_nearFadeDistance) / fadeDistance, 0.0, 1.0), 2.0);
v_ditherAmount *= 1.0 - clamp((distance - farFadeDistance) / fadeDistance, 0.0, 1.0);
v_ditherAmount *= 1.0 - clamp((distance - FarFadeDistance) / fadeDistance, 0.0, 1.0);
#endif
#if defined(MULTI_TARGET)
Expand Down
8 changes: 6 additions & 2 deletions samples/golf/src/golf/shaders/ShadowMapping.inl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ inline const std::string ShadowVertex = R"(
#include WIND_CALC
#endif
#if defined(FAR_DISTANCE)
const float FarFadeDistance = FAR_DISTANCE;
#else
const float FarFadeDistance = 360.f;
#endif
void main()
{
Expand Down Expand Up @@ -266,13 +271,12 @@ worldPosition.z += windResult.lowFreq.y;
#if defined(DITHERED)
float fadeDistance = u_nearFadeDistance * 2.0;
const float farFadeDistance = 360.f;
vec4 p = worldMatrix * a_position;
float d = length(p.xyz - u_cameraWorldPosition);
v_ditherAmount = pow(clamp((d - u_nearFadeDistance) / fadeDistance, 0.0, 1.0), 2.0);
v_ditherAmount *= 1.0 - clamp((d - farFadeDistance) / fadeDistance, 0.0, 1.0);
v_ditherAmount *= 1.0 - clamp((d - FarFadeDistance) / fadeDistance, 0.0, 1.0);
#endif
Expand Down
30 changes: 22 additions & 8 deletions samples/golf/src/golf/shaders/TreeShader.inl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ R"(
#include WATER_LEVEL
#if defined(FAR_DISTANCE)
const float FarFadeDistance = FAR_DISTANCE;
#else
const float FarFadeDistance = 360.f;
#endif
void main()
{
//int UID = gl_InstanceID << 16 | (gl_VertexID & 0x0000ffff);
Expand Down Expand Up @@ -222,13 +228,14 @@ if(visibility > MinVisibility){
//proximity fade
float fadeDistance = u_nearFadeDistance * 5.0;//2.0; //I forget what this magic number was for. Lesson learned?
const float farFadeDistance = 360.f;
v_data.ditherAmount = pow(clamp((distance - u_nearFadeDistance) / fadeDistance, 0.0, 1.0), 2.0);
//fades far leaves before culling kicks in at 280m
v_data.ditherAmount *= 1.0 - clamp((distance - 255.0) / 25.0, 0.0, 1.0);
//fades far leaves before culling kicks in at 280m - culling is now controlled by CameraFarPlane as isFarFadeDistance
//v_data.ditherAmount *= 1.0 - clamp((distance - 255.0) / 25.0, 0.0, 1.0);
v_data.ditherAmount *= 1.0 - clamp((distance - FarFadeDistance) / fadeDistance, 0.0, 1.0);
v_data.darkenAmount = (((1.0 - pow(clamp(distance / farFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
v_data.darkenAmount = (((1.0 - pow(clamp(distance / FarFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
gl_ClipDistance[0] = dot(worldPosition, u_clipPlane);
Expand Down Expand Up @@ -426,6 +433,12 @@ inline const std::string BranchVertex = R"(
#include WIND_CALC
#include WATER_LEVEL
#if defined(FAR_DISTANCE)
const float FarFadeDistance = FAR_DISTANCE;
#else
const float FarFadeDistance = 360.f;
#endif
void main()
{
#if defined (INSTANCING)
Expand Down Expand Up @@ -478,14 +491,15 @@ inline const std::string BranchVertex = R"(
//proximity fade
float fadeDistance = u_nearFadeDistance * 5.0;//2.0;
const float farFadeDistance = 360.f;
float distance = length(worldPosition.xyz - u_cameraWorldPosition);
v_ditherAmount = pow(clamp((distance - u_nearFadeDistance) / fadeDistance, 0.0, 1.0), 2.0);
//fades far leaves before culling kicks in at 280m
v_ditherAmount *= 1.0 - clamp((distance - 255.0) / 25.0, 0.0, 1.0);
//fades far leaves before culling kicks in at 280m - culling and FarFadeDistance are all controlled by CameraFarPlane now.
//v_ditherAmount *= 1.0 - clamp((distance - 255.0) / 25.0, 0.0, 1.0);
v_ditherAmount *= 1.0 - clamp((distance - FarFadeDistance) / fadeDistance, 0.0, 1.0);
v_darkenAmount = (((1.0 - pow(clamp(distance / farFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
v_darkenAmount = (((1.0 - pow(clamp(distance / FarFadeDistance, 0.0, 1.0), 5.0)) * 0.8) + 0.2);
gl_ClipDistance[1] = dot(worldPosition, vec4(vec3(0.0, 1.0, 0.0), WaterLevel - 0.001));
})";
Expand Down

0 comments on commit ab3a601

Please sign in to comment.