Translucency, Stipple, and Stencil

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Translucency, Stipple, and Stencil

Postby Bart » Mon May 30, 2016 10:25 am

I wanted to move this discussion out of the general forum because I lose track. Ian, you had provided me with this decompilation of the PRO_Polygon::APISetTranslucencyPatternSelect() function:

Code: Select all
void __thiscall PRO_Polygon::APISetTranslucencyPatternSelect(PRO_Polygon *this, __int32 a2)
{
  if ( !(*((_BYTE *)this + 83) & 2) )
    *((_DWORD *)this + 6) ^= (*((_DWORD *)this + 6) ^ (a2 << 17)) & 0x20000;
}


Here is what it is actually doing:

Code: Select all
void PRO_Polygon::APISetTranslucencyPatternSelect(long pattern)
{
  if (_user_xlu_pattern_select)
    _hw_polygon._mcw2._translucency_pattern_select = pattern & 1;
}


There is a bit field at the very end of the object that is used by the API that holds API-level state information. These bits can affect how the hardware polygon is formatted. In this case, _user_xlu_pattern_select doesn't look like anything too special, although I wonder why they even make that configurable. My guess is that it's safe to assume that when polygons are translucent, the pattern can be freely changed except in some specific case where perhaps the API creates translucent polygons internally and wants to enforce a specific pattern.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Translucency, Stipple, and Stencil

Postby Ian » Mon May 30, 2016 12:50 pm

I wonder if this bitfield actually exists in polygon or other memory
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: Translucency, Stipple, and Stencil

Postby Bart » Mon May 30, 2016 12:59 pm

Ian wrote:I wonder if this bitfield actually exists in polygon or other memory


Only the PRO_HW_Polygon is copied to the Pro-1000. That bit field is lost and almost certainly never existed on the Model 3, which mostly uses pre-formatted models (rather than building them on the fly via an API like this). This is just book-keeping for the Windows-hosted code.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Translucency, Stipple, and Stencil

Postby Ian » Mon May 30, 2016 1:00 pm

I'm still puzzled my stipple alpha. You can't have normal alpha transparency, and alpha, there must be something to toggle between the two
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: Translucency, Stipple, and Stencil

Postby Bart » Mon May 30, 2016 1:06 pm

Ian wrote:I'm still puzzled my stipple alpha. You can't have normal alpha transparency, and alpha, there must be something to toggle between the two


What do you mean? The case where alpha textures are used along with polygon translucency? I don't see why you can't have both. The rasterizer presumably implements stipple by skipping pixels under the control of some mask function indexed by screen X and Y coordinate. This would be done just prior to writing the pixel to the frame buffer.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Translucency, Stipple, and Stencil

Postby Ian » Mon May 30, 2016 1:41 pm

Well, technically you can have both. But the whole point of stipple alpha is you don't need real transparency :p

This is quake2 stipple alpha transparency. There is no alpha blending going on here at all

Image

Closeup of da pixels :p

Image

If you actually applied any kind of real alpha blending to the remaining pixels you'd be hard pressed to see the transparent surface at all :p
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: Translucency, Stipple, and Stencil

Postby Bart » Mon May 30, 2016 3:47 pm

How often do translucent polygons also have alpha textures? I vaguely recall the manual saying that this was possible and that the translucency levels are effectively multiplied. If you had a 50% stipple pattern and another 50% texture alpha, the result should look similar to 25% alpha, I imagine.

My guess is that stipple is probably not intended to be used with alpha textures but that the hardware considers these orthogonal, unrelated settings and just does what it's told. I can think of two reasons why they would continue to support stipple: 1) alpha blending was probably very costly back then because it required reading the frame buffer. There may have been a need for very large translucent objects (e.g., water), and stipple is a cheap way to do it. 2) The database driven nature of the hardware probably made it cumbersome to sort objects by depth. This provides an easy alternative.

The bigger question in my mind is why I've never noticed a stipple pattern on the actual system. Could anti-aliasing have smoothed it out?
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Translucency, Stipple, and Stencil

Postby Ian » Mon May 30, 2016 4:21 pm

I am guessing .. it was only used for shadows in games. If you stipple the shadows, suddenly all the Z fighting problems are gone. I think everything else was just alpha blended.
Stipple doesn't actually look that bad, it looks horrible in quake because it has no texturing filtering at all (the software renderer anyway).
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: Translucency, Stipple, and Stencil

Postby Ian » Mon May 30, 2016 4:23 pm

If you check out this image

Image

The middle pattern is how I guess shadows are being drawn on the model3. You almost can't see the pattern at all
Ian
 
Posts: 2044
Joined: Tue Feb 23, 2016 9:23 am

Re: Translucency, Stipple, and Stencil

Postby Bart » Mon May 30, 2016 6:54 pm

Ian wrote:If you check out this image

Image

The middle pattern is how I guess shadows are being drawn on the model3. You almost can't see the pattern at all


Err, which middle pattern? The third from left?
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Next

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest

cron