mirror of
https://github.com/w23/xash3d-fwgs
synced 2025-01-18 14:50:05 +01:00
fix projection matrix vulkan fixup
we were mixing up row vs column major matrices now RTX ray generation is fixes, and traditional rasterizer rendering should also be projecting similar to gl render
This commit is contained in:
parent
28cdeaeb1d
commit
78d9a87344
@ -21,9 +21,9 @@ void main() {
|
||||
vec2 res = imageSize(image);
|
||||
vec2 uv = (gl_GlobalInvocationID.xy + .5) / res * 2. - 1.;
|
||||
|
||||
vec4 origin = ubo.inv_view * vec4(0, 0, 0, 1);
|
||||
vec4 target = ubo.inv_proj * vec4(uv.x, uv.y, 1, 1);
|
||||
vec4 direction = ubo.inv_view * vec4(normalize(target.xyz), 0);
|
||||
vec4 origin = ubo.inv_view * vec4(0, 0, 0, 1);
|
||||
vec4 target = ubo.inv_proj * vec4(uv.x, uv.y, 1, 1);
|
||||
vec4 direction = ubo.inv_view * vec4(normalize(target.xyz), 0);
|
||||
|
||||
vec3 C = vec3(0.);
|
||||
vec3 O = origin.xyz, D=direction.xyz;
|
||||
@ -37,7 +37,7 @@ void main() {
|
||||
C = vec3(1., 0., 1.);
|
||||
} else {
|
||||
vec3 pos = O+D*l;
|
||||
C = fract(pos);
|
||||
C = fract(pos/100.);
|
||||
}
|
||||
|
||||
imageStore(image, ivec2(gl_GlobalInvocationID.xy), vec4(C, 1.));
|
||||
|
@ -465,18 +465,20 @@ void VK_RenderStateSetMatrix( const matrix4x4 mvp )
|
||||
Matrix4x4_ToArrayFloatGL( mvp, (float*)g_render_state.dirty_uniform_data.mvp );
|
||||
}
|
||||
|
||||
void VK_RenderStateSetProjectionMatrix(const matrix4x4 proj)
|
||||
void VK_RenderStateSetProjectionMatrix(const matrix4x4 proj_vk)
|
||||
{
|
||||
matrix4x4 tmp;
|
||||
Matrix4x4_Invert_Full(tmp, proj);
|
||||
Matrix4x4_ToArrayFloatGL( tmp, g_render_state.rtx.proj_inv);
|
||||
matrix4x4 proj_inv_row;
|
||||
Matrix4x4_Invert_Full(proj_inv_row, proj_vk);
|
||||
Matrix4x4_ToArrayFloatGL(proj_inv_row, (float*)g_render_state.rtx.proj_inv);
|
||||
}
|
||||
|
||||
void VK_RenderStateSetViewMatrix(const matrix4x4 view)
|
||||
{
|
||||
// TODO there's a more efficient way to construct an inverse view matrix
|
||||
// from vforward/right/up vectors and origin in g_camera
|
||||
matrix4x4 tmp;
|
||||
Matrix4x4_Invert_Full(tmp, view);
|
||||
Matrix4x4_ToArrayFloatGL( tmp, g_render_state.rtx.view_inv);
|
||||
Matrix4x4_ToArrayFloatGL( tmp, (float*)g_render_state.rtx.view_inv);
|
||||
}
|
||||
|
||||
static uint32_t allocUniform( uint32_t size, uint32_t alignment ) {
|
||||
|
@ -541,11 +541,12 @@ static void setupCamera( const ref_viewpass_t *rvp, matrix4x4 mvp )
|
||||
|
||||
{
|
||||
// Vulkan has Y pointing down, and z should end up in (0, 1)
|
||||
// NOTE this matrix is row-major
|
||||
const matrix4x4 vk_proj_fixup = {
|
||||
{1, 0, 0, 0},
|
||||
{0, -1, 0, 0},
|
||||
{0, 0, .5, 0},
|
||||
{0, 0, .5, 1}
|
||||
{0, 0, .5, .5},
|
||||
{0, 0, 0, 1}
|
||||
};
|
||||
Matrix4x4_Concat( mvp, vk_proj_fixup, g_camera.worldviewProjectionMatrix);
|
||||
Matrix4x4_Concat( g_camera.projectionMatrixVk, vk_proj_fixup, g_camera.projectionMatrix);
|
||||
|
Loading…
x
Reference in New Issue
Block a user