debayer.frag 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. uniform sampler2D texture;
  5. uniform mat3 color_matrix;
  6. uniform float inv_gamma;
  7. uniform float blacklevel;
  8. varying vec2 top_left_uv;
  9. varying vec2 top_right_uv;
  10. varying vec2 bottom_left_uv;
  11. varying vec2 bottom_right_uv;
  12. void
  13. main()
  14. {
  15. // Note the coordinates for texture samples need to be a varying, as the
  16. // Mali-400 has this as a fast path allowing 32-bit floats. Otherwise
  17. // they end up as 16-bit floats and that's not accurate enough.
  18. vec4 samples = vec4(texture2D(texture, top_left_uv).r,
  19. texture2D(texture, top_right_uv).r,
  20. texture2D(texture, bottom_left_uv).r,
  21. texture2D(texture, bottom_right_uv).r);
  22. #if defined(CFA_BGGR)
  23. vec3 color = vec3(samples.w, (samples.y + samples.z) / 2.0, samples.x);
  24. #elif defined(CFA_GBRG)
  25. vec3 color = vec3(samples.z, (samples.x + samples.w) / 2.0, samples.y);
  26. #elif defined(CFA_GRBG)
  27. vec3 color = vec3(samples.y, (samples.x + samples.w) / 2.0, samples.z);
  28. #else
  29. vec3 color = vec3(samples.x, (samples.y + samples.z) / 2.0, samples.w);
  30. #endif
  31. color -= blacklevel;
  32. color *= color_matrix;
  33. vec3 gamma_color = pow(color, vec3(inv_gamma));
  34. gl_FragColor = vec4(gamma_color, 1);
  35. }