Black borders on contour textures?

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!

Re: Black borders on contour textures?

Postby Ian » Tue Jul 03, 2018 12:26 am

The current code works because it only writes fully opaque pixels, ie with alpha of 255
Why are you writing pixels with values greater than 0 but less than 255 to the colour buffer ? :)

If you explicitly set the semi transparent pixels to have an alpha of 1.0 or 255 in r3dshader, surely everything should work as expected?
Ian
 
Posts: 1468
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Tue Jul 03, 2018 9:04 am

Ian wrote:hy are you writing pixels with values greater than 0 but less than 255 to the colour buffer ? :)

If you explicitly set the semi transparent pixels to have an alpha of 1.0 or 255 in r3dshader, surely everything should work as expected?


Ok Ian, thanks for the hint, finally I sorted this out! :)

This is what was happening: in fragment shader, after the texture border cut based on a given threshold value, I didn't force the remaining texels' alpha channel to 1.0 for alpha test textures. So I wrote less-than-1 alpha channel data in the color buffer (due to bilinear filter the transition between 1 and 0 alpha is not abrupt). Now I fixed this with a last check to the remaining, after the cut, texels and forced their value to 1 only for alpha test textures.

This was a sneaky and elusive bug in my build because, before r733, in RenderScene function GL_BLEND state was disabled for opaque textures (so even alpha test); the end result was more "forgiving". As if non discarded texels' alpha value was being ignored, so I couldn't notice. ;)
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Tue Jul 03, 2018 11:09 am

Glad you got it sorted :)
The contour texturing thing on the model3 is weird. Never seen anything like that on other hardware before.
Ian
 
Posts: 1468
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby Bart » Wed Jul 04, 2018 12:43 pm

What's the deal with contour textures anyway? How is the threshold for blended alpha values that fall between 0 and 1 determined?
User avatar
Bart
Site Admin
 
Posts: 2178
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: Black borders on contour textures?

Postby HarryTuttle » Wed Jul 04, 2018 1:50 pm

Hi Bart!

Bart wrote:What's the deal with contour textures anyway? How is the threshold for blended alpha values that fall between 0 and 1 determined?


Theorically it should be set by SetContourThreshold command (see DevGuide), but we don't know where this value is/should be stored. It doesn't seem to be present in any node/model/texture attribute.

I've found empirically that a threshold value of 32/255 (better with the use of a dilate pixel filter) gives an almost model3-like result in every game, at least with every contour texture I've looked at. Obviously we need to do the computation in fragment shader and discard the texels under that threshold.

Offtopic:
Code: Select all
Copyright 2011-2018 by Bart Trzynadlowski, Nik Henson, Ian Curtis,
                       Harry Tuttle, and Spindizzi

Thanks for the inclusion, I really appreciate that. :)
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Wed Jul 04, 2018 3:12 pm

Thanks for the inclusion, I really appreciate that.

:) Well you made some pretty significant contributions. Stuff I probably never would have figured out!

Theorically it should be set by SetContourThreshold command (see DevGuide), but we don't know where this value is/should be stored.

It's just set client side when processing the textures before they are sent to the hardware. So it won't appear in any culling node or whatever. The same as having a library processing textures before uploading them to opengl.
Ian
 
Posts: 1468
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Wed Jul 04, 2018 3:19 pm

Ian wrote:It's just set client side when processing the textures before they are sent to the hardware. So it won't appear in any culling node or whatever. The same as having a library processing textures before uploading them to opengl.


Yeah, now I remember that you've disassembled a lot of related functions last year. You've even sent to me those... :)

If you're really sure about this that's good news because it means the cut threshold for contour textures is a fixed, hardcoded value and I think I've found it.
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Wed Jul 04, 2018 3:22 pm

I'll see if i can dig out exactly where it is set in the api
Ian
 
Posts: 1468
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby Ian » Wed Jul 04, 2018 3:26 pm

Code: Select all
void __thiscall PRO_Texture::SetContourThreshold(PRO_Texture *this, __int32 a2)
{
  __int32 v2; // eax@1

  v2 = a2;
  if ( a2 >= 1 )
  {
    if ( a2 > 254 )
      v2 = 254;
    *((_DWORD *)this + 15) = v2;
  }
  else
  {
    *((_DWORD *)this + 15) = 1;
  }
}


Just sets the threshold

Code: Select all
unsigned __int16 __cdecl getPackedTexel5551(struct PRO_Texture *a1, __int32 a2)
{
  return (unsigned __int8)(*(_BYTE *)(*((_DWORD *)a1 + 13) + a2) >> 3) | (unsigned __int16)(4
                                                                                          * ((unsigned __int8)(*(_BYTE *)(*((_DWORD *)a1 + 12) + a2) & 0xF8) | (unsigned __int16)(32 * ((unsigned __int8)(*(_BYTE *)(*((_DWORD *)a1 + 11) + a2) & 0xF8) | (unsigned __int16)(((unsigned int)*(_BYTE *)(*((_DWORD *)a1 + 14) + a2) < *((_DWORD *)a1 + 15)) << 8)))));
}


If you can get past the decompiled ugliness
this + 15 is where the threshold value is stored.

in the function it's doing
if value < thresholdValue

So it's all done client side.
Ian
 
Posts: 1468
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Wed Jul 04, 2018 3:29 pm

Excellent! :)

One less thing to worry about.
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Previous

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest