暂无描述

viewdisplay.frag 620B

12345678910111213141516171819202122232425
  1. #version 450
  2. layout (binding = 1) uniform sampler2DArray samplerView;
  3. layout (binding = 0) uniform UBO
  4. {
  5. layout(offset = 272) float distortionAlpha;
  6. } ubo;
  7. layout (location = 0) in vec2 inUV;
  8. layout (location = 0) out vec4 outColor;
  9. layout (constant_id = 0) const float VIEW_LAYER = 0.0f;
  10. void main()
  11. {
  12. const float alpha = ubo.distortionAlpha;
  13. vec2 p1 = vec2(2.0 * inUV - 1.0);
  14. vec2 p2 = p1 / (1.0 - alpha * length(p1));
  15. p2 = (p2 + 1.0) * 0.5;
  16. bool inside = ((p2.x >= 0.0) && (p2.x <= 1.0) && (p2.y >= 0.0 ) && (p2.y <= 1.0));
  17. outColor = inside ? texture(samplerView, vec3(p2, VIEW_LAYER)) : vec4(0.0);
  18. }