Keep SdfgiDebug shader's push constant size <= 128

This commit is contained in:
Pedro J. Estébanez 2022-07-29 13:25:11 +02:00
parent cd24fb848e
commit 278950f731
3 changed files with 28 additions and 35 deletions

View File

@ -1591,34 +1591,24 @@ void GI::SDFGI::debug_draw(uint32_t p_view_count, const Projection *p_projection
push_constant.max_cascades = cascades.size(); push_constant.max_cascades = cascades.size();
push_constant.screen_size[0] = p_width; push_constant.screen_size[0] = p_width;
push_constant.screen_size[1] = p_height; push_constant.screen_size[1] = p_height;
push_constant.probe_axis_size = probe_axis_count;
push_constant.use_occlusion = uses_occlusion;
push_constant.y_mult = y_mult; push_constant.y_mult = y_mult;
push_constant.z_near = -p_projections[v].get_z_near(); push_constant.z_near = -p_projections[v].get_z_near();
push_constant.cam_transform[0] = p_transform.basis.rows[0][0]; for (int i = 0; i < 3; i++) {
push_constant.cam_transform[1] = p_transform.basis.rows[1][0]; for (int j = 0; j < 3; j++) {
push_constant.cam_transform[2] = p_transform.basis.rows[2][0]; push_constant.cam_basis[i][j] = p_transform.basis.rows[j][i];
push_constant.cam_transform[3] = 0; }
push_constant.cam_transform[4] = p_transform.basis.rows[0][1]; }
push_constant.cam_transform[5] = p_transform.basis.rows[1][1]; push_constant.cam_origin[0] = p_transform.origin[0];
push_constant.cam_transform[6] = p_transform.basis.rows[2][1]; push_constant.cam_origin[1] = p_transform.origin[1];
push_constant.cam_transform[7] = 0; push_constant.cam_origin[2] = p_transform.origin[2];
push_constant.cam_transform[8] = p_transform.basis.rows[0][2];
push_constant.cam_transform[9] = p_transform.basis.rows[1][2];
push_constant.cam_transform[10] = p_transform.basis.rows[2][2];
push_constant.cam_transform[11] = 0;
push_constant.cam_transform[12] = p_transform.origin.x;
push_constant.cam_transform[13] = p_transform.origin.y;
push_constant.cam_transform[14] = p_transform.origin.z;
push_constant.cam_transform[15] = 1;
// need to properly unproject for asymmetric projection matrices in stereo.. // need to properly unproject for asymmetric projection matrices in stereo..
Projection inv_projection = p_projections[v].inverse(); Projection inv_projection = p_projections[v].inverse();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 3; j++) {
push_constant.inv_projection[i * 4 + j] = inv_projection.matrix[i][j]; push_constant.inv_projection[j][i] = inv_projection.matrix[i][j];
} }
} }

View File

@ -232,16 +232,13 @@ private:
uint32_t max_cascades; uint32_t max_cascades;
int32_t screen_size[2]; int32_t screen_size[2];
uint32_t use_occlusion;
float y_mult; float y_mult;
uint32_t probe_axis_size;
float z_near; float z_near;
float reserved1;
float reserved2;
float cam_transform[16]; float inv_projection[3][4];
float inv_projection[16]; float cam_basis[3][3];
float cam_origin[3];
}; };
SdfgiDebugShaderRD debug; SdfgiDebugShaderRD debug;

View File

@ -37,16 +37,14 @@ layout(push_constant, std430) uniform Params {
uint max_cascades; uint max_cascades;
ivec2 screen_size; ivec2 screen_size;
bool use_occlusion;
float y_mult; float y_mult;
int probe_axis_size;
float z_near; float z_near;
float reserved1;
float reserved2;
mat4 cam_transform; mat3x4 inv_projection;
mat4 inv_projection; // We pack these more tightly than mat3 and vec3, which will require some reconstruction trickery.
float cam_basis[3][3];
float cam_origin[3];
} }
params; params;
@ -82,13 +80,21 @@ void main() {
vec3 ray_pos; vec3 ray_pos;
vec3 ray_dir; vec3 ray_dir;
{ {
ray_pos = params.cam_transform[3].xyz; ray_pos = vec3(params.cam_origin[0], params.cam_origin[1], params.cam_origin[2]);
ray_dir.xy = ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0); ray_dir.xy = ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0);
ray_dir.z = params.z_near; ray_dir.z = params.z_near;
ray_dir = (params.inv_projection * vec4(ray_dir, 1.0)).xyz;
ray_dir = normalize(mat3(params.cam_transform) * ray_dir); ray_dir = (vec4(ray_dir, 1.0) * mat4(params.inv_projection)).xyz;
mat3 cam_basis;
{
vec3 c0 = vec3(params.cam_basis[0][0], params.cam_basis[0][1], params.cam_basis[0][2]);
vec3 c1 = vec3(params.cam_basis[1][0], params.cam_basis[1][1], params.cam_basis[1][2]);
vec3 c2 = vec3(params.cam_basis[2][0], params.cam_basis[2][1], params.cam_basis[2][2]);
cam_basis = mat3(c0, c1, c2);
}
ray_dir = normalize(cam_basis * ray_dir);
} }
ray_pos.y *= params.y_mult; ray_pos.y *= params.y_mult;