1#ifdef COMPILEPS
2uniform sampler2D sDiffMap;
3uniform samplerCube sDiffCubeMap;
4uniform sampler2D sNormalMap;
5uniform sampler2D sSpecMap;
6uniform sampler2D sEmissiveMap;
7uniform sampler2D sEnvMap;
8uniform samplerCube sEnvCubeMap;
9uniform sampler2D sLightRampMap;
10uniform sampler2D sLightSpotMap;
11uniform samplerCube sLightCubeMap;
12#ifndef GL_ES
13    uniform sampler3D sVolumeMap;
14    uniform sampler2D sAlbedoBuffer;
15    uniform sampler2D sNormalBuffer;
16    uniform sampler2D sDepthBuffer;
17    uniform sampler2D sLightBuffer;
18    #ifdef VSM_SHADOW
19        uniform sampler2D sShadowMap;
20    #else
21        uniform sampler2DShadow sShadowMap;
22    #endif
23    uniform samplerCube sFaceSelectCubeMap;
24    uniform samplerCube sIndirectionCubeMap;
25    uniform samplerCube sZoneCubeMap;
26    uniform sampler3D sZoneVolumeMap;
27#else
28    uniform highp sampler2D sShadowMap;
29#endif
30
31#ifdef GL3
32#define texture2D texture
33#define texture2DProj textureProj
34#define texture3D texture
35#define textureCube texture
36#define texture2DLod textureLod
37#define texture2DLodOffset textureLodOffset
38#endif
39
40vec3 DecodeNormal(vec4 normalInput)
41{
42    #ifdef PACKEDNORMAL
43        vec3 normal;
44        normal.xy = normalInput.ag * 2.0 - 1.0;
45        normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
46        return normal;
47    #else
48        return normalize(normalInput.rgb * 2.0 - 1.0);
49    #endif
50}
51
52vec3 EncodeDepth(float depth)
53{
54    #ifndef GL3
55        vec3 ret;
56        depth *= 255.0;
57        ret.x = floor(depth);
58        depth = (depth - ret.x) * 255.0;
59        ret.y = floor(depth);
60        ret.z = (depth - ret.y);
61        ret.xy *= 1.0 / 255.0;
62        return ret;
63    #else
64        // OpenGL 3 can use different MRT formats, so no need for encoding
65        return vec3(depth, 0.0, 0.0);
66    #endif
67}
68
69float DecodeDepth(vec3 depth)
70{
71    #ifndef GL3
72        const vec3 dotValues = vec3(1.0, 1.0 / 255.0, 1.0 / (255.0 * 255.0));
73        return dot(depth, dotValues);
74    #else
75        // OpenGL 3 can use different MRT formats, so no need for encoding
76        return depth.r;
77    #endif
78}
79
80float ReconstructDepth(float hwDepth)
81{
82    return dot(vec2(hwDepth, cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x)), cDepthReconstruct.zw);
83}
84#endif
85