Samplers.glsl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. uniform sampler2DShadow sShadowMap;
  19. uniform samplerCube sFaceSelectCubeMap;
  20. uniform samplerCube sIndirectionCubeMap;
  21. uniform samplerCube sZoneCubeMap;
  22. uniform sampler3D sZoneVolumeMap;
  23. #else
  24. uniform sampler2D sShadowMap;
  25. #endif
  26. #ifdef GL3
  27. #define texture2D texture
  28. #define texture2DProj textureProj
  29. #define texture3D texture
  30. #define textureCube texture
  31. #define texture2DLod textureLod
  32. #define texture2DLodOffset textureLodOffset
  33. #endif
  34. vec3 DecodeNormal(vec4 normalInput)
  35. {
  36. #ifdef PACKEDNORMAL
  37. vec3 normal;
  38. normal.xy = normalInput.ag * 2.0 - 1.0;
  39. normal.z = sqrt(max(1.0 - dot(normal.xy, normal.xy), 0.0));
  40. return normal;
  41. #else
  42. return normalize(normalInput.rgb * 2.0 - 1.0);
  43. #endif
  44. }
  45. vec3 EncodeDepth(float depth)
  46. {
  47. #ifndef GL3
  48. vec3 ret;
  49. depth *= 255.0;
  50. ret.x = floor(depth);
  51. depth = (depth - ret.x) * 255.0;
  52. ret.y = floor(depth);
  53. ret.z = (depth - ret.y);
  54. ret.xy *= 1.0 / 255.0;
  55. return ret;
  56. #else
  57. // OpenGL 3 can use different MRT formats, so no need for encoding
  58. return vec3(depth, 0.0, 0.0);
  59. #endif
  60. }
  61. float DecodeDepth(vec3 depth)
  62. {
  63. #ifndef GL3
  64. const vec3 dotValues = vec3(1.0, 1.0 / 255.0, 1.0 / (255.0 * 255.0));
  65. return dot(depth, dotValues);
  66. #else
  67. // OpenGL 3 can use different MRT formats, so no need for encoding
  68. return depth.r;
  69. #endif
  70. }
  71. float ReconstructDepth(float hwDepth)
  72. {
  73. return dot(vec2(hwDepth, cDepthReconstruct.y / (hwDepth - cDepthReconstruct.x)), cDepthReconstruct.zw);
  74. }
  75. #endif