From ca046d26c5a2db9bc1594b0da4cfd62b6a8a6043 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 13 Jan 2017 16:12:43 +0100 Subject: [PATCH] Make particle texture slightly higher quality --- src/swrenderer/drawers/r_draw.cpp | 17 +++++++++-------- src/swrenderer/drawers/r_draw.h | 3 ++- src/swrenderer/drawers/r_draw_pal.cpp | 6 +++--- src/swrenderer/drawers/r_draw_rgba.cpp | 6 +++--- src/swrenderer/things/r_particle.cpp | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/swrenderer/drawers/r_draw.cpp b/src/swrenderer/drawers/r_draw.cpp index 081c379a7..46c0ec784 100644 --- a/src/swrenderer/drawers/r_draw.cpp +++ b/src/swrenderer/drawers/r_draw.cpp @@ -65,7 +65,7 @@ namespace swrenderer int fuzzpos; int fuzzviewheight; - uint32_t particle_texture[16 * 16]; + uint32_t particle_texture[PARTICLE_TEXTURE_SIZE * PARTICLE_TEXTURE_SIZE]; short zeroarray[MAXWIDTH]; short screenheightarray[MAXWIDTH]; @@ -237,16 +237,17 @@ namespace swrenderer void R_InitParticleTexture() { - for (int y = 0; y < 16; y++) + float center = PARTICLE_TEXTURE_SIZE * 0.5f; + for (int y = 0; y < PARTICLE_TEXTURE_SIZE; y++) { - for (int x = 0; x < 16; x++) + for (int x = 0; x < PARTICLE_TEXTURE_SIZE; x++) { - float dx = (8 - x) / 8.0f; - float dy = (8 - y) / 8.0f; - float dist = sqrt(dx * dx + dy * dy); - float alpha = clamp(3.0f - dist * 3.0f, 0.0f, 1.0f); + float dx = (center - x - 0.5f) / center; + float dy = (center - y - 0.5f) / center; + float dist2 = dx * dx + dy * dy; + float alpha = clamp(1.1f - dist2 * 1.1f, 0.0f, 1.0f); - particle_texture[x + y * 16] = (int)(alpha * 64.0f + 0.5f); + particle_texture[x + y * PARTICLE_TEXTURE_SIZE] = (int)(alpha * 128.0f + 0.5f); } } } diff --git a/src/swrenderer/drawers/r_draw.h b/src/swrenderer/drawers/r_draw.h index 30bf46771..f7facda88 100644 --- a/src/swrenderer/drawers/r_draw.h +++ b/src/swrenderer/drawers/r_draw.h @@ -121,7 +121,8 @@ namespace swrenderer extern int fuzzpos; extern int fuzzviewheight; - extern uint32_t particle_texture[16 * 16]; + #define PARTICLE_TEXTURE_SIZE 64 + extern uint32_t particle_texture[PARTICLE_TEXTURE_SIZE * PARTICLE_TEXTURE_SIZE]; extern bool r_swtruecolor; diff --git a/src/swrenderer/drawers/r_draw_pal.cpp b/src/swrenderer/drawers/r_draw_pal.cpp index f577f6425..b0938572d 100644 --- a/src/swrenderer/drawers/r_draw_pal.cpp +++ b/src/swrenderer/drawers/r_draw_pal.cpp @@ -2788,10 +2788,10 @@ namespace swrenderer uint8_t *dest = thread->dest_for_thread(_dest_y, _pitch, _dest); int pitch = _pitch * thread->num_cores; - const uint32_t *source = &particle_texture[(_fracposx >> FRACBITS) * 16]; + const uint32_t *source = &particle_texture[(_fracposx >> FRACBITS) * PARTICLE_TEXTURE_SIZE]; uint32_t particle_alpha = _alpha; - uint32_t fracstep = 16 * FRACUNIT / _count; + uint32_t fracstep = PARTICLE_TEXTURE_SIZE * FRACUNIT / _count; uint32_t fracpos = fracstep * thread->skipped_by_thread(_dest_y) + fracstep / 2; fracstep *= thread->num_cores; @@ -2801,7 +2801,7 @@ namespace swrenderer for (int y = 0; y < count; y++) { - uint32_t alpha = (source[fracpos >> FRACBITS] * particle_alpha) >> 6; + uint32_t alpha = (source[fracpos >> FRACBITS] * particle_alpha) >> 7; uint32_t inv_alpha = 256 - alpha; int bg = *dest; diff --git a/src/swrenderer/drawers/r_draw_rgba.cpp b/src/swrenderer/drawers/r_draw_rgba.cpp index 6dbd676b2..434497f99 100644 --- a/src/swrenderer/drawers/r_draw_rgba.cpp +++ b/src/swrenderer/drawers/r_draw_rgba.cpp @@ -962,10 +962,10 @@ namespace swrenderer uint32_t *dest = thread->dest_for_thread(_dest_y, _pitch, _dest); int pitch = _pitch * thread->num_cores; - const uint32_t *source = &particle_texture[(_fracposx >> FRACBITS) * 16]; + const uint32_t *source = &particle_texture[(_fracposx >> FRACBITS) * PARTICLE_TEXTURE_SIZE]; uint32_t particle_alpha = _alpha; - uint32_t fracstep = 16 * FRACUNIT / _count; + uint32_t fracstep = PARTICLE_TEXTURE_SIZE * FRACUNIT / _count; uint32_t fracpos = fracstep * thread->skipped_by_thread(_dest_y) + fracstep / 2; fracstep *= thread->num_cores; @@ -975,7 +975,7 @@ namespace swrenderer for (int y = 0; y < count; y++) { - uint32_t alpha = (source[fracpos >> FRACBITS] * particle_alpha) >> 6; + uint32_t alpha = (source[fracpos >> FRACBITS] * particle_alpha) >> 7; uint32_t inv_alpha = 256 - alpha; uint32_t bg_red = (*dest >> 16) & 0xff; diff --git a/src/swrenderer/things/r_particle.cpp b/src/swrenderer/things/r_particle.cpp index b20acbcf6..e8d1cb1b7 100644 --- a/src/swrenderer/things/r_particle.cpp +++ b/src/swrenderer/things/r_particle.cpp @@ -249,7 +249,7 @@ namespace swrenderer spacing = RenderTarget->GetPitch(); - uint32_t fracstepx = 16 * FRACUNIT / countbase; + uint32_t fracstepx = PARTICLE_TEXTURE_SIZE * FRACUNIT / countbase; uint32_t fracposx = fracstepx / 2; if (r_swtruecolor)