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