particles.fragment.fx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Samplers
  2. varying vec2 vUV;
  3. varying vec4 vColor;
  4. uniform vec4 textureMask;
  5. uniform sampler2D diffuseSampler;
  6. #include<clipPlaneFragmentDeclaration>
  7. #include<imageProcessingDeclaration>
  8. #include<helperFunctions>
  9. #include<imageProcessingFunctions>
  10. #ifdef RAMPGRADIENT
  11. varying vec4 remapRanges;
  12. uniform sampler2D rampSampler;
  13. #endif
  14. void main(void) {
  15. #include<clipPlaneFragment>
  16. vec4 textureColor = texture2D(diffuseSampler, vUV);
  17. vec4 baseColor = (textureColor * textureMask + (vec4(1., 1., 1., 1.) - textureMask)) * vColor;
  18. #ifdef RAMPGRADIENT
  19. float alpha = baseColor.a;
  20. float remappedColorIndex = clamp((alpha - remapRanges.x) / remapRanges.y, 0.0, 1.0);
  21. vec4 rampColor = texture2D(rampSampler, vec2(1.0 - remappedColorIndex, 0.));
  22. baseColor.rgb *= rampColor.rgb;
  23. // Remapped alpha
  24. float finalAlpha = baseColor.a;
  25. baseColor.a = clamp((alpha * rampColor.a - remapRanges.z) / remapRanges.w, 0.0, 1.0);
  26. #endif
  27. #ifdef BLENDMULTIPLYMODE
  28. float sourceAlpha = vColor.a * textureColor.a;
  29. baseColor.rgb = baseColor.rgb * sourceAlpha + vec3(1.0) * (1.0 - sourceAlpha);
  30. #endif
  31. // Apply image processing if relevant. As this applies in linear space,
  32. // We first move from gamma to linear.
  33. #ifdef IMAGEPROCESSINGPOSTPROCESS
  34. baseColor.rgb = toLinearSpace(baseColor.rgb);
  35. #else
  36. #ifdef IMAGEPROCESSING
  37. baseColor.rgb = toLinearSpace(baseColor.rgb);
  38. baseColor = applyImageProcessing(baseColor);
  39. #endif
  40. #endif
  41. gl_FragColor = baseColor;
  42. }