#Texture clipping

6 messages · Page 1 of 1 (latest)

supple yacht
#

Apologize for the horrible image, I am in a moving vehicle, but I hope it serves as an illustration of my problem.

The short version of my question is: how do I properly clip only the part of the texture that is in the camera's view?

The longer version with context is this:

I am using a 3D ortho camera to render my sprites as billboards to avoid wasting time on y-sorting.

The next (or previous) step of my rendering pipeline is tilemaps. Instead of rendering individual tiles, I want to bake all my tilemap layers into same-sized textures and only update them as needed / overwrite them on scene changes.

The problem:

I have no idea what I'm doing, the math here seems to be just simple geometry but I can't get it to work. The world-space 2D coordinates match the texture coordinates 1:1, so I know there is a perfectly simple way to achieve this.

Currently I am doing:

I am already calculating an occlusion rectangle that is slightly smaller than the camera view for testing purposes, which works fine.

My next attempt will be maybe blasting it into the world, getting a world-space collision rect between it and the tilemap and using that as the source and dest rect for my billboard? Since they are both 1:1 in size, this should... work. Though I am probably not accounting for something here.

If anyone has any pointers, I would appreciate it.

#

forgot to write, I could also technically use a dual cam setup where the 2d cam renders the tilemap layers. This would make sure that the tilemap doesn't have to consider render order (as in 3D depth, I could just underlay / overlay it). The main issue here would be keeping it in sync with the 3D camera.

grand coral
#

BeginScissorMode/EndScissorMode will create a clipping rectangle in screen space

supple yacht
#

I basically got here by experimenting with different variables for position and origin, and I know that the problem is there. Most likely. Probably

grand coral
#

you can also draw to a render texture then draw that texture to the screen