| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #pragma once
- #include "BsRenderBeastPrerequisites.h"
- #include "BsPostProcessing.h"
- #include "BsObjectRendering.h"
- #include "BsRenderQueue.h"
- #include "BsRendererObject.h"
- #include "BsBounds.h"
- #include "BsConvexVolume.h"
- namespace bs { namespace ct
- {
- /** @addtogroup RenderBeast
- * @{
- */
- BS_PARAM_BLOCK_BEGIN(PerCameraParamDef)
- BS_PARAM_BLOCK_ENTRY(Vector3, gViewDir)
- BS_PARAM_BLOCK_ENTRY(Vector3, gViewOrigin)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatViewProj)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatView)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatProj)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvProj)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatInvViewProj)
- BS_PARAM_BLOCK_ENTRY(Matrix4, gMatScreenToWorld)
- BS_PARAM_BLOCK_ENTRY(Vector2, gDeviceZToWorldZ)
- BS_PARAM_BLOCK_ENTRY(Vector2, gNDCZToWorldZ)
- BS_PARAM_BLOCK_ENTRY(Vector2, gNearFar)
- BS_PARAM_BLOCK_ENTRY(Vector4I, gViewportRectangle)
- BS_PARAM_BLOCK_ENTRY(Vector4, gClipToUVScaleOffset)
- BS_PARAM_BLOCK_ENTRY(float, gAmbientFactor)
- BS_PARAM_BLOCK_END
- extern PerCameraParamDef gPerCameraParamDef;
- BS_PARAM_BLOCK_BEGIN(SkyboxParamDef)
- BS_PARAM_BLOCK_ENTRY(Color, gClearColor)
- BS_PARAM_BLOCK_END
- extern SkyboxParamDef gSkyboxParamDef;
- /** Shader that renders a skybox using a cubemap or a solid color. */
- template<bool SOLID_COLOR>
- class SkyboxMat : public RendererMaterial<SkyboxMat<SOLID_COLOR>>
- {
- RMAT_DEF("Skybox.bsl");
- public:
- SkyboxMat();
- /** Binds the material for rendering and sets up any global parameters. */
- void bind(const SPtr<GpuParamBlockBuffer>& perCamera);
- /** Updates the skybox texture & solid color used by the material. */
- void setParams(const SPtr<Texture>& texture, const Color& solidColor);
- private:
- GpuParamTexture mSkyTextureParam;
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- };
- /** Set of properties describing the output render target used by a renderer view. */
- struct RENDERER_VIEW_TARGET_DESC
- {
- SPtr<RenderTarget> target;
- Rect2I viewRect;
- Rect2 nrmViewRect;
- UINT32 targetWidth;
- UINT32 targetHeight;
- UINT32 numSamples;
- UINT32 clearFlags;
- Color clearColor;
- float clearDepthValue;
- UINT16 clearStencilValue;
- };
- /** Set of properties used describing a specific view that the renderer can render. */
- struct RENDERER_VIEW_DESC
- {
- RENDERER_VIEW_TARGET_DESC target;
- Matrix4 viewTransform;
- Matrix4 projTransform;
- Vector3 viewDirection;
- Vector3 viewOrigin;
- bool flipView;
- float nearPlane;
- float farPlane;
- bool isOverlay : 1;
- bool isHDR : 1;
- bool noLighting : 1;
- bool triggerCallbacks : 1;
- bool runPostProcessing : 1;
- bool renderingReflections : 1;
- UINT64 visibleLayers;
- ConvexVolume cullFrustum;
- StateReduction stateReduction;
- const Camera* sceneCamera;
- };
- /** Information whether certain scene objects are visible in a view, per object type. */
- struct VisibilityInfo
- {
- Vector<bool> renderables;
- };
- /** Information used for culling an object against a view. */
- struct CullInfo
- {
- CullInfo(const Bounds& bounds, UINT64 layer = -1)
- :bounds(bounds), layer(layer)
- { }
- Bounds bounds;
- UINT64 layer;
- };
- /** Contains information about a Camera, used by the Renderer. */
- class RendererCamera
- {
- public:
- RendererCamera();
- RendererCamera(const RENDERER_VIEW_DESC& desc);
- /** Sets state reduction mode that determines how do render queues group & sort renderables. */
- void setStateReductionMode(StateReduction reductionMode);
- /** Updates the internal camera post-processing data. */
- void setPostProcessSettings(const SPtr<PostProcessSettings>& ppSettings);
- /** Updates the internal information with a new view transform. */
- void setTransform(const Vector3& origin, const Vector3& direction, const Matrix4& view,
- const Matrix4& proj, const ConvexVolume& worldFrustum);
- /** Updates all internal information with new view information. */
- void setView(const RENDERER_VIEW_DESC& desc);
- /** Returns the world position of the view. */
- Vector3 getViewOrigin() const { return mViewDesc.viewOrigin; }
- /** Returns a matrix that contains combined projection and view transforms. */
- Matrix4 getViewProjMatrix() const { return mViewDesc.projTransform * mViewDesc.viewTransform; }
- /** Returns the distance to the near clipping plane. */
- float getNearPlane() const { return mViewDesc.nearPlane; }
- /** Returns the distance to the far clipping plane. */
- float getFarPlane() const { return mViewDesc.farPlane; }
- /** Returns true if the view requires high dynamic range rendering. */
- bool isHDR() const { return mViewDesc.isHDR; }
- /** Returns true if this view only renders overlay, and not scene objects. */
- bool isOverlay() const { return mViewDesc.isOverlay; }
- /** Returns true if the view should be rendered with no lighting. */
- bool renderWithNoLighting() const { return mViewDesc.noLighting; }
- /** Returns the final render target the rendered contents should be output to. */
- SPtr<RenderTarget> getFinalTarget() const { return mViewDesc.target.target; }
- /** Returns normalized coordinates of the viewport area this view renders to. */
- Rect2 getViewportRect() const { return mViewDesc.target.nrmViewRect; }
- /** Returns true if the resulting render target should be flipped vertically. */
- bool getFlipView() const { return mViewDesc.flipView; }
- /** Returns the color to clear the non-rendered areas of the scene color target to. */
- Color getClearColor() const { return mViewDesc.target.clearColor; }
- /** Returns the number of samples per pixel to render. */
- UINT32 getNumSamples() const { return mViewDesc.target.numSamples; }
- /** Returns true if the current view is being used to render reflection probes. */
- bool isRenderingReflections() const { return mViewDesc.renderingReflections; }
- /** Returns the scene camera this object is based of. This can be null for manually constructed renderer cameras. */
- const Camera* getSceneCamera() const { return mViewDesc.sceneCamera; }
- /** Returns true if external render callbacks should trigger for this view. */
- bool checkTriggerCallbacks() const { return mViewDesc.triggerCallbacks; }
- /** Returns true if post-processing effects should be triggered for this view. */
- bool checkRunPostProcessing() const { return mViewDesc.runPostProcessing; }
- /**
- * Prepares render targets for rendering. When done call endRendering().
- *
- * @param[in] useGBuffer Set to true if you will be rendering to internal render targets containing the
- * GBuffer (retrieved via getRenderTargets()).
- */
- void beginRendering(bool useGBuffer);
- /** Ends rendering and frees any acquired resources. */
- void endRendering();
- /** Returns the view's renderTargets. Only valid if called in-between beginRendering() and endRendering() calls. */
- SPtr<RenderTargets> getRenderTargets() const { return mRenderTargets; }
- /**
- * Returns a render queue containing all opaque objects. Make sure to call determineVisible() beforehand if view
- * or object transforms changed since the last time it was called.
- */
- const SPtr<RenderQueue>& getOpaqueQueue() const { return mOpaqueQueue; }
-
- /**
- * Returns a render queue containing all transparent objects. Make sure to call determineVisible() beforehand if
- * view or object transforms changed since the last time it was called.
- */
- const SPtr<RenderQueue>& getTransparentQueue() const { return mTransparentQueue; }
- /**
- * Populates view render queues by determining visible renderable objects.
- *
- * @param[in] renderables A set of renderable objects to iterate over and determine visibility for.
- * @param[in] cullInfos A set of world bounds & other information relevant for culling the provided
- * renderable objects. Must be the same size as the @p renderables array.
- * @param[out] visibility Output parameter that will have the true bit set for any visible renderable
- * object. If the bit for an object is already set to true, the method will never
- * change it to false which allows the same bitfield to be provided to multiple
- * renderer views. Must be the same size as the @p renderables array.
- *
- * As a side-effect, per-view visibility data is also calculated and can be
- * retrieved by calling getVisibilityMask().
- */
- void determineVisible(const Vector<RendererObject*>& renderables, const Vector<CullInfo>& cullInfos,
- Vector<bool>* visibility = nullptr);
- /**
- * Culls the provided set of bounds against the current frustum and outputs a set of visibility flags determining
- * which entry is or ins't visible by this view. Both inputs must be arrays of the same size.
- */
- void calculateVisibility(const Vector<CullInfo>& cullInfos, Vector<bool>& visibility) const;
- /**
- * Culls the provided set of bounds against the current frustum and outputs a set of visibility flags determining
- * which entry is or ins't visible by this view. Both inputs must be arrays of the same size.
- */
- void calculateVisibility(const Vector<Sphere>& bounds, Vector<bool>& visibility) const;
- /** Returns the visibility mask calculated with the last call to determineVisible(). */
- const VisibilityInfo& getVisibilityMasks() const { return mVisibility; }
- /**
- * Returns a structure containing information about post-processing effects. This structure will be modified and
- * maintained by the post-processing system.
- */
- PostProcessInfo& getPPInfo() { return mPostProcessInfo; }
- /** Updates the GPU buffer containing per-view information, with the latest internal data. */
- void updatePerViewBuffer();
- /** Returns a buffer that stores per-view parameters. */
- SPtr<GpuParamBlockBuffer> getPerViewBuffer() const { return mParamBuffer; }
- private:
- /**
- * Extracts the necessary values from the projection matrix that allow you to transform device Z value (range [0, 1]
- * into view Z value.
- *
- * @param[in] projMatrix Projection matrix that was used to create the device Z value to transform.
- * @return Returns two values that can be used to transform device z to view z using this formula:
- * z = (deviceZ + y) * x.
- */
- Vector2 getDeviceZTransform(const Matrix4& projMatrix) const;
- /**
- * Extracts the necessary values from the projection matrix that allow you to transform NDC Z value (range depending
- * on render API) into view Z value.
- *
- * @param[in] projMatrix Projection matrix that was used to create the NDC Z value to transform.
- * @return Returns two values that can be used to transform NDC z to view z using this formula:
- * z = (NDCZ + y) * x.
- */
- Vector2 getNDCZTransform(const Matrix4& projMatrix) const;
- RENDERER_VIEW_DESC mViewDesc;
- SPtr<RenderQueue> mOpaqueQueue;
- SPtr<RenderQueue> mTransparentQueue;
- SPtr<RenderTargets> mRenderTargets;
- PostProcessInfo mPostProcessInfo;
- bool mUsingGBuffer;
- SPtr<GpuParamBlockBuffer> mParamBuffer;
- VisibilityInfo mVisibility;
- };
- /** @} */
- }}
|