(Particles) Some targets do not anything, inluding comments before the version line
[platform/core/uifw/dali-demo.git] / examples / particles / shaders / particle-view.frag
1 #version 300 es
2 // Fragment shader for particles, which simulates depth of field using
3 // a combination of procedural texturing, alpha testing and alpha blending.
4
5 precision lowp float;
6 uniform float uAlphaTestRefValue;
7 uniform vec2 uFadeRange; // near, far
8 in vec2 vUvUnit;
9 flat in float vDepth;
10 flat in float vFocalDistance;
11 flat in float vOpacity;
12 flat in vec3 vColor;
13 out vec4 oFragColor;
14
15 const float REF_VALUE_THRESHOLD = 1. / 64.;
16
17 void main()
18 {
19   // Softened disc pattern from normalized UVs
20   float value = 1.f - dot(vUvUnit, vUvUnit);
21
22   // Decrease area of particles 'in-focus'.
23   float refValue = (1.f - vFocalDistance) * .5f;
24   float threshold = REF_VALUE_THRESHOLD * (1.f + vDepth);
25   float alpha = pow(value, vFocalDistance) * smoothstep(refValue - threshold, refValue + threshold, value);
26   if (alpha < uAlphaTestRefValue)
27   {
28     discard;
29   }
30
31   // Apply opacity
32   alpha *= vOpacity;
33   alpha *= alpha;
34
35   // Fade particles out as they get close to the near and far clipping planes
36   alpha *= smoothstep(.0f, uFadeRange.x, vDepth) * smoothstep(1.f, uFadeRange.y, vDepth);
37
38   oFragColor = vec4(vColor, alpha);
39 }