ReflectionCubemapCommon.bslinc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. Technique : base("ReflectionCubemapCommon") =
  2. {
  3. Language = "HLSL11";
  4. Pass =
  5. {
  6. Common =
  7. {
  8. float3 getDirFromCubeFace(uint cubeFace, float2 uv)
  9. {
  10. float3 dir;
  11. if(cubeFace == 0)
  12. dir = float3(1.0f, -uv.y, -uv.x);
  13. else if(cubeFace == 1)
  14. dir = float3(-1.0f, -uv.y, uv.x);
  15. else if(cubeFace == 2)
  16. dir = float3(uv.x, 1.0f, uv.y);
  17. else if(cubeFace == 3)
  18. dir = float3(uv.x, -1.0f, -uv.y);
  19. else if(cubeFace == 4)
  20. dir = float3(uv.x, -uv.y, 1.0f);
  21. else
  22. dir = float3(-uv.x, -uv.y, -1.0f);
  23. return dir;
  24. }
  25. /**
  26. * Calculates a mip level to sample from based on roughness value.
  27. *
  28. * @param roughness Roughness in range [0, 1]. Higher values yield more roughness.
  29. * @param numMips Total number of mip-map levels in the texture we'll be sampling from.
  30. * @return Index of the mipmap level to sample.
  31. */
  32. float mapRoughnessToMipLevel(float roughness, uint numMips)
  33. {
  34. // We use the following equation:
  35. // mipLevel = log10(roughness) / log10(dropPercent)
  36. //
  37. // Where dropPercent represent by what % to drop the roughness with each mip level.
  38. // We convert to log2 and a assume a drop percent value of 0.6. This gives us:
  39. // mipLevel = -1.35692 * log2(roughness);
  40. return max(0, numMips - 1 - (-1.35692 * log2(roughness)));
  41. }
  42. float mapMipLevelToRoughness(uint mipLevel)
  43. {
  44. // mapRoughnessToMipLevel() solved for roughness
  45. return 1.0f - exp2(-0.7369655941662063 * mipLevel);
  46. }
  47. };
  48. };
  49. };
  50. Technique : base("ReflectionCubemapCommon") =
  51. {
  52. Language = "GLSL";
  53. Pass =
  54. {
  55. Common =
  56. {
  57. vec3 getDirFromCubeFace(uint cubeFace, vec2 uv)
  58. {
  59. vec3 dir;
  60. if(cubeFace == 0)
  61. dir = vec3(1.0f, -uv.y, -uv.x);
  62. else if(cubeFace == 1)
  63. dir = vec3(-1.0f, -uv.y, uv.x);
  64. else if(cubeFace == 2)
  65. dir = vec3(uv.x, 1.0f, uv.y);
  66. else if(cubeFace == 3)
  67. dir = vec3(uv.x, -1.0f, -uv.y);
  68. else if(cubeFace == 4)
  69. dir = vec3(uv.x, -uv.y, 1.0f);
  70. else
  71. dir = vec3(-uv.x, -uv.y, -1.0f);
  72. return dir;
  73. }
  74. };
  75. };
  76. };