Graphics/SkyboxBackground: Add movement scaler
Former-commit-id: 02682210b2b3d4b0cf27c6dd8cf171a025a92701
This commit is contained in:
parent
11abcc7da4
commit
91f778dd89
|
|
@ -32,11 +32,15 @@ namespace Nz
|
|||
|
||||
void Draw(const AbstractViewer* viewer) const;
|
||||
|
||||
BackgroundType GetBackgroundType() const;
|
||||
BackgroundType GetBackgroundType() const override;
|
||||
inline const Vector3f& GetMovementOffset() const;
|
||||
inline float GetMovementScale() const;
|
||||
inline const TextureRef& GetTexture() const;
|
||||
inline TextureSampler& GetTextureSampler();
|
||||
inline const TextureSampler& GetTextureSampler() const;
|
||||
|
||||
inline void SetMovementOffset(const Vector3f& offset);
|
||||
inline void SetMovementScale(float scale);
|
||||
inline void SetTexture(TextureRef cubemapTexture);
|
||||
inline void SetTextureSampler(const TextureSampler& sampler);
|
||||
|
||||
|
|
@ -48,6 +52,8 @@ namespace Nz
|
|||
|
||||
TextureRef m_texture;
|
||||
TextureSampler m_sampler;
|
||||
Vector3f m_movementOffset;
|
||||
float m_movementScale;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,16 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline const Vector3f& Nz::SkyboxBackground::GetMovementOffset() const
|
||||
{
|
||||
return m_movementOffset;
|
||||
}
|
||||
|
||||
inline float SkyboxBackground::GetMovementScale() const
|
||||
{
|
||||
return m_movementScale;
|
||||
}
|
||||
|
||||
inline const TextureRef& SkyboxBackground::GetTexture() const
|
||||
{
|
||||
return m_texture;
|
||||
|
|
@ -22,6 +32,20 @@ namespace Nz
|
|||
return m_sampler;
|
||||
}
|
||||
|
||||
inline void SkyboxBackground::SetMovementOffset(const Vector3f& offset)
|
||||
{
|
||||
NazaraAssert(std::isfinite(offset.x) && std::isfinite(offset.y) && std::isfinite(offset.z), "Offset must be a finite vector");
|
||||
|
||||
m_movementOffset = offset;
|
||||
}
|
||||
|
||||
inline void SkyboxBackground::SetMovementScale(float scale)
|
||||
{
|
||||
NazaraAssert(std::isfinite(scale), "Scale must be a finite value");
|
||||
|
||||
m_movementScale = scale;
|
||||
}
|
||||
|
||||
inline void SkyboxBackground::SetTexture(TextureRef cubemapTexture)
|
||||
{
|
||||
NazaraAssert(!cubemapTexture || cubemapTexture->IsValid(), "Invalid texture");
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@ namespace Nz
|
|||
static VertexBufferRef s_vertexBuffer;
|
||||
}
|
||||
|
||||
SkyboxBackground::SkyboxBackground(TextureRef cubemapTexture)
|
||||
SkyboxBackground::SkyboxBackground(TextureRef cubemapTexture) :
|
||||
m_movementOffset(Vector3f::Zero()),
|
||||
m_movementScale(0.f)
|
||||
{
|
||||
m_sampler.SetWrapMode(SamplerWrap_Clamp); // Nécessaire pour ne pas voir les côtés
|
||||
m_sampler.SetWrapMode(SamplerWrap_Clamp); // We don't want to see any beam
|
||||
|
||||
SetTexture(std::move(cubemapTexture));
|
||||
}
|
||||
|
|
@ -34,9 +36,24 @@ namespace Nz
|
|||
Matrix4f skyboxMatrix(viewer->GetViewMatrix());
|
||||
skyboxMatrix.SetTranslation(Vector3f::Zero());
|
||||
|
||||
float zNear = viewer->GetZNear();
|
||||
|
||||
constexpr float movementLimit = 0.05f;
|
||||
|
||||
Vector3f offset = (viewer->GetEyePosition() - m_movementOffset) * -m_movementScale;
|
||||
offset.x = Clamp(offset.x, -movementLimit, movementLimit);
|
||||
offset.y = Clamp(offset.y, -movementLimit, movementLimit);
|
||||
offset.z = Clamp(offset.z, -movementLimit, movementLimit);
|
||||
offset *= zNear;
|
||||
|
||||
Matrix4f world;
|
||||
world.MakeIdentity();
|
||||
world.SetScale(Vector3f(zNear));
|
||||
world.SetTranslation(offset);
|
||||
|
||||
Renderer::SetIndexBuffer(s_indexBuffer);
|
||||
Renderer::SetMatrix(MatrixType_View, skyboxMatrix);
|
||||
Renderer::SetMatrix(MatrixType_World, Matrix4f::Scale(Vector3f(viewer->GetZNear())));
|
||||
Renderer::SetMatrix(MatrixType_World, world);
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
Renderer::SetShader(s_shader);
|
||||
Renderer::SetTexture(0, m_texture);
|
||||
|
|
|
|||
Loading…
Reference in New Issue