ref: 4ed5ec69d44f6af09c291a55ae682102d82c3a73
parent: 7138ee9632e711d1aad9400ed2c5df0e4bf90c72
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Oct 14 13:29:37 EDT 2024
add back v_blend logic and (reduced to 30% default) v_cshiftpercent
--- a/colormatrix.c
+++ b/colormatrix.c
@@ -23,6 +23,7 @@
static float cmbrightness[4*4];
static float cmcontrast[4*4];
static float cmsaturation[4*4];
+static float cmvblend[4*4];
static float gs[3] = {0.3086, 0.6094, 0.0820};
static void
@@ -37,11 +38,39 @@
}
static void
-cmcvarcb(cvar_t *var)
+cmrecalc(void)
{
- float r, v, *m, t[4*4], t2[4*4];
+ float t[4*4], t2[4*4];
int i;
+ mmul(t, cmbrightness, cmcontrast);
+ mmul(t2, t, cmsaturation);
+ mmul(t, t2, cmvblend);
+ for(i = 0; i < 4*4; i++)
+ cm[i] = CM(t[i]);
+ cmident = memcmp(cm, cm0, sizeof(cm)) == 0;
+}
+
+void
+cmsetvblend(float b[4])
+{
+ float r;
+
+ r = 1 - b[3];
+ cmvblend[4*0+0] = r;
+ cmvblend[4*0+3] = b[2];
+ cmvblend[4*1+1] = r;
+ cmvblend[4*1+3] = b[1];
+ cmvblend[4*2+2] = r;
+ cmvblend[4*2+3] = b[0];
+ cmrecalc();
+}
+
+static void
+cmcvarcb(cvar_t *var)
+{
+ float r, v, *m;
+
if(var == &v_brightness){
v = clamp(var->value, 0.5, 4.5);
m = cmbrightness;
@@ -95,17 +124,14 @@
m[4*3+1] = 0;
m[4*3+2] = 0;
m[4*3+3] = 1;
- mmul(t, cmbrightness, cmcontrast);
- mmul(t2, t, cmsaturation);
- for(i = 0; i < 4*4; i++)
- cm[i] = CM(t2[i]);
- cmident = memcmp(cm, cm0, sizeof(cm)) == 0;
+ cmrecalc();
}
void
cminit(void)
{
- memmove(cm, cm0, sizeof(cm));
+ memmove(cm, cm0, sizeof(cm0));
+ memmove(cmvblend, cmf0, sizeof(cmf0));
Cvar_RegisterVariable(&v_brightness);
v_brightness.cb = cmcvarcb;
--- a/colormatrix.h
+++ b/colormatrix.h
@@ -5,5 +5,6 @@
extern cvar_t v_contrast;
extern cvar_t v_brightness;
+void cmsetvblend(float blend[4]);
void cmprocess(s16int cm[4*4], void *in, void *out, int n);
void cminit(void);
--- a/r_local.h
+++ b/r_local.h
@@ -193,6 +193,5 @@
void R_AnimateLight (void);
void R_LightPoint (vec3_t p, int *r);
void R_SetupFrame (void);
-void R_cshift_f (void);
void R_SplitEntityOnNode2 (mnode_t *node);
void R_MarkLights (dlight_t *light, int bit, mnode_t *node);
--- a/view.c
+++ b/view.c
@@ -12,6 +12,8 @@
cvar_t v_scale = {"v_scale", "1", true};
+static cvar_t v_cshiftpercent = {"v_cshiftpercent", "30", true};
+
static cvar_t scr_ofsx = {"scr_ofsx","0", false};
static cvar_t scr_ofsy = {"scr_ofsy","0", false};
static cvar_t scr_ofsz = {"scr_ofsz","0", false};
@@ -398,6 +400,30 @@
cl.cshifts[CSHIFT_POWERUP].percent = 0;
}
+static void
+V_Blend(void)
+{
+ float c[4], a;
+ int i;
+
+ c[0] = c[1] = c[2] = c[3] = 0;
+ for(i = 0; i < NUM_CSHIFTS; i++){
+ a = ((cl.cshifts[i].percent * v_cshiftpercent.value)/100.0)/255.0;
+ if(a > 0){
+ c[3] += a*(1 - c[3]);
+ a = a/c[3];
+ c[0] = c[0]*(1-a) + cl.cshifts[i].destcolor[0]*a;
+ c[1] = c[1]*(1-a) + cl.cshifts[i].destcolor[1]*a;
+ c[2] = c[2]*(1-a) + cl.cshifts[i].destcolor[2]*a;
+ }
+ }
+ c[3] = clamp(c[3], 0, 1.0);
+ c[2] *= c[3]/255.0;
+ c[1] *= c[3]/255.0;
+ c[0] *= c[3]/255.0;
+ cmsetvblend(c);
+}
+
/*
=============
V_UpdatePalette
@@ -431,7 +457,8 @@
cl.cshifts[CSHIFT_BONUS].percent -= host_frametime*100;
if (cl.cshifts[CSHIFT_BONUS].percent <= 0)
cl.cshifts[CSHIFT_BONUS].percent = 0;
- // FIXME(sigrid): 24-bit
+
+ V_Blend();
}
@@ -852,6 +879,7 @@
Cvar_RegisterVariable(&v_scale);
v_scale.cb = v_scale_cb;
+ Cvar_RegisterVariable(&v_cshiftpercent);
Cvar_RegisterVariable (&v_centermove);
Cvar_RegisterVariable (&v_centerspeed);