imageProcessingFunctions.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Do not edit.
  2. import { ShaderStore } from "../../Engines/shaderStore.js";
  3. const name = "imageProcessingFunctions";
  4. const shader = `#if defined(COLORGRADING) && !defined(COLORGRADING3D)
  5. /**
  6. * Polyfill for SAMPLE_TEXTURE_3D,which is unsupported in WebGL.
  7. * sampler3dSetting.x=textureOffset (0.5/textureSize).
  8. * sampler3dSetting.y=textureSize.
  9. */
  10. #define inline
  11. vec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)
  12. {float sliceSize=2.0*sampler3dSetting.x;
  13. #ifdef SAMPLER3DGREENDEPTH
  14. float sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;
  15. #else
  16. float sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;
  17. #endif
  18. float sliceInteger=floor(sliceContinuous);float sliceFraction=sliceContinuous-sliceInteger;
  19. #ifdef SAMPLER3DGREENDEPTH
  20. vec2 sliceUV=color.rb;
  21. #else
  22. vec2 sliceUV=color.rg;
  23. #endif
  24. sliceUV.x*=sliceSize;sliceUV.x+=sliceInteger*sliceSize;sliceUV=saturate(sliceUV);vec4 slice0Color=texture2D(colorTransform,sliceUV);sliceUV.x+=sliceSize;sliceUV=saturate(sliceUV);vec4 slice1Color=texture2D(colorTransform,sliceUV);vec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);
  25. #ifdef SAMPLER3DBGRMAP
  26. color.rgb=result.rgb;
  27. #else
  28. color.rgb=result.bgr;
  29. #endif
  30. return color;}
  31. #endif
  32. #ifdef TONEMAPPING_ACES
  33. const mat3 ACESInputMat=mat3(
  34. vec3(0.59719,0.07600,0.02840),
  35. vec3(0.35458,0.90834,0.13383),
  36. vec3(0.04823,0.01566,0.83777)
  37. );const mat3 ACESOutputMat=mat3(
  38. vec3( 1.60475,-0.10208,-0.00327),
  39. vec3(-0.53108, 1.10813,-0.07276),
  40. vec3(-0.07367,-0.00605, 1.07602)
  41. );vec3 RRTAndODTFit(vec3 v)
  42. {vec3 a=v*(v+0.0245786)-0.000090537;vec3 b=v*(0.983729*v+0.4329510)+0.238081;return a/b;}
  43. vec3 ACESFitted(vec3 color)
  44. {color=ACESInputMat*color;color=RRTAndODTFit(color);color=ACESOutputMat*color;color=saturate(color);return color;}
  45. #endif
  46. #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_DEFINITIONS
  47. vec4 applyImageProcessing(vec4 result) {
  48. #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATSTART
  49. #ifdef EXPOSURE
  50. result.rgb*=exposureLinear;
  51. #endif
  52. #ifdef VIGNETTE
  53. vec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;viewportXY=viewportXY*2.0-1.0;vec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);float vignetteTerm=dot(vignetteXY1,vignetteXY1);float vignette=pow(vignetteTerm,vignetteSettings2.w);vec3 vignetteColor=vignetteSettings2.rgb;
  54. #ifdef VIGNETTEBLENDMODEMULTIPLY
  55. vec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);result.rgb*=vignetteColorMultiplier;
  56. #endif
  57. #ifdef VIGNETTEBLENDMODEOPAQUE
  58. result.rgb=mix(vignetteColor,result.rgb,vignette);
  59. #endif
  60. #endif
  61. #ifdef TONEMAPPING
  62. #ifdef TONEMAPPING_ACES
  63. result.rgb=ACESFitted(result.rgb);
  64. #else
  65. const float tonemappingCalibration=1.590579;result.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);
  66. #endif
  67. #endif
  68. result.rgb=toGammaSpace(result.rgb);result.rgb=saturate(result.rgb);
  69. #ifdef CONTRAST
  70. vec3 resultHighContrast=result.rgb*result.rgb*(3.0-2.0*result.rgb);if (contrast<1.0) {result.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);} else {result.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);}
  71. #endif
  72. #ifdef COLORGRADING
  73. vec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;
  74. #ifdef COLORGRADING3D
  75. vec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;
  76. #else
  77. vec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;
  78. #endif
  79. result.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);
  80. #endif
  81. #ifdef COLORCURVES
  82. float luma=getLuminance(result.rgb);vec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));vec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;result.rgb*=colorCurve.rgb;result.rgb=mix(vec3(luma),result.rgb,colorCurve.a);
  83. #endif
  84. #ifdef DITHER
  85. float rand=getRand(gl_FragCoord.xy*vInverseScreenSize);float dither=mix(-ditherIntensity,ditherIntensity,rand);result.rgb=saturate(result.rgb+vec3(dither));
  86. #endif
  87. #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATEND
  88. return result;}`;
  89. // Sideeffect
  90. ShaderStore.IncludesShadersStore[name] = shader;
  91. /** @internal */
  92. export const imageProcessingFunctions = { name, shader };
  93. //# sourceMappingURL=imageProcessingFunctions.js.map