kernelBlur.fragment.fx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Parameters
  2. uniform sampler2D textureSampler;
  3. uniform vec2 delta;
  4. // Varying
  5. varying vec2 sampleCenter;
  6. #ifdef DOF
  7. uniform sampler2D circleOfConfusionSampler;
  8. uniform vec2 cameraMinMaxZ;
  9. float sampleDistance(const in vec2 offset) {
  10. float depth = texture2D(circleOfConfusionSampler, offset).g; // depth value from DepthRenderer: 0 to 1
  11. return cameraMinMaxZ.x + (cameraMinMaxZ.y - cameraMinMaxZ.x)*depth; // actual distance from the lens
  12. }
  13. float sampleCoC(const in vec2 offset) {
  14. float coc = texture2D(circleOfConfusionSampler, offset).r;
  15. return coc; // actual distance from the lens
  16. }
  17. #endif
  18. #include<kernelBlurVaryingDeclaration>[0..varyingCount]
  19. #ifdef PACKEDFLOAT
  20. #include<packingFunctions>
  21. #endif
  22. void main(void)
  23. {
  24. float computedWeight = 0.0;
  25. #ifdef PACKEDFLOAT
  26. float blend = 0.;
  27. #else
  28. vec4 blend = vec4(0.);
  29. #endif
  30. #ifdef DOF
  31. float sumOfWeights = CENTER_WEIGHT; // Since not all values are blended, keep track of sum to devide result by at the end to get an average (start at center weight as center pixel is added by default)
  32. float factor = 0.0;
  33. // Add center pixel to the blur by default
  34. #ifdef PACKEDFLOAT
  35. blend += unpack(texture2D(textureSampler, sampleCenter)) * CENTER_WEIGHT;
  36. #else
  37. blend += texture2D(textureSampler, sampleCenter) * CENTER_WEIGHT;
  38. #endif
  39. #endif
  40. #include<kernelBlurFragment>[0..varyingCount]
  41. #include<kernelBlurFragment2>[0..depCount]
  42. #ifdef PACKEDFLOAT
  43. gl_FragColor = pack(blend);
  44. #else
  45. gl_FragColor = blend;
  46. #endif
  47. #ifdef DOF
  48. gl_FragColor /= sumOfWeights;
  49. #endif
  50. }