Page 2 of 2

Re: Black borders on contour textures?

PostPosted: Tue Jul 03, 2018 12:26 am
by Ian
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?

Re: Black borders on contour textures?

PostPosted: Tue Jul 03, 2018 9:04 am
by HarryTuttle
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. ;)

Re: Black borders on contour textures?

PostPosted: Tue Jul 03, 2018 11:09 am
by Ian
Glad you got it sorted :)
The contour texturing thing on the model3 is weird. Never seen anything like that on other hardware before.

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 12:43 pm
by Bart
What's the deal with contour textures anyway? How is the threshold for blended alpha values that fall between 0 and 1 determined?

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 1:50 pm
by HarryTuttle
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. :)

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 3:12 pm
by Ian
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.

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 3:19 pm
by HarryTuttle
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.

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 3:22 pm
by Ian
I'll see if i can dig out exactly where it is set in the api

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 3:26 pm
by Ian
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.

Re: Black borders on contour textures?

PostPosted: Wed Jul 04, 2018 3:29 pm
by HarryTuttle
Excellent! :)

One less thing to worry about.