Alternative to #1203 and #1611 Camera bindings have historically been "hacked in". They were _required_ in all shaders and only supported a single Mat4. PBR (#1554) requires the CameraView matrix, but adding this using the "hacked" method forced users to either include all possible camera data in a single binding (#1203) or include all possible bindings (#1611). This approach instead assigns each "active camera" its own RenderResourceBindings, which are populated by CameraNode. The PassNode then retrieves (and initializes) the relevant bind groups for all render pipelines used by visible entities. * Enables any number of camera bindings , including zero (with any set or binding number ... set 0 should still be used to avoid rebinds). * Renames Camera binding to CameraViewProj * Adds CameraView binding
44 lines
1.2 KiB
GLSL
44 lines
1.2 KiB
GLSL
#version 450
|
|
|
|
layout(location = 0) in vec3 Vertex_Position;
|
|
layout(location = 1) in vec3 Vertex_Normal;
|
|
layout(location = 2) in vec2 Vertex_Uv;
|
|
|
|
layout(location = 0) out vec2 v_Uv;
|
|
|
|
layout(set = 0, binding = 0) uniform CameraViewProj {
|
|
mat4 ViewProj;
|
|
};
|
|
|
|
layout(set = 2, binding = 0) uniform Transform {
|
|
mat4 Model;
|
|
};
|
|
layout(set = 2, binding = 1) uniform Sprite {
|
|
vec2 size;
|
|
uint flip;
|
|
};
|
|
|
|
void main() {
|
|
vec2 uv = Vertex_Uv;
|
|
|
|
// Flip the sprite if necessary by flipping the UVs
|
|
|
|
uint x_flip_bit = 1; // The X flip bit
|
|
uint y_flip_bit = 2; // The Y flip bit
|
|
|
|
// Note: Here we subtract f32::EPSILON from the flipped UV coord. This is due to reasons unknown
|
|
// to me (@zicklag ) that causes the uv's to be slightly offset and causes over/under running of
|
|
// the sprite UV sampling which is visible when resizing the screen.
|
|
float epsilon = 0.00000011920929;
|
|
if ((flip & x_flip_bit) == x_flip_bit) {
|
|
uv = vec2(1.0 - uv.x - epsilon, uv.y);
|
|
}
|
|
if ((flip & y_flip_bit) == y_flip_bit) {
|
|
uv = vec2(uv.x, 1.0 - uv.y - epsilon);
|
|
}
|
|
|
|
v_Uv = uv;
|
|
|
|
vec3 position = Vertex_Position * vec3(size, 1.0);
|
|
gl_Position = ViewProj * Model * vec4(position, 1.0);
|
|
} |