cs_assao_postprocess_importance_map_a.sc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2018 Attila Kocsis. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #include "bgfx_compute.sh"
  6. #include "uniforms.sh"
  7. IMAGE2D_WO(s_target, r8, 0);
  8. SAMPLER2D(s_importanceMap, 1);
  9. // Shaders below only needed for adaptive quality level
  10. CONST(float cSmoothenImportance) = 1.0;
  11. NUM_THREADS(8, 8, 1)
  12. void main()
  13. {
  14. uvec2 dtID = uvec2(gl_GlobalInvocationID.xy);
  15. uvec2 dim = imageSize(s_target).xy;
  16. if (all(lessThan(dtID.xy, dim) ) )
  17. {
  18. uvec2 pos = uvec2(dtID.xy);
  19. vec2 inUV = (dtID.xy+vec2(0.5,0.5)) * u_quarterResPixelSize;
  20. float centre = texture2DLod(s_importanceMap, inUV, 0.0 ).x;
  21. //return centre;
  22. vec2 halfPixel = u_quarterResPixelSize * 0.5f;
  23. #if BGFX_SHADER_LANGUAGE_GLSL
  24. halfPixel.y = -halfPixel.y;
  25. #endif
  26. vec4 vals;
  27. vals.x = texture2DLod(s_importanceMap, inUV + vec2( -halfPixel.x * 3, -halfPixel.y ), 0.0 ).x;
  28. vals.y = texture2DLod(s_importanceMap, inUV + vec2( +halfPixel.x, -halfPixel.y * 3 ), 0.0 ).x;
  29. vals.z = texture2DLod(s_importanceMap, inUV + vec2( +halfPixel.x * 3, +halfPixel.y ), 0.0 ).x;
  30. vals.w = texture2DLod(s_importanceMap, inUV + vec2( -halfPixel.x, +halfPixel.y * 3 ), 0.0 ).x;
  31. float avgVal = dot( vals, vec4( 0.25, 0.25, 0.25, 0.25 ) );
  32. vals.xy = max( vals.xy, vals.zw );
  33. float maxVal = max( centre, max( vals.x, vals.y ) );
  34. imageStore(s_target, ivec2(dtID.xy), mix( maxVal, avgVal, cSmoothenImportance ).xxxx);
  35. }
  36. }