diff --git a/libsocial/include/Input.hpp b/libsocial/include/Input.hpp index 3d86508c1..f30b619e6 100644 --- a/libsocial/include/Input.hpp +++ b/libsocial/include/Input.hpp @@ -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 values = {}; std::fill(values.begin(), values.end(), 0); diff --git a/samples/golf/src/golf/ChunkVisSystem.cpp b/samples/golf/src/golf/ChunkVisSystem.cpp index 4aa6b86be..54713d0a7 100644 --- a/samples/golf/src/golf/ChunkVisSystem.cpp +++ b/samples/golf/src/golf/ChunkVisSystem.cpp @@ -29,6 +29,7 @@ source distribution. #include "ChunkVisSystem.hpp" #include "TerrainBuilder.hpp" +#include "GameConsts.hpp" #include #include @@ -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; } diff --git a/samples/golf/src/golf/GameConsts.hpp b/samples/golf/src/golf/GameConsts.hpp index 7e760563d..3d436bff5 100644 --- a/samples/golf/src/golf/GameConsts.hpp +++ b/samples/golf/src/golf/GameConsts.hpp @@ -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; diff --git a/samples/golf/src/golf/GolfStateAssets.cpp b/samples/golf/src/golf/GolfStateAssets.cpp index 75f0b9669..ccbf9ea59 100644 --- a/samples/golf/src/golf/GolfStateAssets.cpp +++ b/samples/golf/src/golf/GolfStateAssets.cpp @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/samples/golf/src/golf/GolfStateCameras.cpp b/samples/golf/src/golf/GolfStateCameras.cpp index e61a8df9d..c4b2e06f6 100644 --- a/samples/golf/src/golf/GolfStateCameras.cpp +++ b/samples/golf/src/golf/GolfStateCameras.cpp @@ -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().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 }; }; @@ -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().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 }; @@ -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().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 }; @@ -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().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 }; }; @@ -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 }; }; @@ -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 }; }; @@ -452,7 +452,7 @@ void GolfState::createCameras() { auto vpSize = glm::vec2(cro::App::getWindow().getSize()); cam.setPerspective(m_sharedData.fov * camEnt.getComponent().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 }; }; diff --git a/samples/golf/src/golf/shaders/BillboardShader.inl b/samples/golf/src/golf/shaders/BillboardShader.inl index bdecf38e0..c742c3cc2 100644 --- a/samples/golf/src/golf/shaders/BillboardShader.inl +++ b/samples/golf/src/golf/shaders/BillboardShader.inl @@ -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 @@ -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); diff --git a/samples/golf/src/golf/shaders/CelShader.inl b/samples/golf/src/golf/shaders/CelShader.inl index c265fa59f..ab3cffd50 100644 --- a/samples/golf/src/golf/shaders/CelShader.inl +++ b/samples/golf/src/golf/shaders/CelShader.inl @@ -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) @@ -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) diff --git a/samples/golf/src/golf/shaders/ShadowMapping.inl b/samples/golf/src/golf/shaders/ShadowMapping.inl index 0366cadf1..87743825b 100644 --- a/samples/golf/src/golf/shaders/ShadowMapping.inl +++ b/samples/golf/src/golf/shaders/ShadowMapping.inl @@ -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() { @@ -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 diff --git a/samples/golf/src/golf/shaders/TreeShader.inl b/samples/golf/src/golf/shaders/TreeShader.inl index c73ff956c..86972c377 100644 --- a/samples/golf/src/golf/shaders/TreeShader.inl +++ b/samples/golf/src/golf/shaders/TreeShader.inl @@ -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); @@ -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); @@ -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) @@ -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)); })";