Samplers.glsl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifdef COMPILEPS
  2. uniform sampler2D sDiffMap;
  3. uniform samplerCube sDiffCubeMap;
  4. uniform sampler2D sNormalMap;
  5. uniform sampler2D sSpecMap;
  6. uniform sampler2D sEmissiveMap;
  7. uniform sampler2D sEnvMap;
  8. uniform samplerCube sEnvCubeMap;
  9. uniform sampler2D sLightRampMap;
  10. uniform sampler2D sLightSpotMap;
  11. uniform 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. #ifdef GL3
  31. #define texture2D texture
  32. #define texture2DProj textureProj
  33. #define texture3D texture
  34. #define textureCube texture
  35. #define texture2DLod textureLod
  36. #define texture2DLodOffset textureLodOffset
  37. #endif
  38. vec3 DecodeNormal(vec4 normalInput)
  39. {
  40. #ifdef PACKEDNORMAL
  41. vec3 normal;
  42. normal.xy = normalInput.ag * 2.0 - 1.0;
  43. normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
  44. return normal;
  45. #else
  46. return normalize(normalInput.rgb * 2.0 - 1.0);
  47. #endif
  48. }
  49. vec3 EncodeDepth(float depth)
  50. {
  51. #ifndef GL3
  52. vec3 ret;
  53. depth *= 255.0;
  54. ret.x = floor(depth);
  55. depth = (depth - ret.x) * 255.0;
  56. ret.y = floor(depth);
  57. ret.z = (depth - ret.y);
  58. ret.xy *= 1.0 / 255.0;
  59. return ret;
  60. #else
  61. // OpenGL 3 can use different MRT formats, so no need for encoding
  62. return vec3(depth, 0.0, 0.0);
  63. #endif
  64. }
  65. float DecodeDepth(vec3 depth)
  66. {
  67. #ifndef GL3
  68. const vec3 dotValues = vec3(1.0, 1.0 / 255.0, 1.0 / (255.0 * 255.0));
  69. return dot(depth, dotValues);
  70. #else
  71. // OpenGL 3 can use different MRT formats, so no need for encoding
  72. return depth.r;
  73. #endif
  74. }
  75. float ReconstructDepth(float hwDepth)
  76. {
  77. return dot(vec2(hwDepth, cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x)), cDepthReconstruct.zw);
  78. }
  79. #endif