KDAB / kuesa

Professional 3D asset creation and integration workflow for Qt
https://www.kuesa.com/
139 stars 27 forks source link

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

Open dangelog opened 5 years ago

dangelog commented 5 years ago

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 commented 5 years ago

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.

seanharmer commented 5 years ago

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.

dangelog commented 5 years ago

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