Merge "Fix issue using broken image" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / graphics / shaders / skybox-equirectangular-shader.frag
1 // Fragment shader for a skybox in equirectangular projection
2 precision mediump float;
3
4 uniform sampler2D uSkyBoxEquirectangularTexture;
5
6 uniform vec4  uColor;
7 uniform float uIntensity;
8
9 varying vec3 vTexCoord;
10
11 // Take the sample direction as interpolated from the cube's local position,
12 // and use this direction vector and the spherical to cartesian coordinate
13 // conversion to sample the equirectangular map as if it's a cube map.
14
15 const float M_1_PI = 0.3183; // The reciprocal of pi in radians
16 const float M_1_2PI = 0.1591; // The reciprocal of 2*pi in radians
17
18 const vec2 inverseAtan = vec2(M_1_2PI, M_1_PI);
19
20 vec2 SampleEquirectangularMapAsCubeMap(vec3 v)
21 {
22     vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
23     uv *= inverseAtan;
24     uv += 0.5;
25     return uv;
26 }
27
28 void main()
29 {
30   // Project the equirectangular map to a cube's faces
31   vec2 uv = SampleEquirectangularMapAsCubeMap(normalize(vTexCoord));
32
33   // Flip the texture UVs vertically
34   vec2 uvFlippped = vec2(uv.x, 1.0 - uv.y);
35
36   vec4 texColor = texture2D( uSkyBoxEquirectangularTexture, uvFlippped ) * uIntensity;
37   gl_FragColor = texColor * uColor;
38 }