Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[High Velocity - Mountain Racing Challenge (USA)] Problème d'affichage de l'arrière plan... #1496

Open
BenjaminSiskoo opened this issue Dec 16, 2023 · 3 comments

Comments

@BenjaminSiskoo
Copy link
Collaborator

kronos20231216_f235e2e

image

On devrait voir la ville en arrière plan :

image

Savestate :

highvelocity.zip

@BenjaminSiskoo BenjaminSiskoo changed the title [High Velocity - Mountain Racing Challenge (USA)] Problème d'aggichage de l'arrière plan... [High Velocity - Mountain Racing Challenge (USA)] Problème d'affichage de l'arrière plan... Dec 16, 2023
@fafling
Copy link

fafling commented Dec 18, 2023

L'arrière-plan est affiché par le RBG0.

Je ne sais pas par quel miracle il était correct en v2.5.0 publique, mais il avait des problèmes avant et presque tout de suite après.

Ces problèmes remontent aux WIP des 09-10/12/2021 qui fixait le gradient du ciel de Quake.

@FCare
Copy link
Owner

FCare commented Aug 27, 2024

Ca deconne sur ce shader:

#version 430 core 
#ifdef GL_ES
precision highp float; 
precision highp int;
precision highp image2D;
#endif
layout(local_size_x = 4, local_size_y = 4) in;
layout(rgba8, binding = 0) writeonly uniform image2D outSurface;
layout(std430, binding = 1) readonly buffer VDP2 { uint vram[]; };
 struct vdp2rotationparameter_struct{ 
 uint PlaneAddrv[16];
 float Xst;
 float Yst;
 float Zst;
 float deltaXst;
 float deltaYst;
 float deltaX;
 float deltaY;
 float A;
 float B;
 float C;
 float D;
 float E;
 float F;
 float Px;
 float Py;
 float Pz;
 float Cx;
 float Cy;
 float Cz;
 float Mx;
 float My;
 float kx;
 float ky;
 float KAst;
 float deltaKAst;
 float deltaKAx;
 uint coeftbladdr;
 int coefenab;
 int coefmode;
 int coefdatasize;
 int use_coef_for_linecolor;
 float Xp;
 float Yp;
 float dX;
 float dY;
 int screenover;
 int msb;
 uint charaddr;
 int planew, planew_bits, planeh, planeh_bits;
 int MaxH, MaxV;
 float Xsp;
 float Ysp;
 float dx;
 float dy;
 float lkx;
 float lky;
 int KtablV;
 int ShiftPaneX;
 int ShiftPaneY;
 int MskH;
 int MskV;
 uint lineaddr;
 int k_mem_type;
 uint over_pattern_name;
 int linecoefenab;
 int padding;
};
layout(std430, binding = 2) readonly buffer vdp2Param { 
  vdp2rotationparameter_struct para[2];
};
layout(std140, binding = 3) uniform  RBGDrawInfo { 
  float hres_scale; 
  float vres_scale; 
  int cellw_; 
  int cellh_; 
  uint paladdr_; 
  int pagesize; 
  int patternshift; 
  int planew; 
  int pagewh; 
  int patterndatasize; 
  uint supplementdata; 
  int auxmode; 
  int patternwh;
  uint coloroffset;
  int transparencyenable;
  int specialcolormode;
  uint specialcode;
  int colornumber;
  int window_area_mode;  uint priority;
  int startLine;
  int endLine;
  uint specialprimode;
  float alpha_lncl;
  uint lncl_table_addr;
  uint cram_mode;
};
layout(std430, binding = 5) readonly buffer VDP2C { uint cram[]; };
layout(std430, binding = 6) readonly buffer ROTW { uint  rotWin[]; };
layout(rgba8, binding = 7) writeonly uniform image2D lnclSurface;
layout(std430, binding = 8) readonly buffer ALPHA { uint  alpha[]; };
 uint specialfunction;
 uint specialcolorfunction;
 int GetKValue( int paramid, vec2 pos, out float ky, out float kx, out uint lineaddr ){ 
  uint kdata;
  int kindex = int(para[paramid].deltaKAst*pos.y)+int(para[paramid].deltaKAx*pos.x); 
  if (para[paramid].coefdatasize == 2) { 
    uint addr = ( uint( int(para[paramid].coeftbladdr) + (kindex<<1)) &0x7FFFFu); 
    if( para[paramid].k_mem_type == 0) { 
	     kdata = vram[ addr>>2 ]; 
      if( (addr & 0x02u) != 0u ) { kdata >>= 16; } 
      kdata = (((kdata) >> 8 & 0xFFu) | ((kdata) & 0xFFu) << 8);
    }else{
      if (cram_mode != 2u) addr |= 0x800u;
      kdata = cram[ (addr&0xFFFu)>>2  ]; 
      if( (addr & 0x02u) != 0u ) { kdata >>= 16; } 
    }
    if ( (kdata & 0x8000u) != 0u) { return -1; }
    float kval = 0;
	   if((kdata&0x4000u)!=0u) kval=float( int(kdata&0x7FFFu)| int(0xFFFF8000u) )/1024.0;
    else kval=float(kdata&0x7FFFu)/1024.0;
    if (para[paramid].coefmode == 0) {
			 kx = kval;
			 ky = kval;
    } else if (para[paramid].coefmode == 1) {
      kx = kval;
    } else if (para[paramid].coefmode == 2) {
      ky = kval;
    } 
  }else{
    uint addr = ( uint( int(para[paramid].coeftbladdr) + (kindex<<2))&0x7FFFFu); 
    if( para[paramid].k_mem_type == 0) { 
	     kdata = vram[ addr>>2 ]; 
      kdata = ((kdata&0xFF000000u) >> 24 | ((kdata) >> 8 & 0xFF00u) | ((kdata) & 0xFF00u) << 8 | (kdata&0x000000FFu) << 24);
    }else{
      if (cram_mode != 2u) addr |= 0x800u;
      kdata = cram[ (addr&0xFFFu)>>2 ]; 
      kdata = ((kdata&0xFFFF0000u)>>16|(kdata&0x0000FFFFu)<<16);
    }
	 if( para[paramid].linecoefenab != 0) lineaddr = (kdata >> 24) & 0x7Fu; else lineaddr = 0u;
	 if((kdata&0x80000000u)!=0u){ return -1;}
    float kval = 0;
	 if((kdata&0x00800000u)!=0u) kval=float( int(kdata&0x00FFFFFFu)| int(0xFF800000u) )/65536.0;
  else kval=float(kdata&0x00FFFFFFu)/65536.0;
    if (para[paramid].coefmode == 0) {
			 kx = kval;
			 ky = kval;
    } else if (para[paramid].coefmode == 1) {
      kx = kval;
    } else if (para[paramid].coefmode == 2) {
      ky = kval;
    } 
  }
  return 0;
 }
bool isWindowInside(uint x, uint y)
{
  uint upLx = rotWin[y] & 0xFFFFu;
  uint upRx = (rotWin[y] >> 16) & 0xFFFFu;
  // inside
  if (window_area_mode == 1)
  {
    if (rotWin[y] == 0u) return false;
    if (x >= upLx && x <= upRx)
    {
      return true;
    }
    else {
      return false;
    }
    // outside
  }
  else {
    if (rotWin[y] == 0u) return true;
    if (x < upLx) return true;
    if (x > upRx) return true;
    return false;
  }
  return false;
}
uint get_cram_msb(uint colorindex) { 
 uint shift = 1; 
	uint colorval = 0u; 
 if (cram_mode == 2u) shift = 2; 
	colorindex = ((colorindex<<shift)&0xFFFu); 
	colorval = cram[colorindex >> 2]; 
	if ((colorindex & 0x02u) != 0u) { colorval >>= 16; } 
	return (colorval & 0x8000u); 
}
 vec4 vdp2color(uint alpha_, uint prio, uint cc_on, uint index) {
 uint ret = (((alpha_ & 0xF8u) | prio) << 24 | ((cc_on & 0x1u)<<16) | (index& 0xFEFFFFu));
 return vec4(float((ret >> 0)&0xFFu)/255.0,float((ret >> 8)&0xFFu)/255.0, float((ret >> 16)&0xFFu)/255.0, float((ret >> 24)&0xFFu)/255.0);
}
int PixelIsSpecialPriority( uint specialcode, uint dot ) { 
  dot &= 0xfu; 
  if ( (specialcode & 0x01u) != 0u && (dot == 0u || dot == 1u) ){ return 1;} 
  if ( (specialcode & 0x02u) != 0u && (dot == 2u || dot == 3u) ){ return 1;} 
  if ( (specialcode & 0x04u) != 0u && (dot == 4u || dot == 5u) ){ return 1;} 
  if ( (specialcode & 0x08u) != 0u && (dot == 6u || dot == 7u) ){ return 1;} 
  if ( (specialcode & 0x10u) != 0u && (dot == 8u || dot == 9u) ){ return 1;} 
  if ( (specialcode & 0x20u) != 0u && (dot == 0xau || dot == 0xbu) ){ return 1;} 
  if ( (specialcode & 0x40u) != 0u && (dot == 0xcu || dot == 0xdu) ){ return 1;} 
  if ( (specialcode & 0x80u) != 0u && (dot == 0xeu || dot == 0xfu) ){ return 1;} 
  return 0; 
} 
uint Vdp2SetSpecialPriority(uint dot) {
  uint prio = priority;
  if (specialprimode == 2u) {
    prio = priority & 0xEu;
    if ((specialfunction & 1u) != 0u) {
      if (PixelIsSpecialPriority(specialcode, dot) != 0u)
      {
        prio |= 1u;
      }
    }
  }
  if (specialprimode == 1u) {
		prio = (priority & 0xEu) | specialfunction;
  }
	return prio;
}
uint setCCOn(uint index, uint dot) {
    uint cc_ = 1u;
    switch (specialcolormode)
    {
    case 1:
      if (specialcolorfunction == 0) { cc_ = 0; } break;
    case 2:
      if (specialcolorfunction == 0) { cc_ = 0; }
      else { if ((specialcode & (1u << ((dot & 0xFu) >> 1))) == 0u) { cc_ = 0; } } 
      break; 
    case 3:
	   if (get_cram_msb(index) == 0u) { cc_ = 0; }
	   break;
    }
    return cc_;
}
vec4 Vdp2ColorRamGetColorOffset(uint offset) { 
  uint flag = 0x380u;
  if (cram_mode == 1u) flag = 0x780u;
  uint index = ((((lncl_table_addr&flag) | (offset&0x7Fu))<<1u)&0xFFFu);
  uint temp = (cram[index>>2]);
  if( (index & 0x02u) != 0u ) { temp >>= 16; } 
  return vec4(float((temp >> 0) &0x1F)/31.0, float((temp >> 5) & 0x1Fu)/31.0, float((temp >> 10) &0x1F)/31.0,alpha_lncl);
}
void main(){ 
  int x, y;
  int paramid = 0;
  int cellw;
  uint paladdr; 
  uint charaddr; 
  uint lineaddr = 0u; 
  float ky; 
  float kx; 
  uint kdata;
  uint cc = 1u;
  int discarded = 0;
  uint priority_ = priority;
  uint patternname = 0xFFFFFFFFu;
  ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
  ivec2 size = imageSize(outSurface);
  if (texel.x >= size.x || texel.y >= size.y ) return;
  if (texel.y < (startLine * vres_scale) || texel.y >= (endLine * vres_scale) ) return;
  vec2 pos = vec2(texel) / vec2(hres_scale, vres_scale);
  vec2 original_pos = floor(vec2(texel) / vec2(hres_scale, vres_scale));
//prg_get_param_mode03
  if( isWindowInside( uint(pos.x), uint(pos.y) ) ) {     paramid = 0; 
    if( para[paramid].coefenab != 0 ){ 
      if( GetKValue(paramid,pos,ky,kx,lineaddr ) == -1 ) { 
        paramid=1;
        if( para[paramid].coefenab != 0 ){ 
          if( GetKValue(paramid,pos,ky,kx,lineaddr ) == -1 ) { 
            if ( para[paramid].linecoefenab != 0) imageStore(lnclSurface,texel,Vdp2ColorRamGetColorOffset(lineaddr));
             imageStore(lnclSurface,texel,vec4(0.0));
   	       imageStore(outSurface,texel,vec4(0.0)); return;} 
          }else{ 
            ky = para[paramid].ky; 
            kx = para[paramid].kx; 
            lineaddr = para[paramid].lineaddr; 
          }
        }
      }else{
        ky = para[paramid].ky; 
        kx = para[paramid].kx; 
        lineaddr = para[paramid].lineaddr; 
      }
    }else{
      paramid = 1; 
      if( para[paramid].coefenab != 0 ){ 
        if( GetKValue(paramid,pos,ky,kx,lineaddr ) == -1 ) { 
          paramid=0;
          if( para[paramid].coefenab != 0 ){ 
            if( GetKValue(paramid,pos,ky,kx,lineaddr ) == -1 ) { 
              if ( para[paramid].linecoefenab != 0) imageStore(lnclSurface,texel,Vdp2ColorRamGetColorOffset(lineaddr));
              else imageStore(lnclSurface,texel,vec4(0.0));
   	         imageStore(outSurface,texel,vec4(0.0)); return;
            } 
          }else{ 
            ky = para[paramid].ky; 
            kx = para[paramid].kx; 
            lineaddr = para[paramid].lineaddr; 
          }
        }
      }else{
        ky = para[paramid].ky; 
        kx = para[paramid].kx; 
        lineaddr = para[paramid].lineaddr; 
      }
   }
//prg_rbg_xy
  float Xsp = para[paramid].A * ((para[paramid].Xst + para[paramid].deltaXst * original_pos.y) - para[paramid].Px) +
  para[paramid].B * ((para[paramid].Yst + para[paramid].deltaYst * original_pos.y) - para[paramid].Py) +
  para[paramid].C * (para[paramid].Zst - para[paramid].Pz);
  float Ysp = para[paramid].D * ((para[paramid].Xst + para[paramid].deltaXst *original_pos.y) - para[paramid].Px) +
  para[paramid].E * ((para[paramid].Yst + para[paramid].deltaYst * original_pos.y) - para[paramid].Py) +
  para[paramid].F * (para[paramid].Zst - para[paramid].Pz);
  float fh = floor(kx * (Xsp + para[paramid].dx * original_pos.x) + para[paramid].Xp);
  float fv = floor(ky * (Ysp + para[paramid].dy * original_pos.x) + para[paramid].Yp);
//prg_rbg_overmode_repeat
  switch( para[paramid].screenover){ 
   case 0: // OVERMODE_REPEAT 
    x = int(fh) & (para[paramid].MaxH-1);
    y = int(fv) & (para[paramid].MaxV-1);
    break;
  case 1: // OVERMODE_SELPATNAME 
    if ((fh < 0.0) || (fh > float(para[paramid].MaxH)) || (fv < 0.0) || (fv > float(para[paramid].MaxV)) ) {
        patternname = para[paramid].over_pattern_name;
    }    x = int(fh);
    y = int(fv);
    break;
  case 2: // OVERMODE_TRANSE 
    if ((fh < 0.0) || (fh > float(para[paramid].MaxH) ) || (fv < 0.0) || (fv > float(para[paramid].MaxV)) ) {
     if ( para[paramid].linecoefenab != 0) imageStore(lnclSurface,texel,Vdp2ColorRamGetColorOffset(lineaddr));
     else imageStore(lnclSurface,texel,vec4(0.0));
   	imageStore(outSurface,texel,vec4(0.0)); 
     return; 
    }
    x = int(fh);
    y = int(fv);
    break;
  case 3: // OVERMODE_512 
    if ((fh < 0.0) || (fh > 512.0) || (fv < 0.0) || (fv > 512.0)) {
     if ( para[paramid].linecoefenab != 0) imageStore(lnclSurface,texel,Vdp2ColorRamGetColorOffset(lineaddr));
     else imageStore(lnclSurface,texel,vec4(0.0));
   	imageStore(outSurface,texel,vec4(0.0)); 
     return; 
    }
    x = int(fh);
    y = int(fv);
    break;
   }
//prg_rbg_get_patternaddr
  int planenum = (x >> para[paramid].ShiftPaneX) + ((y >> para[paramid].ShiftPaneY) << 2);
  x &= (para[paramid].MskH);
  y &= (para[paramid].MskV);
  uint addr = para[paramid].PlaneAddrv[planenum];
  addr += uint( (((y >> 9) * pagesize * planew) + 
  ((x >> 9) * pagesize) + 
  (((y & 511) >> patternshift) * pagewh) + 
  ((x & 511) >> patternshift)) << patterndatasize ); 
  addr &= 0x7FFFFu;
//prg_rbg_get_pattern_data_2w
  patternname = vram[addr>>2]; 
  uint tmp1 = patternname & 0x7FFFu; 
  charaddr = patternname >> 16; 
  charaddr = (((charaddr >> 8) & 0xFFu) | ((charaddr) & 0xFFu) << 8);
  tmp1 = (((tmp1 >> 8) & 0xFFu) | ((tmp1) & 0xFFu) << 8);
  uint flipfunction = (tmp1 & 0xC000u) >> 14;
  if(colornumber==0) paladdr = tmp1 & 0x7Fu; else paladdr = tmp1 & 0x70u;
  specialfunction = (tmp1 & 0x2000u) >> 13;
  specialcolorfunction = (tmp1 & 0x1000u) >> 12;
  charaddr &= 0x3FFFu;
  charaddr *= 0x20u;
//prg_rbg_get_charaddr
  cellw = 8; 
  if (patternwh == 1) { 
    x &= 0x07;
    y &= 0x07;
    if ( (flipfunction & 0x2u) != 0u ) y = 7 - y;
    if ( (flipfunction & 0x1u) != 0u ) x = 7 - x;
  }else{
    if (flipfunction != 0u) { 
      y &= 16 - 1;
      if ( (flipfunction & 0x2u) != 0u ) {
        if ( (y & 8) == 0 ) {
          y = 8 - 1 - y + 16;
        }else{ 
          y = 16 - 1 - y;
        }
      } else if ( (y & 8) != 0 ) { 
        y += 8; 
      }
      if ((flipfunction & 0x1u) != 0u ) {
        if ( (x & 8) == 0 ) y += 8;
        x &= 8 - 1;
        x = 8 - 1 - x;
      } else if ( (x & 8) != 0 ) {
        y += 8;
        x &= 8 - 1;
      } else {
        x &= 8 - 1;
      }
    }else{
      y &= 16 - 1;
      if ( (y & 8) != 0 ) y += 8;
      if ( (x & 8) != 0 ) y += 8;
      x &= 8 - 1;
    }
  }
//prg_rbg_getcolor_8bpp
  uint dot = 0u;
  uint cramindex = 0u;
  uint dotaddr = (charaddr + uint((y*cellw)+x))&0x7FFFFu;
  dot = vram[ dotaddr >> 2];
  if( (dotaddr & 0x3u) == 0u ) dot >>= 0;
  else if( (dotaddr & 0x3u) == 1u ) dot >>= 8;
  else if( (dotaddr & 0x3u) == 2u ) dot >>= 16;
  else if( (dotaddr & 0x3u) == 3u ) dot >>= 24;
  dot = dot & 0xFFu; 
  if ( dot == 0u && transparencyenable != 0 ) { 
    discarded = 1; 
  } else {
    cramindex = (coloroffset + ((paladdr << 4) | dot));
    priority_ = Vdp2SetSpecialPriority(dot);
    cc = setCCOn(cramindex, dot);
  }
  if ( para[paramid].linecoefenab != 0) imageStore(lnclSurface,texel,Vdp2ColorRamGetColorOffset(lineaddr));
  else imageStore(lnclSurface,texel,vec4(0.0));
  if (discarded != 0) imageStore(outSurface,texel,vec4(0.0));
  else imageStore(outSurface,texel,vdp2color(alpha[int(original_pos.y)], priority_, cc, cramindex));
}

@FCare
Copy link
Owner

FCare commented Aug 27, 2024

En 2.5.0 le rendu logiciel etait actif

@FCare FCare pinned this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants