BsReflectionProbes.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsRenderBeastPrerequisites.h"
  5. #include "BsRendererMaterial.h"
  6. #include "BsParamBlocks.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup RenderBeast
  10. * @{
  11. */
  12. BS_PARAM_BLOCK_BEGIN(ReflectionCubeDownsampleParamDef)
  13. BS_PARAM_BLOCK_ENTRY(int, gCubeFace)
  14. BS_PARAM_BLOCK_END
  15. extern ReflectionCubeDownsampleParamDef gReflectionCubeDownsampleParamDef;
  16. /** Performs filtering on cubemap faces in order to prepare them for importance sampling. */
  17. class ReflectionCubeDownsampleMat : public RendererMaterial<ReflectionCubeDownsampleMat>
  18. {
  19. RMAT_DEF("ReflectionCubeDownsample.bsl")
  20. public:
  21. ReflectionCubeDownsampleMat();
  22. /** Downsamples the provided texture face and outputs it to the provided target. */
  23. void execute(const SPtr<Texture>& source, UINT32 face, const TextureSurface& surface,
  24. const SPtr<RenderTarget>& target);
  25. private:
  26. SPtr<GpuParamBlockBuffer> mParamBuffer;
  27. GpuParamTexture mInputTexture;
  28. };
  29. BS_PARAM_BLOCK_BEGIN(ReflectionCubeImportanceSampleParamDef)
  30. BS_PARAM_BLOCK_ENTRY(int, gCubeFace)
  31. BS_PARAM_BLOCK_ENTRY(int, gMipLevel)
  32. BS_PARAM_BLOCK_ENTRY(float, gPrecomputedMipFactor)
  33. BS_PARAM_BLOCK_END
  34. extern ReflectionCubeImportanceSampleParamDef gReflectionCubeImportanceSampleParamDef;
  35. /** Performs importance sampling on cubemap faces in order for make them suitable for specular evaluation. */
  36. class ReflectionCubeImportanceSampleMat : public RendererMaterial<ReflectionCubeImportanceSampleMat>
  37. {
  38. RMAT_DEF("ReflectionCubeImportanceSample.bsl")
  39. public:
  40. ReflectionCubeImportanceSampleMat();
  41. /** Importance samples the provided texture face and outputs it to the provided target. */
  42. void execute(const SPtr<Texture>& source, UINT32 face, UINT32 mip, const SPtr<RenderTarget>& target);
  43. private:
  44. static const UINT32 NUM_SAMPLES;
  45. SPtr<GpuParamBlockBuffer> mParamBuffer;
  46. GpuParamTexture mInputTexture;
  47. };
  48. /** Helper class that handles generation and processing of textures used for reflection probes. */
  49. class ReflectionProbes
  50. {
  51. public:
  52. /**
  53. * Performs filtering on the cubemap, populating its mip-maps with filtered values that can be used for
  54. * evaluating specular reflections.
  55. *
  56. * @param[in, out] cubemap Cubemap to filter. Its mip level 0 will be read, filtered and written into
  57. * other mip levels.
  58. * @param[in] scratch Temporary cubemap texture to use for the filtering process. Must match the size of
  59. * the source cubemap.
  60. */
  61. static void filterCubemapForSpecular(const SPtr<Texture>& cubemap, const SPtr<Texture>& scratch);
  62. static const UINT32 REFLECTION_CUBEMAP_SIZE;
  63. };
  64. /** @} */
  65. }}