ReflectionCubemapCommon.bslinc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. Technique : base("ReflectionCubemap") =
  2. {
  3. Language = "HLSL11";
  4. Pass =
  5. {
  6. Common =
  7. {
  8. #define REFLECTION_MIP_OFFSET 2
  9. /**
  10. * Calculates a mip level to sample from based on roughness value.
  11. *
  12. * @param roughness Roughness in range [0, 1]. Higher values yield more roughness.
  13. * @param numMips Total number of mip-map levels in the texture we'll be sampling from.
  14. * @return Index of the mipmap level to sample.
  15. */
  16. float getMipFromRoughness(float roughness, float numMips)
  17. {
  18. // Note: This is just a heuristic as we don't calculate the exact size of the specular lobe,
  19. // and neither do our filtered maps
  20. // We add an offset because we want to ignore the highest few mip levels
  21. return numMips - 1 - REFLECTION_MIP_OFFSET - log2(roughness);
  22. }
  23. };
  24. };
  25. };
  26. Technique : base("ReflectionCubemap") =
  27. {
  28. Language = "GLSL";
  29. Pass =
  30. {
  31. Common =
  32. {
  33. #define REFLECTION_MIP_OFFSET 2
  34. /**
  35. * Calculates a mip level to sample from based on roughness value.
  36. *
  37. * @param roughness Roughness in range [0, 1]. Higher values yield more roughness.
  38. * @param numMips Total number of mip-map levels in the texture we'll be sampling from.
  39. * @return Index of the mipmap level to sample.
  40. */
  41. void getMipFromRoughness(float roughness, float numMips, out float mipLevel)
  42. {
  43. // Note: This is just a heuristic as we don't calculate the exact size of the specular lobe,
  44. // and neither do our filtered maps
  45. // We add an offset because we want to ignore the highest few mip levels
  46. mipLevel = numMips - 1 - REFLECTION_MIP_OFFSET - log2(roughness);
  47. }
  48. };
  49. };
  50. };