Hello everyone
Im currently working on trying to build my own space invader type of game, in 2D using Metal.
I have 3 backgrounds for the game, and Ive split out these three in its own “renderer”.
For example:
MainRenderer creates commandEncoder, etc, and pass that into BackgroundRenderer, then it goes to the MidgroundRenderer, etc.
The Background Quad that fills the full screen was initially made like this:
vertices = [
Vertex(position: [-1, 1], textureCoordinate: [0, 1]),
Vertex(position: [1, 1], textureCoordinate: [1, 1]),
Vertex(position: [1, -1], textureCoordinate: [1, 0]),
Vertex(position: [-1, -1], textureCoordinate: [0, 0])
]
This all worked fine and I could draw separate layers so to speak.
Then I wanted to introduce depth testing between the layers so gave each renderer its own depthStencilState with a .less comparison value. All good.
However, I wanted to use the z-axis of each layer to determine the depth value.
So when I add the z axis to my background quad like this:
vertices = [
Vertex(position: [-1, 1, 1], textureCoordinate: [0, 1]),
Vertex(position: [1, 1, 1], textureCoordinate: [1, 1]),
Vertex(position: [1, -1, 1], textureCoordinate: [1, 0]),
Vertex(position: [-1, -1, 1], textureCoordinate: [0, 0])
]
my texture is all distorted. I can’t figure out what the issue is even after several hours with chatgpt, haha.
Ive tried just render the first layer with a orthographic projection matrix too but it doesnt work.
Anyone has any ideas or suggestions to try?
Thank you