| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsRenderBeastPrerequisites.h" |
| 6 | #include "Renderer/BsRendererMaterial.h" |
| 7 | #include "Renderer/BsParamBlocks.h" |
| 8 | #include "RenderAPI/BsGpuPipelineParamInfo.h" |
| 9 | #include "BsRendererLight.h" |
| 10 | |
| 11 | namespace bs { namespace ct |
| 12 | { |
| 13 | struct SkyInfo; |
| 14 | struct SceneInfo; |
| 15 | class RendererViewGroup; |
| 16 | |
| 17 | /** @addtogroup RenderBeast |
| 18 | * @{ |
| 19 | */ |
| 20 | |
| 21 | /** Maximum number of refl. probes that can influence an object when basic forward rendering is used. */ |
| 22 | static constexpr UINT32 STANDARD_FORWARD_MAX_NUM_PROBES = 8; |
| 23 | |
| 24 | /** Information about a single reflection probe, as seen by the lighting shader. */ |
| 25 | struct ReflProbeData |
| 26 | { |
| 27 | Vector3 position; |
| 28 | float radius; |
| 29 | Vector3 boxExtents; |
| 30 | float transitionDistance; |
| 31 | Matrix4 invBoxTransform; |
| 32 | UINT32 cubemapIdx; |
| 33 | UINT32 type; // 0 - Sphere, 1 - Box |
| 34 | Vector2 padding; |
| 35 | }; |
| 36 | |
| 37 | /** Contains GPU buffers used by the renderer to manipulate reflection probes. */ |
| 38 | class VisibleReflProbeData |
| 39 | { |
| 40 | public: |
| 41 | VisibleReflProbeData() = default; |
| 42 | |
| 43 | /** |
| 44 | * Updates the internal buffers with a new set of refl. probes. Before calling make sure that probe visibility has |
| 45 | * been calculated for the provided view group. |
| 46 | */ |
| 47 | void update(const SceneInfo& sceneInfo, const RendererViewGroup& viewGroup); |
| 48 | |
| 49 | /** Returns a GPU bindable buffer containing information about every reflection probe. */ |
| 50 | SPtr<GpuBuffer> getProbeBuffer() const { return mProbeBuffer; } |
| 51 | |
| 52 | /** Returns the number of reflection probes in the probe buffer. */ |
| 53 | UINT32 getNumProbes() const { return mNumProbes; } |
| 54 | |
| 55 | /** Returns information about a probe at the specified index. */ |
| 56 | const ReflProbeData& getProbeData(UINT32 idx) const { return mReflProbeData[idx]; } |
| 57 | |
| 58 | private: |
| 59 | Vector<ReflProbeData> mReflProbeData; |
| 60 | SPtr<GpuBuffer> mProbeBuffer; |
| 61 | UINT32 mNumProbes = 0; |
| 62 | }; |
| 63 | |
| 64 | BS_PARAM_BLOCK_BEGIN(ReflProbeParamsParamDef) |
| 65 | BS_PARAM_BLOCK_ENTRY(INT32, gReflCubemapNumMips) |
| 66 | BS_PARAM_BLOCK_ENTRY(INT32, gNumProbes) |
| 67 | BS_PARAM_BLOCK_ENTRY(INT32, gSkyCubemapAvailable) |
| 68 | BS_PARAM_BLOCK_ENTRY(INT32, gUseReflectionMaps) |
| 69 | BS_PARAM_BLOCK_ENTRY(INT32, gSkyCubemapNumMips) |
| 70 | BS_PARAM_BLOCK_ENTRY(float, gSkyBrightness) |
| 71 | BS_PARAM_BLOCK_END |
| 72 | |
| 73 | extern ReflProbeParamsParamDef gReflProbeParamsParamDef; |
| 74 | |
| 75 | /** Renderer information specific to a single reflection probe. */ |
| 76 | class RendererReflectionProbe |
| 77 | { |
| 78 | public: |
| 79 | RendererReflectionProbe(ReflectionProbe* probe); |
| 80 | |
| 81 | /** Populates the structure with reflection probe parameters. */ |
| 82 | void getParameters(ReflProbeData& output) const; |
| 83 | |
| 84 | ReflectionProbe* probe; |
| 85 | UINT32 arrayIdx; |
| 86 | bool arrayDirty : 1; |
| 87 | mutable bool errorFlagged : 1; |
| 88 | }; |
| 89 | |
| 90 | /** Helper struct containing all parameters for binding image lighting related data to the GPU programs using them .*/ |
| 91 | struct ImageBasedLightingParams |
| 92 | { |
| 93 | /** |
| 94 | * Initializes the parameters from the provided parameters. |
| 95 | * |
| 96 | * @param[in] params GPU parameters object to look for the parameters in. |
| 97 | * @param[in] programType Type of the GPU program to look up the parameters for. |
| 98 | * @param[in] optional If true no warnings will be thrown if some or all of the parameters will be found. |
| 99 | * @param[in] gridIndices Set to true if grid indices (used by light grid) parameter is required. |
| 100 | * @param[in] probeArray True if the refl. probe data is to be provided in a structured buffer. |
| 101 | */ |
| 102 | void populate(const SPtr<GpuParams>& params, GpuProgramType programType, bool optional, bool gridIndices, |
| 103 | bool probeArray); |
| 104 | |
| 105 | GpuParamTexture skyReflectionsTexParam; |
| 106 | GpuParamTexture ambientOcclusionTexParam; |
| 107 | GpuParamTexture ssrTexParam; |
| 108 | GpuParamTexture reflectionProbeCubemapsTexParam; |
| 109 | |
| 110 | GpuParamTexture preintegratedEnvBRDFParam; |
| 111 | GpuParamBuffer reflectionProbesParam; |
| 112 | |
| 113 | GpuParamBuffer reflectionProbeIndicesParam; |
| 114 | GpuParamBinding reflProbeParamBindings; |
| 115 | |
| 116 | // Only utilized when standard forward rendering is used |
| 117 | GpuParamBinding reflProbesBinding; |
| 118 | }; |
| 119 | |
| 120 | /** Parameter buffer containing information about reflection probes. */ |
| 121 | struct ReflProbeParamBuffer |
| 122 | { |
| 123 | ReflProbeParamBuffer(); |
| 124 | |
| 125 | /** Updates the parameter buffer contents with required refl. probe data. */ |
| 126 | void populate(const Skybox* sky, UINT32 numProbes, const SPtr<Texture>& reflectionCubemaps, |
| 127 | bool capturingReflections); |
| 128 | |
| 129 | SPtr<GpuParamBlockBuffer> buffer; |
| 130 | }; |
| 131 | |
| 132 | BS_PARAM_BLOCK_BEGIN(ReflProbesParamDef) |
| 133 | BS_PARAM_BLOCK_ENTRY_ARRAY(ReflProbeData, gReflectionProbes, STANDARD_FORWARD_MAX_NUM_PROBES) |
| 134 | BS_PARAM_BLOCK_END |
| 135 | |
| 136 | extern ReflProbesParamDef gReflProbesParamDef; |
| 137 | |
| 138 | /** @} */ |
| 139 | }} |
| 140 | |