I need to draw a sprite to a render target so that later on I can use it to mask the rendering of another sprite. However, in order for this to work, I need to draw the sprite to the full width and height of the render target.
The sprite’s world position can be anything, so first I need to get the vertex shader to output “local sprite coordinates” to the render target. I’m pretty sure that in the vertex shader I can just ignore the view_proj matrix and just output the position as it goes in
gl_Position = vec4(position.xyz, 1.0);
Also, in the render script I’m pretty sure I have to set an orthographic projection and the size of the viewport to the size of the sprite
One thing to note here is that the sprite vertices are batched, in order to create one draw call, as opposed to one draw call per sprite. Thus the sprite vertices are in world space.
Although the material has the option to select World or Local space, we haven’t yet implemented Local space for sprites.
Local space would currently mean that each sprite will become a separate draw call.
(a remedy for that would be to also implement instancing)
What we want to do is to improve on the vertex format of the sprites.
How that would work is not designed yet, and we also don’t have it planned in a near future.
I think a first step would be to put the vertex color in the vertex format, as opposed to having it as a shader uniform (i.e. we don’t want color to break the batching).
As for rendering a quad fullscreen, there are a few ways to do it.
scale the sprite accordinly to fit the screen (“sprite.set_scale()”)
using projected coordinates in the shader (i.e. figuring out how to output vertices with x/y equal to -1 or 1. essentially not using the model/view/projection matrix for the (single) sprite)