vk: orient sprites to camera

Somehow makes sprites correctly oriented (and winding-culled) for ray
tracing, but makes them disappear (winding-culled) for traditional
renderer. This makes zero sense.
This commit is contained in:
Ivan Avdeev 2023-06-01 11:00:50 -07:00
parent edb151bd1b
commit 72acf4882d
3 changed files with 39 additions and 7 deletions

View File

@ -286,3 +286,25 @@ void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const
out_tangent[1] = f * (duv2[1] * e1[1] - duv1[1] * e2[1]);
out_tangent[2] = f * (duv2[1] * e1[2] - duv1[1] * e2[2]);
}
void Matrix4x4_CreateFromVectors(matrix4x4 out, const vec3_t right, const vec3_t up, const vec3_t z, const vec3_t translate) {
out[0][0] = right[0];
out[1][0] = right[1];
out[2][0] = right[2];
out[3][0] = 0;
out[0][1] = up[0];
out[1][1] = up[1];
out[2][1] = up[2];
out[3][1] = 0;
out[0][2] = z[0];
out[1][2] = z[1];
out[2][2] = z[2];
out[3][2] = 0;
out[0][3] = translate[0];
out[1][3] = translate[1];
out[2][3] = translate[2];
out[3][3] = 0;
}

View File

@ -22,3 +22,5 @@ void Matrix4x4_CreateOrtho(matrix4x4 m, float xLeft, float xRight, float yBottom
void Matrix4x4_CreateModelview( matrix4x4 out );
void computeTangent(vec3_t out_tangent, const vec3_t v0, const vec3_t v1, const vec3_t v2, const vec2_t uv0, const vec2_t uv1, const vec2_t uv2);
void Matrix4x4_CreateFromVectors(matrix4x4 out, const vec3_t right, const vec3_t up, const vec3_t z, const vec3_t translate);

View File

@ -49,7 +49,7 @@ static qboolean createQuadModel(void) {
const vec3_t org = {0, 0, 0};
const vec3_t v_right = {1, 0, 0};
const vec3_t v_up = {0, 0, 1};
const vec3_t v_up = {0, 1, 0};
vec3_t v_normal;
CrossProduct(v_right, v_up, v_normal);
@ -128,7 +128,7 @@ qboolean R_SpriteInit(void) {
R_SpeedsRegisterMetric(&g_sprite.stats.sprites, "sprites_count", kSpeedsMetricCount);
return true;
//return createQuadModel();
// TODO return createQuadModel();
}
void R_SpriteShutdown(void) {
@ -784,16 +784,24 @@ static vk_render_type_e spriteRenderModeToRenderType( int render_mode ) {
static void R_DrawSpriteQuad( const char *debug_name, mspriteframe_t *frame, vec3_t org, vec3_t v_right, vec3_t v_up, float scale, int texture, int render_mode, const vec4_t color ) {
vec3_t v_normal;
vec3_t point;
//CrossProduct(v_right, v_up, v_normal);
CrossProduct(v_right, v_up, v_normal);
// TODO can frame->right/left and frame->up/down be asymmetric?
VectorScale(v_right, frame->right * scale, v_right);
VectorScale(v_up, frame->up * scale, v_up);
matrix4x4 transform;
Matrix4x4_CreateFromVectors(transform, v_right, v_up, v_normal, org);
// FIXME orient sprites
//VectorMA( org, frame->down * scale, v_up, point );
//VectorMA( point, frame->left * scale, v_right, dst_vtx[0].pos );
//vtx[0] = org + down * scale + v_up + left * scale * v_right;
Matrix4x4_CreateScale(transform, frame->down * scale);
Matrix4x4_SetOrigin(transform, org[0], org[1], org[2]);
//vtx[0] = org + down * scale * v_up + left * scale * v_right;
// FIXME Scale3
//Matrix4x4_CreateScale(transform, frame->down * scale);
//Matrix4x4_SetOrigin(transform, org[0], org[1], org[2]);
const vk_render_type_e render_type = spriteRenderModeToRenderType(render_mode);
R_RenderModelDraw(&g_sprite.quad.model, (r_model_draw_t){