Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SpriteEffect.cs to honor the Viewport settings #8093

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions MonoGame.Framework/Graphics/Effect/SpriteEffect.cs
Expand Up @@ -63,12 +63,14 @@ void CacheEffectParameters()
protected internal override void OnApply()
{
var vp = GraphicsDevice.Viewport;
if ((vp.Width != _lastViewport.Width) || (vp.Height != _lastViewport.Height))
if (vp.X != _lastViewport.X || vp.Y != _lastViewport.Y ||
vp.Width != _lastViewport.Width || vp.Height != _lastViewport.Height ||
vp.MinDepth != _lastViewport.MinDepth || vp.MaxDepth != _lastViewport.MaxDepth)
{
// Normal 3D cameras look into the -z direction (z = 1 is in front of z = 0). The
// sprite batch layer depth is the opposite (z = 0 is in front of z = 1).
// --> We get the correct matrix with near plane 0 and far plane -1.
Matrix.CreateOrthographicOffCenter(0, vp.Width, vp.Height, 0, 0, -1, out _projection);
// --> We get the correct matrix with near plane 0 and far plane -1 (-MinDepth, -MaxDepth).
Matrix.CreateOrthographicOffCenter(vp.X, vp.X + vp.Width, vp.Y + vp.Height, vp.Y, -vp.MinDepth, -vp.MaxDepth, out _projection);

if (GraphicsDevice.UseHalfPixelOffset)
{
Expand Down