kuesa icon indicating copy to clipboard operation
kuesa copied to clipboard

PBR shaders + normals on the car-example yield visual artifacts

Open dangelog opened this issue 5 years ago • 3 comments

Even MSAA enabled, the car scene still exhibits an enormous amount of aliasing. This is a problem with the model and/or the shaders, as this aliasing appears within faces of the same sub-mesh (e.g. the hood). Either there's normals spiking around some edge, or the shaders are not mipping correctly, or similar.

shot

Note how MSAA is enabled for the ground plane (in the top left corner). However the jagged lines are all around the air intake, including the bottom right part.

Here is even more noticeable, not sure if caused by the same effect:

shot2

Looks like there's no filtering on the env map samples or something like that.

dangelog avatar Apr 29 '19 16:04 dangelog

The "culprit" seems to be sampling at a fixed LOD (in the PBR material), combined with an extremely high frequency texture (the sky/horizon/ground change). The LOD is pretty low (0 or 1) due to the very smooth surface; this causes aliasing when sampling from the environment map: small changes in screen space yield a big change in texture space.

As a counter-example, changing the PBR shader and adding a constant to the LOD (e.g. lod += 3.0) makes everything smooth again.

dangelog avatar Apr 30 '19 13:04 dangelog

I wonder if the pre-convolved envmap for the IBL was generated correctly. Even for a smooth surface, the level 0 mip should be slightly blurred.

seanharmer avatar May 01 '19 08:05 seanharmer

Using another env map (pink sunrise).

This is vanilla (with MSAA enabled):

vanilla

As a test I've patched the fragment shader adding a call to textureQueryLod, and trying to use the biggest mip level between the one computed from the material's roughness and the one that GL would've used:

vec2 miplevel = textureQueryLod(envLight.specular, l);
vec3 specularLight = textureLod(envLight.specular, l, max(lod, miplevel.x)).rgb;

(Requires GL 4)

Result is slightly better!

tquerylod

dangelog avatar May 02 '19 13:05 dangelog