Projektordner für das Team Deutsches Museum (FORUM).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WarpBilinear.frag 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #version 150
  2. uniform sampler2D uTexture;
  3. uniform vec4 uExtends;
  4. uniform vec3 uLuminance;
  5. uniform vec3 uGamma;
  6. uniform vec4 uEdges;
  7. uniform vec4 uCorners;
  8. uniform float uExponent;
  9. uniform bool uEditing;
  10. in vec2 vTexCoord;
  11. in vec4 vColor;
  12. out vec4 fragColor;
  13. float map(in float value, in float inMin, in float inMax, in float outMin, in float outMax)
  14. {
  15. return outMin + (outMax - outMin) * (value - inMin) / (inMax - inMin);
  16. }
  17. float grid(in vec2 uv, in vec2 size)
  18. {
  19. vec2 coord = uv / size;
  20. vec2 grid = abs(fract(coord - 0.5) - 0.5) / (2.0 * fwidth(coord));
  21. float line = min(grid.x, grid.y);
  22. return 1.0 - min(line, 1.0);
  23. }
  24. void main(void)
  25. {
  26. vec4 texColor = texture(uTexture, vTexCoord);
  27. vec2 mapCoord = vec2(map(vTexCoord.x, uCorners.x, uCorners.z, 0.0, 1.0), map(vTexCoord.y, uCorners.y, uCorners.w, 0.0, 1.0));
  28. float a = 1.0;
  29. if (uEdges.x > 0.0) a *= clamp(mapCoord.x / uEdges.x, 0.0, 1.0);
  30. if (uEdges.y > 0.0) a *= clamp(mapCoord.y / uEdges.y, 0.0, 1.0);
  31. if (uEdges.z > 0.0) a *= clamp((1.0 - mapCoord.x) / uEdges.z, 0.0, 1.0);
  32. if (uEdges.w > 0.0) a *= clamp((1.0 - mapCoord.y) / uEdges.w, 0.0, 1.0);
  33. const vec3 one = vec3(1.0);
  34. vec3 blend = (a < 0.5) ? (uLuminance * pow(2.0 * a, uExponent)) : one - (one - uLuminance) * pow(2.0 * (1.0 - a), uExponent);
  35. texColor.rgb *= pow(blend, one / uGamma);
  36. if (uEditing)
  37. {
  38. float f = grid(mapCoord.xy * uExtends.xy, uExtends.zw);
  39. vec4 gridColor = vec4(1.0f);
  40. fragColor = mix(texColor * vColor, gridColor, f);
  41. }
  42. else
  43. {
  44. fragColor = texColor * vColor;
  45. }
  46. }