aarthificial / pixelgraphics

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

Camera mode #6

Open Paerux opened 3 years ago

Paerux commented 3 years ago

I apologize if this was mentioned somewhere but does this only work with Orthographic camera? I use perspective camera for the parallax effect and I was wondering if this could be modified in some way to work with perspective camera, didn't know where else to reach so I figured I'd create an issue

coderEFE commented 2 years ago

I have the same issue as well. I use perspective camera and have some grass assets with a non-zero depth (z-axis) for a parallax effect, but adding the grass or foliage shaders usually makes the grass asset become fixed to a zero depth and removes the parallax effect. I played around with shader and found that creating variations of it with different velocity strengths and wind scales made some grasses stay at their depth, but it's pretty finicky. Hopefully this issue can be resolved, otherwise I may have to find another shader. Awesome shader though!

coderEFE commented 2 years ago

@Paerux I was able to make a modification to the grass_shader shader graph so that the shader now works with a Perspective camera.

image Essentially, I split the object's position into x, y, and z channels and only applied the shader vertex transformations to the x-channel, which prevents the shader from modifying the object's depth (z-axis). If you want the y-channel to be modified also, make sure to apply that channel from the Split to the Add node (I recommend pairing the x and y into a Vector2).

The old shader structure is pictured below: image Notice that it transforms all channels of the object's position from a Vector3 out.

If these instructions don't work for you, I can also attach my shader graph file.

SETENTIAdev commented 1 year ago

Hello, I've got the same issue. Seems like is not working on perspective camera.

If I use perspective, all good: GRASS1

... but my project uses orthographic, so this is what it does: GRASS2

I tried @coderEFE, but result was the same. I don't need depth, as player won't interact with things on foreground/background.

Pinging @aarthificial, since a lot of users might use Orthographic cameras. Any idea on how to fix this would be appreciated. Thanks!