aarthificial / pixelgraphics

A collection of pixel art visual effects
MIT License
353 stars 28 forks source link

Perspective camera mode fix [experimental] #14

Open SETENTIAdev opened 1 year ago

SETENTIAdev commented 1 year ago

Ok, as some users have been having this issue, I thought I'd give it a go and I think a found a solution.

If you have an orthographic camera, all is good: GRASS1

Now, if you use perspective, then this weirdness will happen: GRASS2

After some fiddling, here's my fix, on perspective mode: perspective-fix

So, what changed? Basically, after dumping some values, I noticed the values for _originalCamera.projectionMatrix had a very noticeable difference between two camera modes. Like, in ortho you have tiny values like 0.09, while in perspective, this number was the same, but with less zeros (ie 0.9), so I kinda added this zero back, and all is good.

Basically the fix would be replacing this line:

cmd.SetGlobalVector(ShaderIds.CameraPositionDelta, screenDelta * 0.5f);

... for this one: cmd.SetGlobalVector(ShaderIds.CameraPositionDelta, screenDelta * 0.05f);

I tested different camera Z positions, FOV values and all seem to be working fine, but needs more testing.

If anyone is happy to further test or have the definitive fix, feel free to contribute. Hope this is useful for someone as it is for me!

udulabenaragama commented 1 year ago

In which file do I have to replace this?

SETENTIAdev commented 1 year ago

In which file do I have to replace this?

Hey, file is VelocityCamera.cs, located in: Runtime/Universal/ folder -- Line 111

Heurazio commented 1 year ago

This is great. Thanks a lot for the info.