diff --git a/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli b/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli index 550b0d322..8d0e9f44d 100644 --- a/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli +++ b/features/Grass Collision/Shaders/GrassCollision/GrassCollision.hlsli @@ -1,7 +1,7 @@ cbuffer GrassCollisionPerFrame : register(b5) { - float3 boundCentre; + float4 boundCentre[2]; float boundRadius; bool EnableGrassCollision; float RadiusMultiplier; @@ -10,7 +10,7 @@ cbuffer GrassCollisionPerFrame : register(b5) struct StructuredCollision { - float3 centre; + float3 centre[2]; float radius; }; @@ -23,7 +23,7 @@ float3 GetDisplacedPosition(float3 position, float alpha, uint eyeIndex = 0) // Player bound culling { - float dist = distance(boundCentre, worldPosition); + float dist = distance(boundCentre[eyeIndex].xyz, worldPosition); if (dist > boundRadius) { return 0; } @@ -36,9 +36,9 @@ float3 GetDisplacedPosition(float3 position, float alpha, uint eyeIndex = 0) for (uint collision_index = 0; collision_index < collision_count; collision_index++) { StructuredCollision collision = collisions[collision_index]; - float dist = distance(collision.centre, worldPosition); + float dist = distance(collision.centre[eyeIndex], worldPosition); float power = smoothstep(collision.radius, 0.0, dist); - float3 direction = worldPosition - collision.centre; + float3 direction = worldPosition - collision.centre[eyeIndex]; direction.y = 0; // stops expanding/stretching direction = normalize(direction); float3 shift = power * direction; diff --git a/src/Feature.cpp b/src/Feature.cpp index 1f26d0bad..a4df33c28 100644 --- a/src/Feature.cpp +++ b/src/Feature.cpp @@ -82,6 +82,7 @@ const std::vector& Feature::GetFeatureList() static std::vector featuresVR = { GrassLighting::GetSingleton(), + GrassCollision::GetSingleton(), ExtendedMaterials::GetSingleton(), LightLimitFix::GetSingleton() }; diff --git a/src/Features/GrassCollision.cpp b/src/Features/GrassCollision.cpp index 1733e8a43..487a58e1e 100644 --- a/src/Features/GrassCollision.cpp +++ b/src/Features/GrassCollision.cpp @@ -126,15 +126,15 @@ void GrassCollision::UpdateCollisions() radius *= settings.RadiusMultiplier; CollisionSData data{}; RE::NiPoint3 eyePosition{}; - if (REL::Module::IsVR()) { - // find center of eye position - eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); - eyePosition /= 2; - } else - eyePosition = state->GetRuntimeData().posAdjust.getEye(); - data.centre.x = centerPos.x - eyePosition.x; - data.centre.y = centerPos.y - eyePosition.y; - data.centre.z = centerPos.z - eyePosition.z; + for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { + if (!REL::Module::IsVR()) { + eyePosition = state->GetRuntimeData().posAdjust.getEye(); + } else + eyePosition = state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); + data.centre[eyeIndex].x = centerPos.x - eyePosition.x; + data.centre[eyeIndex].y = centerPos.y - eyePosition.y; + data.centre[eyeIndex].z = centerPos.z - eyePosition.z; + } data.radius = radius; currentCollisionCount++; collisionsData.push_back(data); @@ -200,15 +200,16 @@ void GrassCollision::ModifyGrass(const RE::BSShader*, const uint32_t) auto bound = shaderState.cachedPlayerBound; RE::NiPoint3 eyePosition{}; - if (REL::Module::IsVR()) { - // find center of eye position - eyePosition = state->GetVRRuntimeData().posAdjust.getEye() + state->GetVRRuntimeData().posAdjust.getEye(1); - eyePosition /= 2; - } else - eyePosition = state->GetRuntimeData().posAdjust.getEye(); - perFrameData.boundCentre.x = bound.center.x - eyePosition.x; - perFrameData.boundCentre.y = bound.center.y - eyePosition.y; - perFrameData.boundCentre.z = bound.center.z - eyePosition.z; + for (int eyeIndex = 0; eyeIndex < eyeCount; eyeIndex++) { + if (!REL::Module::IsVR()) { + eyePosition = state->GetRuntimeData().posAdjust.getEye(); + } else + eyePosition = state->GetVRRuntimeData().posAdjust.getEye(eyeIndex); + perFrameData.boundCentre[eyeIndex].x = bound.center.x - eyePosition.x; + perFrameData.boundCentre[eyeIndex].y = bound.center.y - eyePosition.y; + perFrameData.boundCentre[eyeIndex].z = bound.center.z - eyePosition.z; + perFrameData.boundCentre[eyeIndex].w = 0.0f; + } perFrameData.boundRadius = bound.radius * settings.RadiusMultiplier; perFrameData.Settings = settings; diff --git a/src/Features/GrassCollision.h b/src/Features/GrassCollision.h index 77b01c400..6b1a92d12 100644 --- a/src/Features/GrassCollision.h +++ b/src/Features/GrassCollision.h @@ -23,15 +23,14 @@ struct GrassCollision : Feature struct alignas(16) PerFrame { - DirectX::XMFLOAT3 boundCentre; + Vector4 boundCentre[2]; float boundRadius; Settings Settings; - float pad0; }; struct CollisionSData { - DirectX::XMFLOAT3 centre; + Vector3 centre[2]; float radius; }; @@ -41,6 +40,7 @@ struct GrassCollision : Feature bool updatePerFrame = false; ConstantBuffer* perFrame = nullptr; + int eyeCount = !REL::Module::IsVR() ? 1 : 2; virtual void SetupResources(); virtual void Reset();