| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsRenderBeastPrerequisites.h"
- #include "Renderer/BsRendererMaterial.h"
- #include "Renderer/BsParamBlocks.h"
- #include "BsGpuResourcePool.h"
- #include "BsLightRendering.h"
- #include "Renderer/BsRenderSettings.h"
- namespace bs { namespace ct
- {
- struct RendererViewTargetData;
- /** @addtogroup RenderBeast
- * @{
- */
- BS_PARAM_BLOCK_BEGIN(DownsampleParamDef)
- BS_PARAM_BLOCK_ENTRY_ARRAY(Vector2, gOffsets, 4)
- BS_PARAM_BLOCK_END
- extern DownsampleParamDef gDownsampleParamDef;
- /** Shader that downsamples a texture to half its size. */
- class DownsampleMat : public RendererMaterial<DownsampleMat>
- {
- RMAT_DEF("PPDownsample.bsl");
- /** Helper method used for initializing variations of this material. */
- template<UINT32 quality, bool MSAA>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("QUALITY", quality),
- ShaderVariation::Param("MSAA", MSAA)
- });
- return variation;
- };
- public:
- DownsampleMat();
- /** Renders the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& input, const SPtr<RenderTarget>& output);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc(const SPtr<Texture>& target);
- /** Returns the downsample material variation matching the provided parameters. */
- static DownsampleMat* getVariation(UINT32 quality, bool msaa);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTexture;
- };
- BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector4I, gPixelOffsetAndSize)
- BS_PARAM_BLOCK_ENTRY(Vector2, gHistogramParams)
- BS_PARAM_BLOCK_ENTRY(Vector2I, gThreadGroupCount)
- BS_PARAM_BLOCK_END
- extern EyeAdaptHistogramParamDef gEyeAdaptHistogramParamDef;
- /** Shader that creates a luminance histogram used for eye adaptation. */
- class EyeAdaptHistogramMat : public RendererMaterial<EyeAdaptHistogramMat>
- {
- RMAT_DEF_CUSTOMIZED("PPEyeAdaptHistogram.bsl");
- public:
- EyeAdaptHistogramMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& input, const SPtr<Texture>& output, const AutoExposureSettings& settings);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc(const SPtr<Texture>& target);
- /** Calculates the number of thread groups that need to execute to cover the provided texture. */
- static Vector2I getThreadGroupCount(const SPtr<Texture>& target);
- /**
- * Returns a vector containing scale and offset (in that order) that will be applied to luminance values
- * to determine their position in the histogram.
- */
- static Vector2 getHistogramScaleOffset(const AutoExposureSettings& settings);
- static const UINT32 THREAD_GROUP_SIZE_X = 8;
- static const UINT32 THREAD_GROUP_SIZE_Y = 8;
-
- static const UINT32 HISTOGRAM_NUM_TEXELS = (THREAD_GROUP_SIZE_X * THREAD_GROUP_SIZE_Y) / 4;
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mSceneColor;
- GpuParamLoadStoreTexture mOutputTex;
- static const UINT32 LOOP_COUNT_X = 8;
- static const UINT32 LOOP_COUNT_Y = 8;
- };
- BS_PARAM_BLOCK_BEGIN(EyeAdaptHistogramReduceParamDef)
- BS_PARAM_BLOCK_ENTRY(int, gThreadGroupCount)
- BS_PARAM_BLOCK_END
- extern EyeAdaptHistogramReduceParamDef gEyeAdaptHistogramReduceParamDef;
- /** Shader that reduces the luminance histograms created by EyeAdaptHistogramMat into a single histogram. */
- class EyeAdaptHistogramReduceMat : public RendererMaterial<EyeAdaptHistogramReduceMat>
- {
- RMAT_DEF("PPEyeAdaptHistogramReduce.bsl");
- public:
- EyeAdaptHistogramReduceMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& sceneColor, const SPtr<Texture>& histogram, const SPtr<Texture>& prevFrame,
- const SPtr<RenderTarget>& output);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc();
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mHistogramTex;
- GpuParamTexture mEyeAdaptationTex;
- };
- BS_PARAM_BLOCK_BEGIN(EyeAdaptationParamDef)
- BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gEyeAdaptationParams, 3)
- BS_PARAM_BLOCK_END
- extern EyeAdaptationParamDef gEyeAdaptationParamDef;
- /** Shader that computes the eye adaptation value based on scene luminance. */
- class EyeAdaptationMat : public RendererMaterial<EyeAdaptationMat>
- {
- RMAT_DEF_CUSTOMIZED("PPEyeAdaptation.bsl");
- public:
- EyeAdaptationMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& reducedHistogram, const SPtr<RenderTarget>& output, float frameDelta,
- const AutoExposureSettings& settings, float exposureScale);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc();
- /**
- * Populates the provided paramater buffer with eye adaptation parameters. The parameter buffer is expected to be
- * created with EyeAdaptationParamDef block definition.
- */
- static void populateParams(const SPtr<GpuParamBlockBuffer>& paramBuffer, float frameDelta,
- const AutoExposureSettings& settings, float exposureScale);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mReducedHistogramTex;
- };
- /**
- * Shader that computes luminance of all the pixels in the provided texture, and stores them in log2 format, scaled
- * to [0, 1] range (according to eye adapatation parameters) and stores those values in the alpha channel of the
- * output texture. Color channel is just a copy of the input texture. Resulting texture is intended to be provided
- * to the downsampling shader in order to calculate the average luminance, used for non-histogram eye adaptation
- * calculation (when compute shader is not available).
- */
- class EyeAdaptationBasicSetupMat : public RendererMaterial<EyeAdaptationBasicSetupMat>
- {
- RMAT_DEF("PPEyeAdaptationBasicSetup.bsl");
- public:
- EyeAdaptationBasicSetupMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& input, const SPtr<RenderTarget>& output, float frameDelta,
- const AutoExposureSettings& settings, float exposureScale);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc(const SPtr<Texture>& input);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTex;
- };
- BS_PARAM_BLOCK_BEGIN(EyeAdaptationBasicParamsMatDef)
- BS_PARAM_BLOCK_ENTRY(Vector2I, gInputTexSize)
- BS_PARAM_BLOCK_END
- extern EyeAdaptationBasicParamsMatDef gEyeAdaptationBasicParamsMatDef;
- /**
- * Shader that computes eye adapatation value from a texture that has luminance encoded in its alpha channel (as done
- * by EyeAdaptationBasicSetupMat). The result is a 1x1 texture containing the eye adaptation value.
- */
- class EyeAdaptationBasicMat : public RendererMaterial<EyeAdaptationBasicMat>
- {
- RMAT_DEF("PPEyeAdaptationBasic.bsl");
- public:
- EyeAdaptationBasicMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& curFrame, const SPtr<Texture>& prevFrame, const SPtr<RenderTarget>& output,
- float frameDelta, const AutoExposureSettings& settings, float exposureScale);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- static POOLED_RENDER_TEXTURE_DESC getOutputDesc();
- private:
- SPtr<GpuParamBlockBuffer> mEyeAdaptationParamsBuffer;
- SPtr<GpuParamBlockBuffer> mParamsBuffer;
- GpuParamTexture mCurFrameTexParam;
- GpuParamTexture mPrevFrameTexParam;
- };
- BS_PARAM_BLOCK_BEGIN(CreateTonemapLUTParamDef)
- BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gTonemapParams, 2)
- BS_PARAM_BLOCK_ENTRY(float, gGammaAdjustment)
- BS_PARAM_BLOCK_ENTRY(int, gGammaCorrectionType)
- BS_PARAM_BLOCK_ENTRY(Vector3, gSaturation)
- BS_PARAM_BLOCK_ENTRY(Vector3, gContrast)
- BS_PARAM_BLOCK_ENTRY(Vector3, gGain)
- BS_PARAM_BLOCK_ENTRY(Vector3, gOffset)
- BS_PARAM_BLOCK_END
- extern CreateTonemapLUTParamDef gCreateTonemapLUTParamDef;
- BS_PARAM_BLOCK_BEGIN(WhiteBalanceParamDef)
- BS_PARAM_BLOCK_ENTRY(float, gWhiteTemp)
- BS_PARAM_BLOCK_ENTRY(float, gWhiteOffset)
- BS_PARAM_BLOCK_END
- extern WhiteBalanceParamDef gWhiteBalanceParamDef;
- /**
- * Shader that creates a 3D lookup texture that is used to apply tonemapping, color grading, white balancing and gamma
- * correction.
- */
- class CreateTonemapLUTMat : public RendererMaterial<CreateTonemapLUTMat>
- {
- RMAT_DEF_CUSTOMIZED("PPCreateTonemapLUT.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool is3D>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("VOLUME_LUT", is3D),
- });
- return variation;
- };
- public:
- CreateTonemapLUTMat();
- /**
- * Executes the post-process effect with the provided parameters, generating a 3D LUT using a compute shader.
- * Should only be called on the appropriate variation (3D one).
- */
- void execute3D(const SPtr<Texture>& output, const RenderSettings& settings);
- /**
- * Executes the post-process effect with the provided parameters, generating an unwrapped 2D LUT without the use
- * of a compute shader. Should only be called on the appropriate variation (non-3D one).
- */
- void execute2D(const SPtr<RenderTexture>& output, const RenderSettings& settings);
- /** Returns the texture descriptor that can be used for initializing the output render target. */
- POOLED_RENDER_TEXTURE_DESC getOutputDesc() const;
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param[in] is3D If true the material will generate a 3D LUT using a compute shader. Otherwise it will
- * generate an unwrapped 2D LUT withou the use of a compute shader. Depending on this parameter
- * you should call either execute3D() or execute2D() methods to render the material.
- */
- static CreateTonemapLUTMat* getVariation(bool is3D);
- /** Size of the 3D color lookup table. */
- static const UINT32 LUT_SIZE = 32;
- private:
- /** Populates the parameter block buffers using the provided settings. */
- void populateParamBuffers(const RenderSettings& settings);
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- SPtr<GpuParamBlockBuffer> mWhiteBalanceParamBuffer;
- GpuParamLoadStoreTexture mOutputTex;
- bool mIs3D;
- };
- BS_PARAM_BLOCK_BEGIN(TonemappingParamDef)
- BS_PARAM_BLOCK_ENTRY(float, gRawGamma)
- BS_PARAM_BLOCK_ENTRY(float, gManualExposureScale)
- BS_PARAM_BLOCK_ENTRY(int, gNumSamples)
- BS_PARAM_BLOCK_END
- extern TonemappingParamDef gTonemappingParamDef;
- /** Shader that applies tonemapping and converts a HDR image into a LDR image. */
- class TonemappingMat : public RendererMaterial<TonemappingMat>
- {
- RMAT_DEF_CUSTOMIZED("PPTonemapping.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool volumeLUT, bool gammaOnly, bool autoExposure, bool MSAA>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("VOLUME_LUT", volumeLUT),
- ShaderVariation::Param("GAMMA_ONLY", gammaOnly),
- ShaderVariation::Param("AUTO_EXPOSURE", autoExposure),
- ShaderVariation::Param("MSAA", MSAA),
- });
- return variation;
- }
- public:
- TonemappingMat();
- /** Executes the post-process effect with the provided parameters. */
- void execute(const SPtr<Texture>& sceneColor, const SPtr<Texture>& eyeAdaptation, const SPtr<Texture>& colorLUT,
- const SPtr<RenderTarget>& output, const RenderSettings& settings);
- /** Returns the material variation matching the provided parameters. */
- static TonemappingMat* getVariation(bool volumeLUT, bool gammaOnly, bool autoExposure, bool MSAA);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTex;
- GpuParamTexture mColorLUT;
- GpuParamTexture mEyeAdaptationTex;
- };
- const int MAX_BLUR_SAMPLES = 128;
- BS_PARAM_BLOCK_BEGIN(GaussianBlurParamDef)
- BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gSampleOffsets, (MAX_BLUR_SAMPLES + 1) / 2)
- BS_PARAM_BLOCK_ENTRY_ARRAY(Vector4, gSampleWeights, (MAX_BLUR_SAMPLES + 3) / 4)
- BS_PARAM_BLOCK_ENTRY(int, gNumSamples)
- BS_PARAM_BLOCK_END
- extern GaussianBlurParamDef gGaussianBlurParamDef;
- /** Shader that performs Gaussian blur filtering on the provided texture. */
- class GaussianBlurMat : public RendererMaterial<GaussianBlurMat>
- {
- // Direction of the Gaussian filter pass
- enum Direction
- {
- DirVertical,
- DirHorizontal
- };
- RMAT_DEF_CUSTOMIZED("PPGaussianBlur.bsl");
- public:
- GaussianBlurMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] source Input texture to blur.
- * @param[in] filterSize Size of the blurring filter, in percent of the source texture. In range [0, 1].
- * @param[in] destination Output texture to which to write the blurred image to.
- */
- void execute(const SPtr<Texture>& source, float filterSize, const SPtr<RenderTexture>& destination);
- private:
- /** Calculates weights and offsets for the standard distribution of the specified filter size. */
- static UINT32 calcStdDistribution(float filterRadius, std::array<float, MAX_BLUR_SAMPLES>& weights,
- std::array<float, MAX_BLUR_SAMPLES>& offsets);
- /** Calculates the radius of the blur kernel depending on the source texture size and provided scale. */
- static float calcKernelRadius(const SPtr<Texture>& source, float scale, Direction filterDir);
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTexture;
- };
- BS_PARAM_BLOCK_BEGIN(GaussianDOFParamDef)
- BS_PARAM_BLOCK_ENTRY(float, gNearBlurPlane)
- BS_PARAM_BLOCK_ENTRY(float, gFarBlurPlane)
- BS_PARAM_BLOCK_ENTRY(float, gInvNearBlurRange)
- BS_PARAM_BLOCK_ENTRY(float, gInvFarBlurRange)
- BS_PARAM_BLOCK_ENTRY(Vector2, gHalfPixelOffset)
- BS_PARAM_BLOCK_END
- extern GaussianDOFParamDef sGaussianDOFParamDef;
- /**
- * Shader that masks pixels from the input color texture into one or two output textures. The masking is done by
- * determining if the pixel falls into near or far unfocused plane, as determined by depth-of-field parameters. User
- * can pick whether to output pixels just on the near plane, just on the far plane, or both.
- *
- */
- class GaussianDOFSeparateMat : public RendererMaterial<GaussianDOFSeparateMat>
- {
- RMAT_DEF("PPGaussianDOFSeparate.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool near, bool far>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("NEAR", near),
- ShaderVariation::Param("FAR", far)
- });
- return variation;
- }
- public:
- GaussianDOFSeparateMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] color Input color texture to process.
- * @param[in] depth Input depth buffer texture that will be used for determining pixel depth.
- * @param[in] view View through which the depth of field effect is viewed.
- * @param[in] settings Settings used to control depth of field rendering.
- */
- void execute(const SPtr<Texture>& color, const SPtr<Texture>& depth, const RendererView& view,
- const DepthOfFieldSettings& settings);
- /**
- * Returns the texture generated after the shader was executed. Only valid to call this in-between calls to
- * execute() & release(), with @p idx value 0 or 1.
- */
- SPtr<PooledRenderTexture> getOutput(UINT32 idx);
- /**
- * Releases the interally allocated output render textures. Must be called after each call to execute(), when the
- * caller is done using the textures.
- */
- void release();
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param near If true, near plane pixels are output to the first render target.
- * @param far If true, far plane pixels are output to the first render target. If @p near is also enabled, the
- * pixels are output to the second render target instead.
- */
- static GaussianDOFSeparateMat* getVariation(bool near, bool far);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mColorTexture;
- GpuParamTexture mDepthTexture;
- SPtr<PooledRenderTexture> mOutput0;
- SPtr<PooledRenderTexture> mOutput1;
- };
- /**
- * Shader that combines pixels for near unfocused, focused and far unfocused planes, as calculated by
- * GaussianDOFSeparateMat. Outputs final depth-of-field filtered image.
- */
- class GaussianDOFCombineMat : public RendererMaterial<GaussianDOFCombineMat>
- {
- RMAT_DEF("PPGaussianDOFCombine.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool near, bool far>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("NEAR", near),
- ShaderVariation::Param("FAR", far),
- });
- return variation;
- }
- public:
- GaussianDOFCombineMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] focused Input texture containing focused (default) scene color.
- * @param[in] near Input texture containing filtered (blurred) values for the unfocused foreground area.
- * Can be null if no near plane needs to be blended.
- * @param[in] far Input texture containing filtered (blurred) values for the unfocused background area.
- * Can be null if no far plane needs to be blended.
- * @param[in] depth Input depth buffer texture that will be used for determining pixel depth.
- * @param[in] output Texture to output the results to.
- * @param[in] view View through which the depth of field effect is viewed.
- * @param[in] settings Settings used to control depth of field rendering.
- */
- void execute(const SPtr<Texture>& focused, const SPtr<Texture>& near, const SPtr<Texture>& far,
- const SPtr<Texture>& depth, const SPtr<RenderTarget>& output, const RendererView& view,
- const DepthOfFieldSettings& settings);
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param near If true, near plane pixels are read from the near plane texture, otherwise near plane is assumed
- * not to exist.
- * @param far If true, far plane pixels are read from the far plane texture, otherwise far plane is assumed not
- * to exist.
- */
- static GaussianDOFCombineMat* getVariation(bool near, bool far);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mFocusedTexture;
- GpuParamTexture mNearTexture;
- GpuParamTexture mFarTexture;
- GpuParamTexture mDepthTexture;
- };
- BS_PARAM_BLOCK_BEGIN(BuildHiZFParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gHalfPixelOffset)
- BS_PARAM_BLOCK_ENTRY(int, gMipLevel)
- BS_PARAM_BLOCK_END
- extern BuildHiZFParamDef sBuildHiZFParamDef;
- /** Shader that calculates a single level of the hierarchical Z mipmap chain. */
- class BuildHiZMat : public RendererMaterial<BuildHiZMat>
- {
- RMAT_DEF("PPBuildHiZ.bsl");
- public:
- BuildHiZMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] source Input depth texture to use as the source.
- * @param[in] srcMip Mip level to read from the @p source texture.
- * @param[in] srcRect Rectangle in normalized coordinates, describing from which portion of the source
- * texture to read the input.
- * @param[in] dstRect Destination rectangle to limit the writes to.
- * @param[in] output Output target to which to write to results.
- */
- void execute(const SPtr<Texture>& source, UINT32 srcMip, const Rect2& srcRect, const Rect2& dstRect,
- const SPtr<RenderTexture>& output);
- private:
- GpuParamTexture mInputTexture;
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- };
- BS_PARAM_BLOCK_BEGIN(FXAAParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gInvTexSize)
- BS_PARAM_BLOCK_END
- extern FXAAParamDef gFXAAParamDef;
- /** Shader that performs Fast Approximate anti-aliasing. */
- class FXAAMat : public RendererMaterial<FXAAMat>
- {
- RMAT_DEF("PPFXAA.bsl");
- public:
- FXAAMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] source Input texture to apply FXAA to.
- * @param[in] destination Output target to which to write the antialiased image to.
- */
- void execute(const SPtr<Texture>& source, const SPtr<RenderTarget>& destination);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTexture;
- };
- BS_PARAM_BLOCK_BEGIN(SSAOParamDef)
- BS_PARAM_BLOCK_ENTRY(float, gSampleRadius)
- BS_PARAM_BLOCK_ENTRY(float, gWorldSpaceRadiusMask)
- BS_PARAM_BLOCK_ENTRY(Vector2, gTanHalfFOV)
- BS_PARAM_BLOCK_ENTRY(Vector2, gRandomTileScale)
- BS_PARAM_BLOCK_ENTRY(float, gCotHalfFOV)
- BS_PARAM_BLOCK_ENTRY(float, gBias)
- BS_PARAM_BLOCK_ENTRY(Vector2, gDownsampledPixelSize)
- BS_PARAM_BLOCK_ENTRY(Vector2, gFadeMultiplyAdd)
- BS_PARAM_BLOCK_ENTRY(float, gPower)
- BS_PARAM_BLOCK_ENTRY(float, gIntensity)
- BS_PARAM_BLOCK_END
- extern SSAOParamDef gSSAOParamDef;
- /** Textures used as input when calculating SSAO. */
- struct SSAOTextureInputs
- {
- /** Full resolution scene depth. Only used by final SSAO pass. */
- SPtr<Texture> sceneDepth;
- /** Full resolution buffer containing scene normals. Only used by final SSAO pass. */
- SPtr<Texture> sceneNormals;
- /** Precalculated texture containing downsampled normals/depth, to be used for AO input. */
- SPtr<Texture> aoSetup;
- /** Texture containing AO from the previous pass. Only used if upsampling is enabled. */
- SPtr<Texture> aoDownsampled;
- /** Tileable texture containing random rotations that will be applied to AO samples. */
- SPtr<Texture> randomRotations;
- };
- /** Shader that computes ambient occlusion using screen based methods. */
- class SSAOMat : public RendererMaterial<SSAOMat>
- {
- RMAT_DEF("PPSSAO.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool upsample, bool finalPass, int quality>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("MIX_WITH_UPSAMPLED", upsample),
- ShaderVariation::Param("FINAL_AO", finalPass),
- ShaderVariation::Param("QUALITY", quality)
- });
- return variation;
- }
- public:
- SSAOMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] textures Set of textures to be used as input. Which textures are used depends on the
- * template parameters of this class.
- * @param[in] destination Output texture to which to write the ambient occlusion data to.
- * @param[in] settings Settings used to control the ambient occlusion effect.
- */
- void execute(const RendererView& view, const SSAOTextureInputs& textures, const SPtr<RenderTexture>& destination,
- const AmbientOcclusionSettings& settings);
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param upsample If true the shader will blend the calculated AO with AO data from the previous pass.
- * @param finalPass If true the shader will use the full screen normal/depth information and perform
- * intensity scaling, as well as distance fade. Otherwise the shader will use the
- * downsampled AO setup information, with no scaling/fade.
- * @param quality Integer in range [0, 4] that controls the quality of SSAO sampling. Higher numbers yield
- * better quality at the cost of performance.
- */
- static SSAOMat* getVariation(bool upsample, bool finalPass, int quality);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mDepthTexture;
- GpuParamTexture mNormalsTexture;
- GpuParamTexture mDownsampledAOTexture;
- GpuParamTexture mSetupAOTexture;
- GpuParamTexture mRandomTexture;
- };
- BS_PARAM_BLOCK_BEGIN(SSAODownsampleParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gPixelSize)
- BS_PARAM_BLOCK_ENTRY(float, gInvDepthThreshold)
- BS_PARAM_BLOCK_END
- extern SSAODownsampleParamDef gSSAODownsampleParamDef;
- /**
- * Shader that downsamples the depth & normal buffer and stores their results in a common texture, to be consumed
- * by SSAOMat.
- */
- class SSAODownsampleMat : public RendererMaterial<SSAODownsampleMat>
- {
- RMAT_DEF("PPSSAODownsample.bsl");
- public:
- SSAODownsampleMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] sceneDepth Input texture containing scene depth.
- * @param[in] sceneNormals Input texture containing scene world space normals.
- * @param[in] destination Output texture to which to write the downsampled data to.
- * @param[in] depthRange Valid depth range (in view space) within which nearby samples will be averaged.
- */
- void execute(const RendererView& view, const SPtr<Texture>& sceneDepth, const SPtr<Texture>& sceneNormals,
- const SPtr<RenderTexture>& destination, float depthRange);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mDepthTexture;
- GpuParamTexture mNormalsTexture;
- };
- BS_PARAM_BLOCK_BEGIN(SSAOBlurParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gPixelSize)
- BS_PARAM_BLOCK_ENTRY(Vector2, gPixelOffset)
- BS_PARAM_BLOCK_ENTRY(float, gInvDepthThreshold)
- BS_PARAM_BLOCK_END
- extern SSAOBlurParamDef gSSAOBlurParamDef;
- /**
- * Shaders that blurs the ambient occlusion output, in order to hide the noise caused by the randomization texture.
- */
- class SSAOBlurMat : public RendererMaterial<SSAOBlurMat>
- {
- RMAT_DEF("PPSSAOBlur.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool horizontal>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("DIR_HORZ", horizontal)
- });
- return variation;
- }
- public:
- SSAOBlurMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] ao Input texture containing ambient occlusion data to be blurred.
- * @param[in] sceneDepth Input texture containing scene depth.
- * @param[in] destination Output texture to which to write the blurred data to.
- * @param[in] depthRange Valid depth range (in view space) within which nearby samples will be averaged.
- */
- void execute(const RendererView& view, const SPtr<Texture>& ao, const SPtr<Texture>& sceneDepth,
- const SPtr<RenderTexture>& destination, float depthRange);
- /** Returns the material variation matching the provided parameters. */
- static SSAOBlurMat* getVariation(bool horizontal);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mAOTexture;
- GpuParamTexture mDepthTexture;
- };
- BS_PARAM_BLOCK_BEGIN(SSRStencilParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gRoughnessScaleBias)
- BS_PARAM_BLOCK_END
- extern SSRStencilParamDef gSSRStencilParamDef;
- /** Shader used for marking which parts of the screen require screen space reflections. */
- class SSRStencilMat : public RendererMaterial<SSRStencilMat>
- {
- RMAT_DEF("PPSSRStencil.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool msaa, bool singleSampleMSAA>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("MSAA_COUNT", msaa ? 2 : 1),
- ShaderVariation::Param("MSAA_RESOLVE_0TH", singleSampleMSAA)
- });
- return variation;
- }
- public:
- SSRStencilMat();
- /**
- * Renders the effect with the provided parameters, using the currently bound render target.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] gbuffer GBuffer textures.
- * @param[in] settings Parameters used for controling the SSR effect.
- */
- void execute(const RendererView& view, GBufferTextures gbuffer, const ScreenSpaceReflectionsSettings& settings);
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param[in] msaa True if the shader will operate on a multisampled surface.
- * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
- * evaluated. Otherwise all samples will be evaluated.
- * @return Requested variation of the material.
- */
- static SSRStencilMat* getVariation(bool msaa, bool singleSampleMSAA);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GBufferParams mGBufferParams;
- };
- BS_PARAM_BLOCK_BEGIN(SSRTraceParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector4, gNDCToHiZUV)
- BS_PARAM_BLOCK_ENTRY(Vector2, gHiZUVToScreenUV)
- BS_PARAM_BLOCK_ENTRY(Vector2I, gHiZSize)
- BS_PARAM_BLOCK_ENTRY(int, gHiZNumMips)
- BS_PARAM_BLOCK_ENTRY(float, gIntensity)
- BS_PARAM_BLOCK_ENTRY(Vector2, gRoughnessScaleBias)
- BS_PARAM_BLOCK_ENTRY(int, gTemporalJitter)
- BS_PARAM_BLOCK_END
- extern SSRTraceParamDef gSSRTraceParamDef;
- /** Shader used for tracing rays for screen space reflections. */
- class SSRTraceMat : public RendererMaterial<SSRTraceMat>
- {
- RMAT_DEF("PPSSRTrace.bsl");
- /** Helper method used for initializing variations of this material. */
- template<UINT32 quality, bool msaa, bool singleSampleMSAA>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("MSAA_COUNT", msaa ? 2 : 1),
- ShaderVariation::Param("QUALITY", quality),
- ShaderVariation::Param("MSAA_RESOLVE_0TH", singleSampleMSAA)
- });
- return variation;
- }
- public:
- SSRTraceMat();
- /**
- * Renders the effect with the provided parameters.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] gbuffer GBuffer textures.
- * @param[in] sceneColor Scene color texture.
- * @param[in] hiZ Hierarchical Z buffer.
- * @param[in] settings Parameters used for controling the SSR effect.
- * @param[in] destination Render target to which to write the results to.
- */
- void execute(const RendererView& view, GBufferTextures gbuffer, const SPtr<Texture>& sceneColor,
- const SPtr<Texture>& hiZ, const ScreenSpaceReflectionsSettings& settings,
- const SPtr<RenderTarget>& destination);
- /**
- * Calculates a scale & bias that is used for transforming roughness into a fade out value. Anything that is below
- * @p maxRoughness will have the fade value of 1. Values above @p maxRoughness is slowly fade out over a range that
- * is 1/2 the length of @p maxRoughness.
- */
- static Vector2 calcRoughnessFadeScaleBias(float maxRoughness);
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param[in] quality Determines how many rays to trace. In range [0, 4].
- * @param[in] msaa True if the shader will operate on a multisampled surface.
- * @param[in] singleSampleMSAA Only relevant of @p msaa is true. When enabled only the first sample will be
- * evaluated. Otherwise all samples will be evaluated.
- * @return Requested variation of the material.
- */
- static SSRTraceMat* getVariation(UINT32 quality, bool msaa, bool singleSampleMSAA = false);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GBufferParams mGBufferParams;
- GpuParamTexture mSceneColorTexture;
- GpuParamTexture mHiZTexture;
- };
- BS_PARAM_BLOCK_BEGIN(TemporalResolveParamDef)
- BS_PARAM_BLOCK_ENTRY_ARRAY(float, gSampleWeights, 9)
- BS_PARAM_BLOCK_ENTRY_ARRAY(float, gSampleWeightsLowpass, 9)
- BS_PARAM_BLOCK_END
- extern TemporalResolveParamDef gTemporalResolveParamDef;
- BS_PARAM_BLOCK_BEGIN(SSRResolveParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector2, gSceneDepthTexelSize)
- BS_PARAM_BLOCK_ENTRY(Vector2, gSceneColorTexelSize)
- BS_PARAM_BLOCK_ENTRY(float, gManualExposure)
- BS_PARAM_BLOCK_END
- extern SSRResolveParamDef gSSRResolveParamDef;
- /** Shader used for combining SSR information from the previous frame, in order to yield better quality. */
- class SSRResolveMat : public RendererMaterial<SSRResolveMat>
- {
- RMAT_DEF("PPSSRResolve.bsl");
- /** Helper method used for initializing variations of this material. */
- template<bool msaa>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("MSAA", msaa)
- });
- return variation;
- }
- public:
- SSRResolveMat();
- /**
- * Renders the effect with the provided parameters.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] prevFrame SSR data calculated previous frame.
- * @param[in] curFrame SSR data calculated this frame.
- * @param[in] sceneDepth Buffer containing scene depth.
- * @param[in] destination Render target to which to write the results to.
- */
- void execute(const RendererView& view, const SPtr<Texture>& prevFrame, const SPtr<Texture>& curFrame,
- const SPtr<Texture>& sceneDepth, const SPtr<RenderTarget>& destination);
- /**
- * Returns the material variation matching the provided parameters.
- *
- * @param[in] msaa True if the shader will operate on a multisampled surface. Note that previous
- * and current frame color textures must be non-MSAA, regardless of this parameter.
- * @return Requested variation of the material.
- */
- static SSRResolveMat* getVariation(bool msaa);
- private:
- SPtr<GpuParamBlockBuffer> mSSRParamBuffer;
- SPtr<GpuParamBlockBuffer> mTemporalParamBuffer;
- GpuParamTexture mSceneColorTexture;
- GpuParamTexture mPrevColorTexture;
- GpuParamTexture mSceneDepthTexture;
- GpuParamTexture mEyeAdaptationTexture;
- };
- BS_PARAM_BLOCK_BEGIN(EncodeDepthParamDef)
- BS_PARAM_BLOCK_ENTRY(float, gNear)
- BS_PARAM_BLOCK_ENTRY(float, gFar)
- BS_PARAM_BLOCK_END
- extern EncodeDepthParamDef gEncodeDepthParamDef;
- /**
- * Shader that encodes depth from a specified range into [0, 1] range, and writes the result in the alpha channel
- * of the output texture.
- */
- class EncodeDepthMat : public RendererMaterial<EncodeDepthMat>
- {
- RMAT_DEF("PPEncodeDepth.bsl");
- public:
- EncodeDepthMat();
- /**
- * Renders the post-process effect with the provided parameters.
- *
- * @param[in] depth Resolved (non-MSAA) depth texture to encode.
- * @param[in] near Near range (in view space) to start encoding the depth. Any depth lower than this will
- * be encoded to 1.
- * @param[in] far Far range (in view space) to end encoding the depth. Any depth higher than this will
- * be encoded to 0.
- * @param[in] output Output texture to write the results in. Results will be written in the alpha channel.
- */
- void execute(const SPtr<Texture>& depth, float near, float far, const SPtr<RenderTarget>& output);
- private:
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- GpuParamTexture mInputTexture;
- };
- /**
- * Shader that outputs a texture that determines which pixels require per-sample evaluation. Only relevant when
- * rendering with MSAA enabled.
- */
- class MSAACoverageMat : public RendererMaterial<MSAACoverageMat>
- {
- RMAT_DEF("MSAACoverage.bsl");
- /** Helper method used for initializing variations of this material. */
- template<UINT32 msaa>
- static const ShaderVariation& getVariation()
- {
- static ShaderVariation variation = ShaderVariation({
- ShaderVariation::Param("MSAA_COUNT", msaa)
- });
- return variation;
- }
- public:
- MSAACoverageMat();
- /**
- * Renders the effect with the provided parameters, using the currently bound render target.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] gbuffer GBuffer textures.
- */
- void execute(const RendererView& view, GBufferTextures gbuffer);
- /** Returns the material variation matching the provided parameters. */
- static MSAACoverageMat* getVariation(UINT32 msaaCount);
- private:
- GBufferParams mGBufferParams;
- };
- /**
- * Converts the coverage texture output by MSAACoverageMat and writes its information in the highest bit of the
- * currently bound stencil buffer. This allows coverage information to be used by normal (non-compute) rendering
- * shaders.
- */
- class MSAACoverageStencilMat : public RendererMaterial<MSAACoverageStencilMat>
- {
- RMAT_DEF("MSAACoverageStencil.bsl");
- public:
- MSAACoverageStencilMat();
- /**
- * Renders the effect with the provided parameters, using the currently bound render target.
- *
- * @param[in] view Information about the view we're rendering from.
- * @param[in] coverage Coverage texture as output by MSAACoverageMat.
- */
- void execute(const RendererView& view, const SPtr<Texture>& coverage);
- private:
- GpuParamTexture mCoverageTexParam;
- };
- /** @} */
- }}
|