No Description

mirror.frag 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2D samplerColor;
  5. layout (binding = 2) uniform sampler2D samplerColorMap;
  6. layout (location = 0) in vec2 inUV;
  7. layout (location = 1) in vec4 inPos;
  8. layout (location = 0) out vec4 outFragColor;
  9. void main()
  10. {
  11. vec4 tmp = vec4(1.0 / inPos.w);
  12. vec4 projCoord = inPos * tmp;
  13. // Scale and bias
  14. projCoord += vec4(1.0);
  15. projCoord *= vec4(0.5);
  16. // Slow single pass blur
  17. // For demonstration purposes only
  18. const float blurSize = 1.0 / 512.0;
  19. vec4 color = texture(samplerColorMap, inUV);
  20. outFragColor = color * 0.25;
  21. if (gl_FrontFacing)
  22. {
  23. // Only render mirrored scene on front facing (upper) side of mirror surface
  24. vec4 reflection = vec4(0.0);
  25. for (int x = -3; x <= 3; x++)
  26. {
  27. for (int y = -3; y <= 3; y++)
  28. {
  29. reflection += texture(samplerColor, vec2(projCoord.s + x * blurSize, projCoord.t + y * blurSize)) / 49.0;
  30. }
  31. }
  32. outFragColor += reflection * 1.5 * (color.r);
  33. };
  34. }