[Patch] MicroTexture

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: [Patch] MicroTexture

Postby ConversusVans » Mon Mar 13, 2017 10:51 am

Doesn't Harley use microtextures? I have a feeling that game does use them in the Beverly Hills fountain area and the UFO dome area of Hollywood. I haven't played the real deal for a while, though.

BTW, pleased to meet you Harry! Great contributions :)
- Conversus W. Vans (Paul)
User avatar
ConversusVans
 
Posts: 176
Joined: Sun Apr 27, 2014 3:27 pm
Location: The Abandoned Land

Re: [Patch] MicroTexture

Postby HarryTuttle » Mon Mar 13, 2017 11:34 am

ConversusVans wrote:Doesn't Harley use microtextures? I have a feeling that game does use them in the Beverly Hills fountain area and the UFO dome area of Hollywood.

I'll check later.

Edit: checked the fountain and no, it has no microTex. Don't know about the UFO since I've not been able to get there.
---------------------------------------------
Ian, before switching to FixedShading I'd like to put the "Case Closed" stamp on the microTexture thing, so here's the last piece of the puzzle or "the cherry on the cake": Linear fading of microTexture.

Analyzing high quality footage is clear that at some distant point microTextures fade away revealing the underneath base-texture. That point is LOD=1 and, obviously, the distance at which is displayed depends also on the polygon angle in respect of the camera.

So in the fragment shader I've "implemented" (= copied from the net :P ), a GPU-independent mipmapping LOD bias mechanism for microTextures, and blended them with base-textures with opacity 0.5 (@ LOD=0) to 0.0 (@ LOD=1). In the following posts I'll add some screenshot because a picture is better than a thousand words...

This is the fragment pseudo-code:
Code: Select all
// https://www.opengl.org/discussion_boards/showthread.php/177520-Mipmap-level-calculation-using-dFdx-dFdy
float getMipLevel(in vec2 coord, in const sampler2D tex) // in texel units
{
  vec2 texSize = textureSize(tex, 0); // get the size of LOD 0
  coord = coord * texSize;
  vec2 dx_vtc = dFdx(coord);
  vec2 dy_vtc = dFdy(coord);
  float delta_max_sqr = max(dot(dx_vtc, dx_vtc), dot(dy_vtc, dy_vtc));
  float mml = max(0.0, 0.5 * log2(delta_max_sqr) - 1.0); // == log2(sqrt(delta_max_sqr));
  return mml;
}

float lod, lodBias, blendFactor;

lodBias = -1.0;
lod = getMipLevel(vs.coord.st, tex1) + lodBias; // tex1 is the base-texture
lod = max(0.0, lod);
lod = min(5.0, lod);

blendFactor = min(one, 0.5 + lod * 0.5);

finalTexture.rgb = mix(microTexture.rgb, baseTexture.rgb, blendFactor);
Last edited by HarryTuttle on Mon Mar 13, 2017 1:34 pm, edited 1 time in total.
User avatar
HarryTuttle
 
Posts: 299
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] MicroTexture

Postby Ian » Mon Mar 13, 2017 12:40 pm

Show some pics :)
The fade might simply be due to mipmapping alone?
It's odd there are only 6 mipmap levels. Wonder if more exist but are not written to memory
Ian
 
Posts: 844
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] MicroTexture

Postby Ian » Mon Mar 13, 2017 1:06 pm

I should probably add, you will see exactly this without an-isotrophic filtering
Image
Ian
 
Posts: 844
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] MicroTexture

Postby HarryTuttle » Mon Mar 13, 2017 1:24 pm

Ian wrote:I should probably add, you will see exactly this without an-isotrophic filtering
Image


To try to match the arcade in my build base-textures are sampled with these parameters in <Texture.cpp>:
Code: Select all
maxAnistrophy = 1.0f; // Disable anisotropic filtering
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -2.2f);


Microtextures bypass above LOD_BIAS in fragment shader.

This is without microTexture fading:
scud11.png
Supermodel
scud11.png (92.31 KiB) Viewed 274 times


With fading:
scud12.png
Supermodel
scud12.png (79.88 KiB) Viewed 274 times


Reference:
scud13.png
Arcade PCB
scud13.png (90.69 KiB) Viewed 274 times
User avatar
HarryTuttle
 
Posts: 299
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] MicroTexture

Postby HarryTuttle » Mon Mar 13, 2017 1:43 pm

And now with pure tri-linear and no LOD offset in <Texture.cpp>

Without fading:
scud15.png
Fading OFF
scud15.png (80.81 KiB) Viewed 266 times


With fading:
scud14.png
Fading ON
scud14.png (77.14 KiB) Viewed 266 times


Notice how the road appears from the checkered road texture onward.
User avatar
HarryTuttle
 
Posts: 299
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] MicroTexture

Postby Ian » Mon Mar 13, 2017 1:44 pm

The microtextures make the white lines sort of fuzzy in colour. They should become whiter and clearer if they faded out. Will have a proper look when I'm not on my phone
Ian
 
Posts: 844
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] MicroTexture

Postby HarryTuttle » Mon Mar 13, 2017 1:49 pm

Ok :)

The effect anyway it's more visible and clear when watching videos, because you'll see better the transition between detailed and plain textures.
User avatar
HarryTuttle
 
Posts: 299
Joined: Thu Mar 09, 2017 8:57 am

Re: [Patch] MicroTexture

Postby Ian » Mon Mar 13, 2017 1:52 pm

The reference image is kind of odd. Looks like anisotrophic filtering, the lines remain sharp. Maybe the microtextures don't use this
Ian
 
Posts: 844
Joined: Tue Feb 23, 2016 9:23 am

Re: [Patch] MicroTexture

Postby HarryTuttle » Mon Mar 13, 2017 2:06 pm

Ian wrote:The reference image is kind of odd. Looks like anisotrophic filtering, the lines remain sharp. Maybe the microtextures don't use this


I'll try with "maxAnistrophy = 2.0" and/or different LODBias. Anyway below are another bunch of screenshots.

Reference:
scud16.png
Arcade PCB
scud16.png (75.63 KiB) Viewed 258 times


Supermodel:
scud17.png
Supermodel
scud17.png (67.2 KiB) Viewed 258 times


And now with fade levels marked:
scud18.png
Supermodel with marks
scud18.png (63.31 KiB) Viewed 258 times


The "white-ish" level is LOD=0, red is LOD=1, others (green, blue, cyan and magenta) follow suit
User avatar
HarryTuttle
 
Posts: 299
Joined: Thu Mar 09, 2017 8:57 am

PreviousNext

Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest