From 338b404055ec3ca02fd8e6121ca0510ae9a3b4fc Mon Sep 17 00:00:00 2001 From: mittorn Date: Thu, 4 Apr 2019 10:27:18 +0700 Subject: [PATCH] ref_soft: clamp alpha values --- r_edge.c | 11 +++++++++-- r_glblit.c | 7 +++++++ r_scan.c | 10 ++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/r_edge.c b/r_edge.c index e8b73f8d..1ac231a4 100644 --- a/r_edge.c +++ b/r_edge.c @@ -996,6 +996,8 @@ Normal surface cached, texture mapped surface */ void D_AlphaSurf (surf_t *s) { + int alpha; + d_zistepu = s->d_zistepu; d_zistepv = s->d_zistepv; d_ziorigin = s->d_ziorigin; @@ -1052,13 +1054,16 @@ void D_AlphaSurf (surf_t *s) miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust); } #endif + alpha = RI.currententity->curstate.renderamt * 7 / 255; + if( alpha <= 0 && RI.currententity->curstate.renderamt > 0 ) + alpha = 1; if (s->flags & SURF_DRAWTURB ) { cacheblock = R_GetTexture(pface->texinfo->texture->gl_texturenum)->pixels[0]; cachewidth = 64; D_CalcGradients (pface); - TurbulentZ8( s->spans, RI.currententity->curstate.renderamt * 7 / 255 ); + TurbulentZ8( s->spans, alpha); } else { @@ -1070,12 +1075,14 @@ void D_AlphaSurf (surf_t *s) D_CalcGradients (pface); + + if( RI.currententity->curstate.rendermode == kRenderTransAlpha ) D_AlphaSpans16(s->spans); else if( RI.currententity->curstate.rendermode == kRenderTransAdd ) D_AddSpans16(s->spans); else - D_BlendSpans16(s->spans, RI.currententity->curstate.renderamt * 7 / 255 ); + D_BlendSpans16(s->spans, alpha ); } VectorCopy (world_transformed_modelorg, diff --git a/r_glblit.c b/r_glblit.c index 0c2fdf41..a73cac59 100644 --- a/r_glblit.c +++ b/r_glblit.c @@ -231,6 +231,13 @@ void R_BuildBlendMaps() r = r1 * (7 - a) / 7 + (r2 << 2 | BIT(2)) * a / 7; g = g1 * (7 - a) / 7 + (g2 << 3 | MASK(2)) * a / 7; b = b1 * (7 - a) / 7 + (b2 << 3 | MASK(2)) * a / 7; + if( r > MASK(5) ) + r = MASK(5); + if( g > MASK(6) ) + g = MASK(6); + if( b > MASK(5) ) + b = MASK(5); + ASSERT( b < 32 ); major = (((r >> 2) & MASK(3)) << 5) |( (( (g >> 3) & MASK(3)) << 2 ) )| (((b >> 3) & MASK(2))); diff --git a/r_scan.c b/r_scan.c index fa5855c3..18a72ac9 100644 --- a/r_scan.c +++ b/r_scan.c @@ -297,6 +297,11 @@ void TurbulentZ8 (espan_t *pspan, int alpha1) float sdivz16stepu, tdivz16stepu, zi16stepu; alpha = alpha1; + if( alpha > 7 ) + alpha = 7; + if( alpha == 0 ) + return; + r_turb_turb = sintable + ((int)(gpGlobals->time*SPEED)&(CYCLE-1)); r_turb_sstep = 0; // keep compiler happy @@ -960,6 +965,11 @@ void D_BlendSpans16 (espan_t *pspan, int alpha) int izi, izistep; short *pz; + if( alpha > 7 ) + alpha = 7; + if( alpha == 0 ) + return; + sstep = 0; // keep compiler happy tstep = 0; // ditto