pex-gl / pex-shaders

MIT License
3 stars 0 forks source link

GTAO occlusion is not used when colorBounce is enabled #14

Open vorg opened 5 months ago

vorg commented 5 months ago

https://github.com/pex-gl/pex-shaders/blob/59621b26c83506fdd2a71cf67826717caf0b083c/shaders/chunks/ambient-occlusion.glsl.js#L25

should be

color.rgb = vec3(color.rgb * aoData.a + aoData.rgb * color.rgb); //not sure about *2.0
dmnsgn commented 4 months ago

aoData.a is used in the line above with gtao multibounce approximation:

https://github.com/pex-gl/pex-shaders/blob/59621b26c83506fdd2a71cf67826717caf0b083c/shaders/chunks/ambient-occlusion.glsl.js#L24

vorg commented 4 months ago

So aoData.a is actually used in gtaoMultiBounce. The problem was more that colorBounce was not scaled by ssao.mix (named intensity here, not to confuse with colorBounceIntensity or ssao.intensity (to be renamed to aoIntensity))


vec4 ssao(vec4 color, vec4 aoData, float intensity) {
  #ifdef USE_SSAO_COLORS
      vec3 albedoColor = color.rgb; //unlit color of the surface that we don't have ATM
      vec3 colorWithAO = color.rgb * gtaoMultiBounce(aoData.a, albedoColor);
      vec3 colorBounce = albedoColor * aoData.rgb;
      color.rgb = mix(color.rgb, colorWithAO + colorBounce, intensity);
      // color.rgb = vec3(aoData.aaa);
    #else
      color.rgb *= mix(vec3(1.0), vec3(aoData.r), intensity);
    #endif

  return color;
}
``
vorg commented 4 months ago

One way to avoid having to have both ssao.mix and ssao.aoIntensity is to reuse ssao.intensity to fade out GTAO's AO when below 1

visibility = mix(visibility, 1.0, 1.0 - clamp(uIntensity, 0.0, 1.0));
vorg commented 4 months ago

AO wish list

vorg commented 4 months ago

The bounce from baseColor vs directColor should look like that this Source

shad2-results3

We do get that reflection a bit if indirectDiffuse is present as they all (direct + indirect) add up to output color.

vorg commented 4 months ago

@dmnsgn let's keep current code but with better variable names like mentioned in my comment above

vec3 albedoColor = color.rgb; //TODO: unlit color of the surface that we don't have ATM
vec3 colorWithAO = color.rgb * gtaoMultiBounce(aoData.a, albedoColor);
vec3 colorBounce = albedoColor * aoData.rgb;
color.rgb = mix(color.rgb, colorWithAO + colorBounce, intensity);