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!

Black borders on contour textures?

Postby HarryTuttle » Sun Jul 01, 2018 1:36 pm

Hi all!

Finally after over a 5 months hiatus I've been able to spend some time with Supermodel, I was still at r712. The current transparent texture compositing mechanism (great work Ian !) is near perfect, but I found that with 1-bit alpha (contour) textures there is a black border in the area where opaque textures blend toward transparency (due to bilinear filtering).

In the official build the problem seems to be absent, in my build however it shows up like this:
harley_00.jpeg
harley_00.jpeg (243.61 KiB) Viewed 592 times

Probably because my dilate texel effect on contour textures (which I *still* have to submit to Ian) accentuate the issue. Anyway this simple modification to the AllocShaderBase function in <R3DFrameBuffers.cpp> fixes all:
Code: Select all
if(colBase.a == 0.0) discard;

harley_01.jpeg
harley_01.jpeg (232.84 KiB) Viewed 592 times

This way texels are discarded only when are fully transparent and not halfway. Tested also with official build and doesn't cause any problem.

Ian, can you give a look also? :)

Here's the fix:
Attachments
diff_00.zip
(769 Bytes) Downloaded 30 times
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Sun Jul 01, 2018 1:52 pm

Welcome back :)
Sure will check out your patch as soon as I'm back to my pc.
I noticed in the official build the bus at beginning of the attract mode in eca looks a little broken around the wheels, needs your pixel dilate code :)
Ian
 
Posts: 1499
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby YoYo09 » Sun Jul 01, 2018 5:06 pm

Harry Welcome back. :D
flat polygon Specular Highlight support is also expect.
YoYo09
 
Posts: 64
Joined: Mon Nov 28, 2016 7:43 pm

Re: Black borders on contour textures?

Postby Ian » Mon Jul 02, 2018 12:42 am

Code: Select all
if(colBase.a == 0.0) discard;


If we do this we are going to double render a lot of the pixels, since semi transparent pixels will appear on the opaque render target. Not sure if that will have any negative side effects.
Ian
 
Posts: 1499
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Mon Jul 02, 2018 2:53 am

Ian wrote:since semi transparent pixels will appear on the opaque render target.


Yeah, that's the intended behavior, at least with alpha test textures, since they're basically opaque polygons with a 1-bit alpha channel texture. With bilinear filtering the transition from opaque to transparent is not abrupt, but there is an intermediate phase.
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby HarryTuttle » Mon Jul 02, 2018 3:01 am

YoYo09 wrote:Harry Welcome back. :D
flat polygon Specular Highlight support is also expect.


Hi YoYo09! :)

I was working on that, last year. Unfortunately is not an easy task, it seems that the coefficients I use for smoothed polys are just wrong for flat ones. And I suspect that Real3D uses an additional light vector in the mix for those, but is only a theory.

Also, differently from last year I'm very busy with real life & work issues that grab a lot of time and priority from my free time, so my participation on Supermodel is currently extremely limited. :(
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Mon Jul 02, 2018 3:45 am

Yeah, that's the intended behavior, at least with alpha test textures,

Yeah I agree there, but I was more concerned about textures with transparency :)
Maybe we should be forcing the alpha to be 0 or 1 in the fragment shader for contour textures?
Ian
 
Posts: 1499
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Mon Jul 02, 2018 9:38 am

Ian wrote:Yeah I agree there, but I was more concerned about textures with transparency :)
Maybe we should be forcing the alpha to be 0 or 1 in the fragment shader for contour textures?


If I understood your code it's the AllocShaderTrans function that deals with transparent textures. Alpha test ones (type 0) are treated as opaque when their base polygon is opaque. You see in the global fragment shader (I use an external custom one) alpha test textures are cut when their alpha channel is lower than 0.5 to approximate the SetContourThreshold function, the end result is a fully opaque poly/texture which is cut abruptly at a certain point. In my build the situation is a bit more complex due to the dilate texel filter.

If we force their alpha channel to be 0 or 1 we just render them incorrectly, right? Or do you mean to transfer the computation to the AllocShaderBase function inside <R3DFrameBuffers.cpp>? And what about contour texture type 1-4 (= 8-11) ?

Anyway from a performance standing point I didn't see any regression. Consider that my GPU is archaic.
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Re: Black borders on contour textures?

Postby Ian » Mon Jul 02, 2018 11:16 am

Just had to have a look at the shader code to remind me of what was happening

Currently ..
Contour textures are rendered as opaque, and transparent pixels are discarded. The remaining pixels higher than the contour threshold are forced as 1.0 alpha

Code: Select all
   if (textureAlpha == false) {
      tex1Data.a = 1.0;
   }


The code shouldn't write any translucent pixels at all. So the contour path shouldn't write to the alpha layer 1 or 2 at all. Maybe you can put a discard statement in your dilate function for the edge pixels? I haven't seen this code so I'm sorta stabbing in the dark here :)

Also I put in an older AMD card .. will have a go at fixing this ocean hunter thing. Hopefully it's not a driver bug :p
Ian
 
Posts: 1499
Joined: Tue Feb 23, 2016 9:23 am

Re: Black borders on contour textures?

Postby HarryTuttle » Mon Jul 02, 2018 2:38 pm

Ian wrote:The code shouldn't write any translucent pixels at all. So the contour path shouldn't write to the alpha layer 1 or 2 at all. Maybe you can put a discard statement in your dilate function for the edge pixels? I haven't seen this code so I'm sorta stabbing in the dark here :)


Yeah, actually it's what I meant: AllocShaderBase, if I understood correctly, renders opaque pixels (and contour textures), that's why I modified the check inside that function. I didn't touch AllocShaderTrans function.

Regarding my dilate function: besides what I do with rgb data, the alpha channel is cut the same way as the official build, I just use a more relaxed threshold (32/255 instead of 8/16). As a side note, I noticed the former is more close to the arcade, especially for polygons with foliage textures.
User avatar
HarryTuttle
 
Posts: 646
Joined: Thu Mar 09, 2017 8:57 am

Next

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest