OpenArena Message Boards

OpenArena Contributions => Development => Topic started by: fromhell on March 23, 2012, 08:40:34 AM



Title: PowerVR PCX2 support (need shader pre-parsing help)
Post by: fromhell on March 23, 2012, 08:40:34 AM
Here's a fun waste of time i've been having to get some obscure 1997 killed-by-3dfx card to work.  ;D

PCX1/2 have no blendFunc. It always blends everything as an alpha whether you like it or not.  To 'simulate' how a PCX2 behaves (http://www.youtube.com/watch?v=mDAWa6bVt2M), just have this in GL_State
Code:
			default:
dstFactor = GL_ONE; // to get warning to shut up
ri.Error( ERR_DROP, "GL_State: invalid dst blend state bits\n" );
break;
}
                srcFactor = GL_SRC_ALPHA; dstFactor = GL_ONE_MINUS_SRC_ALPHA; } // for pvr debug only!

qglEnable( GL_BLEND );
qglBlendFunc( srcFactor, dstFactor );
}
else
{
qglDisable( GL_BLEND );
}
}

I'm currently hacking in a weird method to force control alpha channels on textures. However, this is difficult as shaders are read in sequence. Right now my current method is an 'alphahack' command like


Code:
thisisashader
{
     cull disable
        {
          //PCXHACK alphahack add // Generate alpha channel from averaging RGB
          map models/weapons2/thisisagun/bang.jpg
          blendFunc add
        }
}
         
For more compatibility i'd like to parse blendFunc add BEFORE THE TEXTURE GETS UPLOADED so I can tell the Upload32 function that this texture is used in a fashion where it is blended additively so it can generate an alpha channel for a card that doesn't support it. I actually already did the parts of generating/demoting alphas, etc by telling it with the alphahack command (where it would then be marked in a new field in texture_t, in the bundle, and be carried all the way to upload32). I just can't seem to do any shader pre-parsing to get a lot of the existing work cut out.

I'll post a diff later, as it's currently a mess. It also appears IoQ3 got rid of the whole GLHW_ detection and compatibility mode setting for some dumb reason, along with r_glDriver (which is necessary for pointing to minigl wrappers)


it's also possible that this work can lead to optimizing  the game for a "fast-and-dirty" software renderer, if there's anyone ever brave enough to make one. Doing these PCX2 hack fixes makes me want to do Mystique hack fixes (adjust alpha threshhold, GT0'ing everything) and Rage hack fixes (GT128ing everything, additiving a few alphas).

I have a lot of faith in getting this card to work good. I've compared performance of Angelyss's highest LOD (13fps) to OA3's Sorceress' highest LOD (31fps), at 1024x768x16 with r_drawworld 0 so the future is certainly looking bright for performance.


Title: Re: PowerVR PCX2 support (need shader pre-parsing help)
Post by: andrewj on March 23, 2012, 10:42:42 PM
For more compatibility i'd like to parse blendFunc add BEFORE THE TEXTURE GETS UPLOADED

I think the easiest way to do that is : give ParseStage() an extra parameter 'load_images', and call ParseStage twice on the same text (first time with load_images as false, second time as true).

Then in ParseStage code, handle the "map" (etc) commands normally but don't call R_FindImageFile() unless load_images is true.  At that time you will know the blendfunc (due to previous call to ParseStage) and can pass extra info to R_FindImageFile.


Title: Re: PowerVR PCX2 support (need shader pre-parsing help)
Post by: fromhell on March 27, 2012, 04:53:25 PM
Did your suggestion but it seemed to have broke every shader instead. I couldn't read the console even.

I'll try doing it as a copy of the ParseStage function with the actual token parsing all replaced by SkipWholeLines until it hits Blendfunc then it can set the alphahack flag in that stage bundle