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

Incorrect behavior of shadow when highdpi is enabled #30

Open
zwirec opened this issue Feb 25, 2019 · 7 comments
Open

Incorrect behavior of shadow when highdpi is enabled #30

zwirec opened this issue Feb 25, 2019 · 7 comments

Comments

@zwirec
Copy link

zwirec commented Feb 25, 2019

OS: MacOS 10.14.2 (18C54)

I have a simple code snippet similar to code located in wiki page https://github.com/matiasah/shadows/wiki/Standard-Demonstration

There is my code:

local Shadows = require("shadows")
local LightWorld = require("shadows.LightWorld")
local Light = require("shadows.Light")
local Body = require("shadows.Body")
local PolygonShadow = require("shadows.ShadowShapes.PolygonShadow")
local CircleShadow = require("shadows.ShadowShapes.CircleShadow")

love.window.setMode(1280, 1280, { highdpi = true })

-- Create a light world
newLightWorld = LightWorld:new()

-- Create a light on the light world, with radius 300
newLight = Light:new(newLightWorld, 300)

-- Set the light's color to white
newLight:SetColor(255, 255, 255, 255)

-- Set the light's position
newLight:SetPosition(400, 400)

-- Create a body
newBody = Body:new(newLightWorld)

-- Set the body's position and rotation
newBody:SetPosition(300, 300)
newBody:SetAngle(-15)

-- Create a polygon shape on the body with the given points
PolygonShadow:new(newBody, -10, -10, 10, -10, 10, 10, -10, 10)

-- Create a circle shape on the body at (-30, -30) with radius 16
CircleShadow:new(newBody, -30, -30, 16)

function love.draw()
    -- Clear the screen
    love.graphics.setColor(255, 255, 255, 255)
    love.graphics.rectangle("fill", 0, 0, love.graphics.getDimensions())

    -- Draw the light world with white color
    newLightWorld:Draw()
end

function love.update()
    -- Move the light to the mouse position with altitude 1.1
    newLight:SetPosition(love.mouse.getX(), love.mouse.getY(), 1.1)

    -- Recalculate the light world
    newLightWorld:Update()
end

function love.mousepressed()
    -- Create a new light with radius 300
    newLight = Light:new(newLightWorld, 300)

    -- Set the light's color randomly
    newLight:SetColor(math.random(0, 255), math.random(0, 255), math.random(0, 255), math.random(0, 255))
end

I set options highdpi for window to true and I got

image

With highdpi=false everything looks as it should be:

image

@matiasah
Copy link
Owner

Uh, unfortunately I don't have the hardware nor software to recreate this scenario, I'm not sure how could I solve this problem or help you out on your issue. I ran your code on my computer (which also uses Windows) but the problem does not seem to show up to me. Sorry.

@Skeletonxf
Copy link
Contributor

Skeletonxf commented Feb 26, 2019

I tried to reproduce this as well on my Linux laptop and I cannot reproduce - I get the correct behavior in the second screenshot without modifying the highdpi to false

I am using f8d1c8c and LOVE 11.1 (Mysterious Mysteries)

@zwirec
Copy link
Author

zwirec commented Feb 27, 2019

I guess this effect is appear by reason of Mac Retina mode

Anyway I would be glad if someone would help me

@Skeletonxf
Copy link
Contributor

It would seem this is a Mac specific flag in Love anyway so it will not be reproducible elsewhere.

https://love2d.org/wiki/love.window.getDPIScale

@matiasah
Copy link
Owner

matiasah commented Feb 27, 2019

the window may take up the same physical size as an 800x600 window, but the area inside the window uses 1600x1200 pixels

Which means, I would have to multiply the canvas size that is being sent to the shader (before it actually is sent to the shader), by the DPI scale.

Edit: Or either use this.
https://love2d.org/wiki/love.graphics.getPixelDimensions

What do you guys suggest?

@matiasah
Copy link
Owner

This issue brings a lot of changes, as most of the things that are being sent to the shaders are erroneous

@Skeletonxf
Copy link
Contributor

I think another concern is that you cannot cache the DPI scale as it might be changed while the application is running. I think multiplying by love.graphics.getDPIScale() everywhere would be more clear when reading the code - however it also seems not all units reported by Love need scaling.

The units of love.graphics.getWidth, love.graphics.getHeight, love.mouse.getPosition, mouse events, love.touch.getPosition, and touch events are always in DPI-scaled units rather than pixels. In LÖVE 0.10 and older they were in pixels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@matiasah @Skeletonxf @zwirec and others