From 808e69bebe7fba7d4fc188372c6712a1605cd566 Mon Sep 17 00:00:00 2001 From: "Matias N. Goldberg" Date: Thu, 30 Dec 2021 12:17:37 -0300 Subject: [PATCH] Apply clang-format to HlmsPbs (#235) --- Components/Hlms/Pbs/include/.clang-format | 43 + .../Pbs/include/Cubemaps/OgreCubemapProbe.h | 83 +- .../Cubemaps/OgreParallaxCorrectedCubemap.h | 107 +- .../OgreParallaxCorrectedCubemapAuto.h | 35 +- .../OgreParallaxCorrectedCubemapBase.h | 94 +- .../Cubemaps/OgrePccPerPixelGridPlacement.h | 14 +- .../InstantRadiosity/OgreInstantRadiosity.h | 212 +-- .../IrradianceField/OgreIfdProbeVisualizer.h | 6 +- .../IrradianceField/OgreIrradianceField.h | 66 +- .../OgreIrradianceFieldRaster.h | 8 +- .../Pbs/include/LightProfiles/OgreIesLoader.h | 2 +- .../include/LightProfiles/OgreLightProfiles.h | 6 +- Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h | 75 +- Components/Hlms/Pbs/include/OgreHlmsPbs.h | 239 +-- .../Hlms/Pbs/include/OgreHlmsPbsDatablock.h | 355 ++-- .../Pbs/include/OgreHlmsPbsPrerequisites.h | 44 +- .../Hlms/Pbs/include/OgreIrradianceVolume.h | 80 +- .../include/Vct/OgreVctCascadedVoxelizer.h | 20 +- .../Pbs/include/Vct/OgreVctImageVoxelizer.h | 15 +- .../Hlms/Pbs/include/Vct/OgreVctLighting.h | 90 +- .../Hlms/Pbs/include/Vct/OgreVctMaterial.h | 73 +- .../Hlms/Pbs/include/Vct/OgreVctVoxelizer.h | 153 +- .../include/Vct/OgreVctVoxelizerSourceBase.h | 16 +- .../Pbs/include/Vct/OgreVoxelVisualizer.h | 20 +- .../Pbs/include/Vct/OgreVoxelizedMeshCache.h | 16 +- .../Pbs/src/Cubemaps/OgreCubemapProbe.cpp | 141 +- .../Cubemaps/OgreParallaxCorrectedCubemap.cpp | 530 +++--- .../OgreParallaxCorrectedCubemapAuto.cpp | 159 +- .../OgreParallaxCorrectedCubemapBase.cpp | 101 +- .../Cubemaps/OgrePccPerPixelGridPlacement.cpp | 1 - .../InstantRadiosity/OgreInstantRadiosity.cpp | 883 +++++---- Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp | 253 ++- Components/Hlms/Pbs/src/OgreHlmsPbs.cpp | 1612 ++++++++--------- .../Hlms/Pbs/src/OgreHlmsPbsDatablock.cpp | 322 ++-- .../Hlms/Pbs/src/OgreIrradianceVolume.cpp | 226 +-- .../Hlms/Pbs/src/Vct/OgreVctLighting.cpp | 313 ++-- .../Hlms/Pbs/src/Vct/OgreVctMaterial.cpp | 105 +- .../Hlms/Pbs/src/Vct/OgreVctVoxelizer.cpp | 524 +++--- .../src/Vct/OgreVctVoxelizerSourceBase.cpp | 10 +- .../Hlms/Pbs/src/Vct/OgreVoxelVisualizer.cpp | 79 +- 40 files changed, 3448 insertions(+), 3683 deletions(-) create mode 100644 Components/Hlms/Pbs/include/.clang-format diff --git a/Components/Hlms/Pbs/include/.clang-format b/Components/Hlms/Pbs/include/.clang-format new file mode 100644 index 00000000000..a8982f3b213 --- /dev/null +++ b/Components/Hlms/Pbs/include/.clang-format @@ -0,0 +1,43 @@ +--- +BasedOnStyle: Google +AlignAfterOpenBracket: Align +#AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'true' +AlignEscapedNewlines: DontAlign +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: 'false' +AllowShortLoopsOnASingleLine: 'false' +BinPackParameters: 'true' +BreakBeforeBraces: Custom +ColumnLimit: '105' +ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' +BreakConstructorInitializers: 'AfterColon' +ConstructorInitializerIndentWidth: '4' +ContinuationIndentWidth: '4' +Cpp11BracedListStyle: 'false' +DerivePointerAlignment: 'false' +IndentCaseLabels: 'false' +IndentWidth: '4' +NamespaceIndentation: All +PointerAlignment: Right +SpaceBeforeParens: Never +SpaceInEmptyParentheses: 'false' +SpacesInParentheses: 'true' +TabWidth: '4' +UseTab: Never +AccessModifierOffset: '-4' +IndentPPDirectives: 'AfterHash' +BraceWrapping: + AfterClass: true + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + IndentBraces: false + +... diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h b/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h index ec0cbc33d08..df46cd2523a 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgreCubemapProbe.h @@ -29,12 +29,14 @@ THE SOFTWARE. #define _OgreCubemapProbe_H_ #include "OgreHlmsPbsPrerequisites.h" -#include "OgreVector3.h" + +#include "Compositor/OgreCompositorChannel.h" #include "Math/Simple/OgreAabb.h" #include "OgreIdString.h" #include "OgreTextureGpu.h" +#include "OgreVector3.h" + #include "OgreHeaderPrefix.h" -#include "Compositor/OgreCompositorChannel.h" namespace Ogre { @@ -47,48 +49,48 @@ namespace Ogre /// Where to position the camera while constructing the probe. Vector3 mProbeCameraPos; /// When the camera enters this area, the probe is collected for blending. - Aabb mArea; + Aabb mArea; /// Value between [0; 1] per axis. At 1, the inner region matches mArea (the outer region) Vector3 mAreaInnerRegion; /// Orientationt. These are not AABBs, but rather OBB (oriented bounding boxes). Matrix3 mOrientation; Matrix3 mInvOrientation; /// The general shape this probe is supposed to represent. - Aabb mProbeShape; + Aabb mProbeShape; - TextureGpu *mTexture; - uint16 mCubemapArrayIdx; + TextureGpu * mTexture; + uint16 mCubemapArrayIdx; SampleDescription mSampleDescription; - IdString mWorkspaceDefName; + IdString mWorkspaceDefName; CompositorWorkspace *mClearWorkspace; CompositorWorkspace *mWorkspace; - Camera *mCamera; + Camera * mCamera; ParallaxCorrectedCubemapBase *mCreator; - InternalCubemapProbe *mInternalProbe; + InternalCubemapProbe *mInternalProbe; - ConstBufferPacked *mConstBufferForManualProbes; - uint32 mNumDatablockUsers; + ConstBufferPacked *mConstBufferForManualProbes; + uint32 mNumDatablockUsers; - uint16 mPriority; + uint16 mPriority; /// False if it should be updated every frame. True if only updated when dirty - bool mStatic; + bool mStatic; public: /// While disabled, this probe won't be updated (even if dirty) and won't be considered /// for blending (i.e. won't be used at all). - bool mEnabled; + bool mEnabled; /// True if we must re-render to update the texture's contents. False when we don't. - bool mDirty; + bool mDirty; /// Number of iterations. The more iterations, the more light bounces and /// light reflections we can capture (i.e. mirror of mirrors), but it will /// take longer to rebuild the probe. /// Default value is 32. /// For non-static probes, you should set this value to 1 for performance. - uint16 mNumIterations; + uint16 mNumIterations; /// Mask to group probes. This probe will only be updated (even if dirty) and /// blended if mMask & system->mMask is non-zero. @@ -98,9 +100,10 @@ namespace Ogre /// Or if you have per room probes, but during a panoramic shot where many rooms /// are in sight, and you want a more "global" probe. /// Defaults to 0xffffffff - uint32 mMask; + uint32 mMask; void destroyWorkspace(); + protected: void destroyTexture(); @@ -136,9 +139,9 @@ namespace Ogre mipmaps at the probe level. User is responsible for supplying a workspace definition that will generate mipmaps though! */ - void setTextureParams( uint32 width, uint32 height, bool useManual=false, - PixelFormatGpu pf=PFG_RGBA8_UNORM_SRGB, bool isStatic=true, - SampleDescription sampleDesc=SampleDescription() ); + void setTextureParams( uint32 width, uint32 height, bool useManual = false, + PixelFormatGpu pf = PFG_RGBA8_UNORM_SRGB, bool isStatic = true, + SampleDescription sampleDesc = SampleDescription() ); /** Initializes the workspace so we can actually render to the cubemap. You must call setTextureParams first. @@ -159,9 +162,9 @@ namespace Ogre This value allows you to override it with a different workspace definition. */ void initWorkspace( float cameraNear = 0.5f, float cameraFar = 500.0f, - IdString workspaceDefOverride = IdString(), + IdString workspaceDefOverride = IdString(), const CompositorChannelVec &additionalChannels = CompositorChannelVec(), - uint8 executionMask = 0xFF ); + uint8 executionMask = 0xFF ); bool isInitialized() const; /** Sets cubemap probe's parameters. @@ -184,8 +187,7 @@ namespace Ogre The OBB should closely match the shape of the environment around it. The better it fits, the more accurate the reflections. */ - void set( const Vector3 &cameraPos, - const Aabb &area, const Vector3 &areaInnerRegion, + void set( const Vector3 &cameraPos, const Aabb &area, const Vector3 &areaInnerRegion, const Matrix3 &orientation, const Aabb &probeShape ); /** Set to False if it should be updated every frame. True if only updated when dirty @@ -193,7 +195,7 @@ namespace Ogre This call is not cheap. */ void setStatic( bool isStatic ); - bool getStatic() const { return mStatic; } + bool getStatic() const { return mStatic; } /** When two probes overlap, you may want one probe to have particularly more influence than the others. Use this value to decrease/increase the weight when blending the probes. @@ -203,10 +205,10 @@ namespace Ogre A value in range [1; 65535] A higher value means the probe should have a stronger influence over the others. */ - void setPriority( uint16 priority ); + void setPriority( uint16 priority ); uint16_t getPriority() const; - Aabb getAreaLS() const { return Aabb( Vector3::ZERO, mArea.mHalfSize ); } + Aabb getAreaLS() const { return Aabb( Vector3::ZERO, mArea.mHalfSize ); } /** Gets the Normalized Distance Function. @param posLS @@ -223,28 +225,29 @@ namespace Ogre void _clearCubemap(); void _updateRender(); - const Vector3& getProbeCameraPos() const { return mProbeCameraPos; } - const Aabb& getArea() const { return mArea; } - const Vector3& getAreaInnerRegion() const { return mAreaInnerRegion; } - const Matrix3& getOrientation() const { return mOrientation; } - const Matrix3& getInvOrientation() const { return mInvOrientation; } - const Aabb& getProbeShape() const { return mProbeShape; } + const Vector3 &getProbeCameraPos() const { return mProbeCameraPos; } + const Aabb & getArea() const { return mArea; } + const Vector3 &getAreaInnerRegion() const { return mAreaInnerRegion; } + const Matrix3 &getOrientation() const { return mOrientation; } + const Matrix3 &getInvOrientation() const { return mInvOrientation; } + const Aabb & getProbeShape() const { return mProbeShape; } + + CompositorWorkspace *getWorkspace() const { return mWorkspace; } - CompositorWorkspace *getWorkspace() const { return mWorkspace; } + TextureGpu *getInternalTexture() const { return mTexture; } - TextureGpu* getInternalTexture() const { return mTexture; } void _addReference(); void _removeReference(); - const SceneNode* getInternalCubemapProbeSceneNode() const; + const SceneNode *getInternalCubemapProbeSceneNode() const; - uint16 getInternalSliceToArrayTexture() const { return mCubemapArrayIdx; } + uint16 getInternalSliceToArrayTexture() const { return mCubemapArrayIdx; } - ConstBufferPacked* getConstBufferForManualProbes() { return mConstBufferForManualProbes; } + ConstBufferPacked *getConstBufferForManualProbes() { return mConstBufferForManualProbes; } - ParallaxCorrectedCubemapBase* getCreator() { return mCreator; } + ParallaxCorrectedCubemapBase *getCreator() { return mCreator; } }; -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemap.h b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemap.h index d4b9a74f5da..4f1cee601e6 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemap.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemap.h @@ -32,10 +32,10 @@ THE SOFTWARE. #include "Cubemaps/OgreParallaxCorrectedCubemapBase.h" -#include "OgreResource.h" +#include "Compositor/OgreCompositorWorkspaceListener.h" #include "OgreFrameListener.h" #include "OgreGpuProgramParams.h" -#include "Compositor/OgreCompositorWorkspaceListener.h" +#include "OgreResource.h" #include "OgreHeaderPrefix.h" @@ -50,48 +50,51 @@ namespace Ogre public FrameListener, protected ManualResourceLoader { - CubemapProbe *mCollectedProbes[OGRE_MAX_CUBE_PROBES]; - uint32 mNumCollectedProbes; - Real mProbeNDFs[OGRE_MAX_CUBE_PROBES]; - Real mProbeBlendFactors[OGRE_MAX_CUBE_PROBES]; + CubemapProbe *mCollectedProbes[OGRE_MAX_CUBE_PROBES]; + uint32 mNumCollectedProbes; + Real mProbeNDFs[OGRE_MAX_CUBE_PROBES]; + Real mProbeBlendFactors[OGRE_MAX_CUBE_PROBES]; CubemapProbeVec mManuallyActiveProbes; - StagingBuffer *mStagingBuffer; + StagingBuffer * mStagingBuffer; size_t mLastPassNumViewMatrices; Matrix4 mCachedLastViewMatrix; - bool mBlendedProbeNeedsUpdate; + bool mBlendedProbeNeedsUpdate; /// This variable should be updated every frame and often represents the camera position, /// but it can also be used set to other things like the player's character position. - public: Vector3 mTrackedPosition; + public: + Vector3 mTrackedPosition; /// When mTrackedPosition is not inside any probe, we'll use the view-projection matrix /// to select the closest probe based on which one has approximately the largest volume /// shown on camera. See setUpdatedTrackedDataFromCamera if you don't know how to set this - public: Matrix4 mTrackedViewProjMatrix; + public: + Matrix4 mTrackedViewProjMatrix; + private: - GpuProgramParametersSharedPtr mBlendCubemapParamsVs[OGRE_MAX_CUBE_PROBES]; - GpuProgramParametersSharedPtr mBlendCubemapParams[OGRE_MAX_CUBE_PROBES]; - TextureUnitState *mBlendCubemapTUs[OGRE_MAX_CUBE_PROBES]; - GpuProgramParametersSharedPtr mCopyCubemapParams[6]; - TextureUnitState *mCopyCubemapTUs[6]; - CubemapProbe mBlankProbe; - CubemapProbe mFinalProbe; - Camera *mBlendProxyCamera; - CompositorWorkspace *mBlendWorkspace; - CompositorWorkspace *mCopyWorkspace; - HlmsSamplerblock const *mSamplerblockPoint; - float mCurrentMip; - uint32 mProxyVisibilityMask; - uint32 mProxyQueryMask; - uint8 mReservedRqId; - MeshPtr mProxyMesh; - Item *mProxyItems[OGRE_MAX_CUBE_PROBES]; - SceneNode *mProxyNodes[OGRE_MAX_CUBE_PROBES]; + GpuProgramParametersSharedPtr mBlendCubemapParamsVs[OGRE_MAX_CUBE_PROBES]; + GpuProgramParametersSharedPtr mBlendCubemapParams[OGRE_MAX_CUBE_PROBES]; + TextureUnitState * mBlendCubemapTUs[OGRE_MAX_CUBE_PROBES]; + GpuProgramParametersSharedPtr mCopyCubemapParams[6]; + TextureUnitState * mCopyCubemapTUs[6]; + CubemapProbe mBlankProbe; + CubemapProbe mFinalProbe; + Camera * mBlendProxyCamera; + CompositorWorkspace * mBlendWorkspace; + CompositorWorkspace * mCopyWorkspace; + HlmsSamplerblock const * mSamplerblockPoint; + float mCurrentMip; + uint32 mProxyVisibilityMask; + uint32 mProxyQueryMask; + uint8 mReservedRqId; + MeshPtr mProxyMesh; + Item * mProxyItems[OGRE_MAX_CUBE_PROBES]; + SceneNode * mProxyNodes[OGRE_MAX_CUBE_PROBES]; struct TempRtt { - TextureGpu *texture; + TextureGpu *texture; uint32 refCount; }; @@ -106,10 +109,11 @@ namespace Ogre /// The temp. RTTs can be shared by all probes if they match the same /// resolution and format. typedef vector::type TempRttVec; - TempRttVec mTmpRtt; - TempRttVec mIblRtt; + TempRttVec mTmpRtt; + TempRttVec mIblRtt; + + virtual void loadResource( Resource *resource ); - virtual void loadResource(Resource* resource); void createProxyGeometry(); void destroyProxyGeometry(); void createCubemapBlendWorkspaceDefinition(); @@ -191,57 +195,58 @@ namespace Ogre void updateAllDirtyProbes(); virtual void _notifyPreparePassHash( const Matrix4 &viewMatrix ); + virtual size_t getConstBufferSize(); - static size_t getConstBufferSizeStatic(); + static size_t getConstBufferSizeStatic(); + virtual void fillConstBufferData( const Matrix4 &viewMatrix, - float * RESTRICT_ALIAS passBufferPtr ) const; + float *RESTRICT_ALIAS passBufferPtr ) const; protected: TextureGpu *findRtt( const TextureGpu *baseParams, TempRttVec &container, uint32 textureFlags, bool fullMipmaps ); - void releaseRtt( const TextureGpu *rtt, TempRttVec &container ); + void releaseRtt( const TextureGpu *rtt, TempRttVec &container ); public: - /// See mTmpRtt. Finds an RTT that is compatible to copy to baseParams. /// Creates one if none found. - virtual TextureGpu* findTmpRtt( const TextureGpu *baseParams ); - virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); + virtual TextureGpu *findTmpRtt( const TextureGpu *baseParams ); + virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); - virtual TextureGpu* findIbl( const TextureGpu *baseParams ); - virtual void releaseIbl( const TextureGpu *tmpRtt ); + virtual TextureGpu *findIbl( const TextureGpu *baseParams ); + virtual void releaseIbl( const TextureGpu *tmpRtt ); virtual void _addManuallyActiveProbe( CubemapProbe *probe ); virtual void _removeManuallyActiveProbe( CubemapProbe *probe ); /// Returns the RenderQueue ID you told us you reserved for storing our internal objects. /// Do not attempt to render the objects that match in that Rq ID & visibility mask. - uint8 getProxyReservedRenderQueueId() const { return mReservedRqId; } + uint8 getProxyReservedRenderQueueId() const { return mReservedRqId; } /// Returns the visibility mask you told us you reserved for storing our internal objects. /// Do not attempt to render the objects that match in that Rq ID & visibility mask. - uint32 getProxyReservedVisibilityMask() const { return mProxyVisibilityMask; } + uint32 getProxyReservedVisibilityMask() const { return mProxyVisibilityMask; } /// Returns the query mask you told us you reserved for storing our internal objects. - uint32 getProxyReservedQueryMask() const { return mProxyQueryMask; } + uint32 getProxyReservedQueryMask() const { return mProxyQueryMask; } - Item * const * getProxyItems() const { return mProxyItems; } - SceneNode * const * getProxySceneNodes() const { return mProxyNodes; } + Item *const * getProxyItems() const { return mProxyItems; } + SceneNode *const *getProxySceneNodes() const { return mProxyNodes; } - //Statistics - uint32 getNumCollectedProbes() const { return mNumCollectedProbes; } + // Statistics + uint32 getNumCollectedProbes() const { return mNumCollectedProbes; } - //CompositorWorkspaceListener overloads + // CompositorWorkspaceListener overloads virtual void passPreExecute( CompositorPass *pass ); virtual void allWorkspacesBeforeBeginUpdate(); virtual void allWorkspacesBeginUpdate(); - //FrameListener overloads - virtual bool frameStarted( const FrameEvent& evt ); + // FrameListener overloads + virtual bool frameStarted( const FrameEvent &evt ); }; /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapAuto.h b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapAuto.h index c3581f158b7..266adc2a1af 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapAuto.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapAuto.h @@ -29,10 +29,13 @@ THE SOFTWARE. #define _OgreParallaxCorrectedCubemapAuto_H_ #include "OgreHlmsPbsPrerequisites.h" + #include "Cubemaps/OgreParallaxCorrectedCubemapBase.h" + +#include "Compositor/OgreCompositorWorkspaceListener.h" #include "OgreFrameListener.h" #include "OgreGpuProgramParams.h" -#include "Compositor/OgreCompositorWorkspaceListener.h" + #include "OgreHeaderPrefix.h" namespace Ogre @@ -69,12 +72,14 @@ namespace Ogre /// This variable should be updated every frame and often represents the camera position, /// but it can also be used set to other things like the player's character position. - public: Vector3 mTrackedPosition; + public: + Vector3 mTrackedPosition; + private: - TextureGpu *mRenderTarget; - TextureGpu *mIblTarget; + TextureGpu *mRenderTarget; + TextureGpu *mIblTarget; - vector::type mReservedSlotBitset; + vector::type mReservedSlotBitset; ParallaxCorrectedCubemapAutoListener *mListener; @@ -100,14 +105,14 @@ namespace Ogre void setListener( ParallaxCorrectedCubemapAutoListener *listener ) { mListener = listener; } ParallaxCorrectedCubemapAutoListener *getListener() const { return mListener; } - virtual TextureGpu* _acquireTextureSlot( uint16 &outTexSlot ); - virtual void _releaseTextureSlot( TextureGpu *texture, uint32 texSlot ); + virtual TextureGpu *_acquireTextureSlot( uint16 &outTexSlot ); + virtual void _releaseTextureSlot( TextureGpu *texture, uint32 texSlot ); - virtual TextureGpu* findTmpRtt( const TextureGpu *baseParams ); - virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); + virtual TextureGpu *findTmpRtt( const TextureGpu *baseParams ); + virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); - virtual TextureGpu* findIbl( const TextureGpu *baseParams ); - virtual void releaseIbl( const TextureGpu *tmpRtt ); + virtual TextureGpu *findIbl( const TextureGpu *baseParams ); + virtual void releaseIbl( const TextureGpu *tmpRtt ); virtual void _copyRenderTargetToCubemap( uint32 cubemapArrayIdx ); @@ -169,20 +174,20 @@ namespace Ogre /// This function also uses a memory-friendly way of updating the probes. void updateAllDirtyProbes(); - //CompositorWorkspaceListener overloads + // CompositorWorkspaceListener overloads virtual void allWorkspacesBeforeBeginUpdate(); virtual void allWorkspacesBeginUpdate(); virtual void passPreExecute( CompositorPass *pass ); - //FrameListener overloads - virtual bool frameStarted( const FrameEvent& evt ); + // FrameListener overloads + virtual bool frameStarted( const FrameEvent &evt ); }; /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapBase.h b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapBase.h index 881df57b0f6..a0ebfca96ae 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapBase.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgreParallaxCorrectedCubemapBase.h @@ -29,17 +29,19 @@ THE SOFTWARE. #define _OgreParallaxCorrectedCubemapBase_H_ #include "OgreHlmsPbsPrerequisites.h" -#include "OgreRenderSystem.h" -#include "Cubemaps/OgreCubemapProbe.h" + #include "Compositor/OgreCompositorWorkspaceListener.h" -#include "OgreIdString.h" +#include "Cubemaps/OgreCubemapProbe.h" #include "OgreId.h" +#include "OgreIdString.h" +#include "OgreRenderSystem.h" + #include "OgreHeaderPrefix.h" namespace Ogre { class CompositorWorkspaceDef; - typedef vector::type CubemapProbeVec; + typedef vector::type CubemapProbeVec; /** @see HlmsPbsDatablock::setCubemapProbe @@ -49,40 +51,44 @@ namespace Ogre public CompositorWorkspaceListener { protected: - TextureGpu *mBindTexture; - HlmsSamplerblock const *mSamplerblockTrilinear; + TextureGpu * mBindTexture; + HlmsSamplerblock const *mSamplerblockTrilinear; CubemapProbeVec mProbes; bool mAutomaticMode; bool mUseDpm2DArray; - bool mIsRendering; - public: bool mPaused; - public: uint32 mMask; /// @see CubemapProbe::mMask + bool mIsRendering; + + public: + bool mPaused; + + public: + uint32 mMask; /// @see CubemapProbe::mMask protected: - Root *mRoot; - SceneManager *mSceneManager; - CompositorWorkspaceDef const *mDefaultWorkspaceDef; + Root * mRoot; + SceneManager * mSceneManager; + CompositorWorkspaceDef const *mDefaultWorkspaceDef; - Pass *mPccCompressorPass; - CubemapProbe *mProbeRenderInProgress; + Pass * mPccCompressorPass; + CubemapProbe *mProbeRenderInProgress; public: ParallaxCorrectedCubemapBase( IdType id, Root *root, SceneManager *sceneManager, const CompositorWorkspaceDef *probeWorkspaceDef, - bool automaticMode ); + bool automaticMode ); virtual ~ParallaxCorrectedCubemapBase(); virtual void _releaseManualHardwareResources(); virtual void _restoreManualHardwareResources(); - uint32 getIblTargetTextureFlags( PixelFormatGpu pixelFormat ) const; + uint32 getIblTargetTextureFlags( PixelFormatGpu pixelFormat ) const; static uint8 getIblNumMipmaps( uint32 width, uint32 height ); /// Adds a cubemap probe. - CubemapProbe* createProbe(); - virtual void destroyProbe( CubemapProbe *probe ); - virtual void destroyAllProbes(); + CubemapProbe *createProbe(); + virtual void destroyProbe( CubemapProbe *probe ); + virtual void destroyAllProbes(); /// Destroys the Proxy Items. Useful if you need to call sceneManager->clearScene(); /// The you MUST call this function before. i.e. @@ -94,13 +100,13 @@ namespace Ogre virtual void prepareForClearScene(); virtual void restoreFromClearScene(); - const CubemapProbeVec& getProbes() const { return mProbes; } + const CubemapProbeVec &getProbes() const { return mProbes; } - bool getAutomaticMode() const { return mAutomaticMode; } - bool getUseDpm2DArray() const { return mUseDpm2DArray; } + bool getAutomaticMode() const { return mAutomaticMode; } + bool getUseDpm2DArray() const { return mUseDpm2DArray; } - TextureGpu* getBindTexture() const { return mBindTexture; } - const HlmsSamplerblock* getBindTrilinearSamplerblock() { return mSamplerblockTrilinear; } + TextureGpu * getBindTexture() const { return mBindTexture; } + const HlmsSamplerblock *getBindTrilinearSamplerblock() { return mSamplerblockTrilinear; } /// By default the probes will be constructed when the user enters its vecinity. /// This can cause noticeable stalls. Use this function to regenerate them all @@ -108,21 +114,22 @@ namespace Ogre virtual void updateAllDirtyProbes() = 0; virtual void _notifyPreparePassHash( const Matrix4 &viewMatrix ); + virtual size_t getConstBufferSize(); + virtual void fillConstBufferData( const Matrix4 &viewMatrix, - float * RESTRICT_ALIAS passBufferPtr ) const; - static void fillConstBufferData( const CubemapProbe &probe, - const Matrix4 &viewMatrix, - const Matrix3 &invViewMat3, - float * RESTRICT_ALIAS passBufferPtr ); + float *RESTRICT_ALIAS passBufferPtr ) const; + static void fillConstBufferData( const CubemapProbe &probe, const Matrix4 &viewMatrix, + const Matrix3 &invViewMat3, + float *RESTRICT_ALIAS passBufferPtr ); /// See mTmpRtt. Finds an RTT that is compatible to copy to baseParams. /// Creates one if none found. - virtual TextureGpu* findTmpRtt( const TextureGpu *baseParams ); - virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); + virtual TextureGpu *findTmpRtt( const TextureGpu *baseParams ); + virtual void releaseTmpRtt( const TextureGpu *tmpRtt ); - virtual TextureGpu* findIbl( const TextureGpu *baseParams ); - virtual void releaseIbl( const TextureGpu *tmpRtt ); + virtual TextureGpu *findIbl( const TextureGpu *baseParams ); + virtual void releaseIbl( const TextureGpu *tmpRtt ); virtual void _copyRenderTargetToCubemap( uint32 cubemapArrayIdx ); @@ -132,33 +139,34 @@ namespace Ogre @return Texture. Can be nullptr if ran out of slots. */ - virtual TextureGpu* _acquireTextureSlot( uint16 &outTexSlot ); - virtual void _releaseTextureSlot( TextureGpu *texture, uint32 texSlot ); + virtual TextureGpu *_acquireTextureSlot( uint16 &outTexSlot ); + virtual void _releaseTextureSlot( TextureGpu *texture, uint32 texSlot ); virtual void _addManuallyActiveProbe( CubemapProbe *probe ); virtual void _removeManuallyActiveProbe( CubemapProbe *probe ); - void _setIsRendering( bool bIsRendering ) { mIsRendering = bIsRendering; } + void _setIsRendering( bool bIsRendering ) { mIsRendering = bIsRendering; } /// Inform whether we're currently updating a probe. Some Hlms / PCC combinations /// should not perform PCC while rendering, either because the RenderTarget is the same /// as the cubemap texture, or because other glitches may occur - bool isRendering() const { return mIsRendering; } + bool isRendering() const { return mIsRendering; } + + void _setProbeRenderInProgress( CubemapProbe *probe ) { mProbeRenderInProgress = probe; } - void _setProbeRenderInProgress( CubemapProbe *probe ) { mProbeRenderInProgress = probe; } + SceneManager *getSceneManager() const; - SceneManager* getSceneManager() const; - const CompositorWorkspaceDef* getDefaultWorkspaceDef() const; + const CompositorWorkspaceDef *getDefaultWorkspaceDef() const; virtual void passPreExecute( CompositorPass *pass ); - //RenderSystem::Listener overloads - virtual void eventOccurred( const String& eventName, const NameValuePairList* parameters ); + // RenderSystem::Listener overloads + virtual void eventOccurred( const String &eventName, const NameValuePairList *parameters ); }; /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Cubemaps/OgrePccPerPixelGridPlacement.h b/Components/Hlms/Pbs/include/Cubemaps/OgrePccPerPixelGridPlacement.h index 14d3479b402..30485b2a9ce 100644 --- a/Components/Hlms/Pbs/include/Cubemaps/OgrePccPerPixelGridPlacement.h +++ b/Components/Hlms/Pbs/include/Cubemaps/OgrePccPerPixelGridPlacement.h @@ -33,9 +33,8 @@ THE SOFTWARE. #include "Cubemaps/OgreParallaxCorrectedCubemapAuto.h" -#include "OgrePixelFormatGpu.h" - #include "Math/Simple/OgreAabb.h" +#include "OgrePixelFormatGpu.h" namespace Ogre { @@ -68,7 +67,7 @@ namespace Ogre class _OgreHlmsPbsExport PccPerPixelGridPlacement : public ParallaxCorrectedCubemapAutoListener { uint32 mNumProbes[3]; - Aabb mFullRegion; + Aabb mFullRegion; Vector3 mOverlap; Vector3 mSnapDeviationError; @@ -130,7 +129,7 @@ namespace Ogre Thus the total number of probes will be numProbes[0] * numProbes[1] * numProbes[2] @param numProbes */ - void setNumProbes( uint32 numProbes[3] ); + void setNumProbes( uint32 numProbes[3] ); const uint32 *getNumProbes() const { return mNumProbes; } /** PccPerPixelGridPlacement needs, as guidance, the maximum region it will be occupying. @@ -140,7 +139,7 @@ namespace Ogre the visible geometry from the probe's perspective. @param fullRegion */ - void setFullRegion( const Aabb &fullRegion ); + void setFullRegion( const Aabb &fullRegion ); const Aabb &getFullRegion() const { return mFullRegion; } /** PccPerPixelGridPlacement will subdivide in mNumProbes[i] probes along each axis, @@ -161,7 +160,7 @@ namespace Ogre Valid range: (0; inf) Default: 1.5 */ - void setOverlap( const Vector3 &overlap ); + void setOverlap( const Vector3 &overlap ); const Vector3 &getOverlap() const { return mOverlap; } /** When the probes have a different size than what they should have, but they're almost @@ -179,7 +178,7 @@ namespace Ogre Use a very large value to always snap 0 to disable snapping in this axis */ - void setSnapDeviationError( const Vector3 &relativeError ); + void setSnapDeviationError( const Vector3 &relativeError ); const Vector3 &getSnapDeviationError() const { return mSnapDeviationError; } /** Very similar to PccPerPixelGridPlacement::setSnapDeviationError but more specific; thus @@ -252,6 +251,7 @@ namespace Ogre */ void setSnapSides( const Vector3 &snapSidesDeviationErrorMin, const Vector3 &snapSidesDeviationErrorMax ); + const Vector3 &getSnapSidesDeviationErrorMin() const; const Vector3 &getSnapSidesDeviationErrorMax() const; diff --git a/Components/Hlms/Pbs/include/InstantRadiosity/OgreInstantRadiosity.h b/Components/Hlms/Pbs/include/InstantRadiosity/OgreInstantRadiosity.h index c9d1a018c3d..c55dc865000 100644 --- a/Components/Hlms/Pbs/include/InstantRadiosity/OgreInstantRadiosity.h +++ b/Components/Hlms/Pbs/include/InstantRadiosity/OgreInstantRadiosity.h @@ -29,23 +29,25 @@ THE SOFTWARE. #define _OgreInstantRadiosity_H_ #include "OgreHlmsPbsPrerequisites.h" -#include "OgreHlmsBufferManager.h" + +#include "Math/Array/OgreArrayRay.h" #include "OgreConstBufferPool.h" -#include "OgreRay.h" +#include "OgreHlmsBufferManager.h" #include "OgreRawPtr.h" -#include "OgreVector2.h" -#include "Math/Array/OgreArrayRay.h" +#include "OgreRay.h" #include "OgreTextureBox.h" +#include "OgreVector2.h" + #include "OgreHeaderPrefix.h" namespace Ogre { /** \addtogroup Component - * @{ - */ + * @{ + */ /** \addtogroup Material - * @{ - */ + * @{ + */ class RandomNumberGenerator; class IrradianceVolume; @@ -54,49 +56,50 @@ namespace Ogre { struct MeshData { - float * RESTRICT_ALIAS vertexData; + float *RESTRICT_ALIAS vertexData; /// Index data may be directly pointing to IndexBufferPacked's shadow copy. /// Don't free the memory in that case! union { - uint8 * RESTRICT_ALIAS indexData; - uint8 const * RESTRICT_ALIAS indexDataConst; + uint8 *RESTRICT_ALIAS indexData; + uint8 const *RESTRICT_ALIAS indexDataConst; }; - size_t numVertices; - size_t numIndices; - bool useIndices16bit; + size_t numVertices; + size_t numIndices; + bool useIndices16bit; - float* getUvStart( uint8_t uvSet ) const; + float *getUvStart( uint8_t uvSet ) const; }; struct MaterialData { - Vector3 diffuse; - bool needsUv; - //TODO: missing translate & scale - Image2 const*image[5]; //1 for diffuse, 4 for the detail maps. - TextureBox box[5]; - uint8 uvSet[5]; + Vector3 diffuse; + bool needsUv; + // TODO: missing translate & scale + Image2 const *image[5]; // 1 for diffuse, 4 for the detail maps. + TextureBox box[5]; + uint8 uvSet[5]; }; struct RayHit { - Real distance; - Real accumDistance; - Ray ray; - //Vector3 pointOnTri; + Real distance; + Real accumDistance; + Ray ray; + // Vector3 pointOnTri; MaterialData material; + Vector3 triVerts[3]; Vector3 triNormal; - Vector2 triUVs[5][3]; //Up to 5 UVs (one per material image) + Vector2 triUVs[5][3]; // Up to 5 UVs (one per material image) }; struct Vpl { - Light *light; + Light * light; Vector3 diffuse; Vector3 position; Vector3 normal; - Vector3 dirDiffuse[6]; /// Directional diffuse + Vector3 dirDiffuse[6]; /// Directional diffuse Real numMergedVpls; }; @@ -108,56 +111,56 @@ namespace Ogre Vector3 dirDiffuse[6]; SparseCluster(); - SparseCluster( int32 blockX, int32 blockY, int32 blockZ, - const Vector3 &_diffuse, const Vector3 &dir, - const Vector3 _dirDiffuse[6] ); + SparseCluster( int32 blockX, int32 blockY, int32 blockZ, const Vector3 &_diffuse, + const Vector3 &dir, const Vector3 _dirDiffuse[6] ); SparseCluster( int32 _blockHash[3] ); - bool operator () ( const SparseCluster &_l, int32 _r[3] ) const; - bool operator () ( int32 _l[3], const SparseCluster &_r ) const; - bool operator () ( const SparseCluster &_l, const SparseCluster &_r ) const; + bool operator()( const SparseCluster &_l, int32 _r[3] ) const; + bool operator()( int32 _l[3], const SparseCluster &_r ) const; + bool operator()( const SparseCluster &_l, const SparseCluster &_r ) const; }; - typedef vector::type RayHitVec; - typedef vector::type VplVec; + typedef vector::type RayHitVec; + typedef vector::type VplVec; typedef set::type SparseClusterSet; struct OrderRenderOperation { - bool operator () ( const v1::RenderOperation &_l, const v1::RenderOperation &_r ) const; + bool operator()( const v1::RenderOperation &_l, const v1::RenderOperation &_r ) const; }; - SceneManager *mSceneManager; - HlmsManager *mHlmsManager; + SceneManager *mSceneManager; + HlmsManager * mHlmsManager; + public: - uint8 mFirstRq; - uint8 mLastRq; - uint32 mVisibilityMask; - uint32 mLightMask; + uint8 mFirstRq; + uint8 mLastRq; + uint32 mVisibilityMask; + uint32 mLightMask; /// Number of rays to trace. More usually results in more accuracy. Sometimes really /// low values (e.g. 32 rays) may achieve convincing results with high performance, while /// high large values (e.g. 10000) achieve more accurate results. - size_t mNumRays; + size_t mNumRays; /// In range [0; inf). Controls how many bounces we'll generate. /// Increases the total number of rays (i.e. more than mNumRays). - size_t mNumRayBounces; + size_t mNumRayBounces; /// In range (0; 1]; how many rays that fired in the previous bounce should survive /// for a next round of bounces. - Real mSurvivingRayFraction; + Real mSurvivingRayFraction; /// Controls how we cluster multiple VPLs into one averaged VPL. Smaller values generate /// more VPLs (reducing performance but improving quality). Bigger values result in less /// VPLs (higher performance, less quality) - Real mCellSize; + Real mCellSize; /// Value ideally in range (0; 1] /// When 1, the VPL is placed at exactly the location where the light ray hits the triangle. /// At 0.99 it will be placed at 99% the distance from light to the location (i.e. moves away /// from the triangle). Using Bias can help with light bleeding, and also allows reducing /// mVplMaxRange (thus increasing performance) at the cost of lower accuracy but still /// "looking good". - Real mBias; - uint32 mNumSpreadIterations; - Real mSpreadThreshold; + Real mBias; + uint32 mNumSpreadIterations; + Real mSpreadThreshold; /// Areas of Interest are defined by both AABB and distance (can be 0). AoIs serve two purposes: /// 1. Define where to shoot the rays (i.e. windows, holes, etc) @@ -181,10 +184,13 @@ namespace Ogre /// entire house) struct AreaOfInterest { - Aabb aabb; - Real sphereRadius; + Aabb aabb; + Real sphereRadius; AreaOfInterest( const Aabb &_aabb, Real _sphereRadius ) : - aabb( _aabb ), sphereRadius( _sphereRadius ) {} + aabb( _aabb ), + sphereRadius( _sphereRadius ) + { + } }; /// Areas of interest. Only used for directional lights. Normally you don't want to @@ -194,54 +200,56 @@ namespace Ogre /// If left unfilled, the system will auto-calculate one (not recommended). /// See AreaOfInterest typedef vector::type AreaOfInterestVec; - AreaOfInterestVec mAoI; + AreaOfInterestVec mAoI; /// ANY CHANGE TO A mVpl* variable will take effect after calling updateExistingVpls /// (or calling build) /// How big each VPL should be. Larger ranges leak light more but also are more accurate /// in the sections they lit correctly, but they are also get more expensive. - Real mVplMaxRange; - Real mVplConstAtten; - Real mVplLinearAtten; - Real mVplQuadAtten; + Real mVplMaxRange; + Real mVplConstAtten; + Real mVplLinearAtten; + Real mVplQuadAtten; /// If all three components of the diffuse colour of a VPL light is below this threshold, /// the VPL is removed (useful for improving performance for VPLs that barely contribute /// to the scene). - Real mVplThreshold; + Real mVplThreshold; /// Tweaks how strong VPL lights should be. /// In range (0; inf) - Real mVplPowerBoost; + Real mVplPowerBoost; /// When true, mVplIntensityRangeMultiplier will be used and each VPL will have /// a dynamic max range (can't exceed mVplMaxRange though), based on its /// intensity (smaller VPLs = shorter ranges, powerful VPLs = larger ranges) - bool mVplUseIntensityForMaxRange; - double mVplIntensityRangeMultiplier; + bool mVplUseIntensityForMaxRange; + double mVplIntensityRangeMultiplier; + + uint32 mMipmapBias; - uint32 mMipmapBias; private: - size_t mTotalNumRays; /// Includes bounces. Autogenerated. - VplVec mVpls; - RayHitVec mRayHits; + size_t mTotalNumRays; /// Includes bounces. Autogenerated. + VplVec mVpls; + RayHitVec mRayHits; RawSimdUniquePtr mArrayRays; FastArray mTmpRaysThatHitObject[ARRAY_PACKED_REALS]; SparseClusterSet mTmpSparseClusters[3]; - typedef map::type MeshDataMapV2; + typedef map::type MeshDataMapV2; typedef map::type MeshDataMapV1; - MeshDataMapV2 mMeshDataMapV2; - MeshDataMapV1 mMeshDataMapV1; - typedef map::type ImageMap; - ImageMap mImageMap; + MeshDataMapV2 mMeshDataMapV2; + MeshDataMapV1 mMeshDataMapV1; + + typedef map::type ImageMap; + ImageMap mImageMap; - vector::type mDebugMarkers; - bool mEnableDebugMarkers; + vector::type mDebugMarkers; + bool mEnableDebugMarkers; - bool mUseTextures; + bool mUseTextures; - bool mUseIrradianceVolume; + bool mUseIrradianceVolume; /** @param lightPos @@ -256,35 +264,33 @@ namespace Ogre @param areaOfInterest Only used for directional light types. See mAoI */ - void processLight( Vector3 lightPos, const Quaternion &lightRot, uint8 lightType, - Radian angle, Vector3 lightColour, Real lightRange, - Real attenConst, Real attenLinear, Real attenQuad, - const AreaOfInterest &areaOfInterest ); + void processLight( Vector3 lightPos, const Quaternion &lightRot, uint8 lightType, Radian angle, + Vector3 lightColour, Real lightRange, Real attenConst, Real attenLinear, + Real attenQuad, const AreaOfInterest &areaOfInterest ); /// Generates the ray bounces based on mRayHits[raySrcStart] through /// mRayHits[raySrcStart+raySrcCount-1]; generating up to 'raysToGenerate' rays /// Returns the number of actually generated rays (which is <= raysToGenerate) /// The generated rays are stored between mRayHits[raySrcStart+raySrcCount] & /// mRayHits[raySrcStart+raySrcCount+returnValue] - size_t generateRayBounces( size_t raySrcStart, size_t raySrcCount, - size_t raysToGenerate, RandomNumberGenerator &rng); + size_t generateRayBounces( size_t raySrcStart, size_t raySrcCount, size_t raysToGenerate, + RandomNumberGenerator &rng ); - const MeshData* downloadVao( VertexArrayObject *vao ); - const MeshData* downloadRenderOp( const v1::RenderOperation &renderOp ); - const Image2& downloadTexture( TextureGpu *texture ); + const MeshData *downloadVao( VertexArrayObject *vao ); + const MeshData *downloadRenderOp( const v1::RenderOperation &renderOp ); + const Image2 & downloadTexture( TextureGpu *texture ); - void testLightVsAllObjects( uint8 lightType, Real lightRange, - ObjectData objData, size_t numNodes, - const AreaOfInterest &areaOfInterest, + void testLightVsAllObjects( uint8 lightType, Real lightRange, ObjectData objData, + size_t numNodes, const AreaOfInterest &areaOfInterest, size_t rayStart, size_t numRays ); - void raycastLightRayVsMesh( Real lightRange, const MeshData meshData, - Matrix4 worldMatrix, const MaterialData &material, + void raycastLightRayVsMesh( Real lightRange, const MeshData meshData, Matrix4 worldMatrix, + const MaterialData & material, const FastArray &raysThatHitObj ); Vpl convertToVpl( Vector3 lightColour, Vector3 pointOnTri, const RayHit &hit ); /// Generates the VPLs from a particular lights, and clusters them. - void generateAndClusterVpls( Vector3 lightColour, Real attenConst, - Real attenLinear, Real attenQuad ); + void generateAndClusterVpls( Vector3 lightColour, Real attenConst, Real attenLinear, + Real attenQuad ); void spreadSparseClusters( const SparseClusterSet &grid0, SparseClusterSet &inOutGrid1 ); void createVplsFromSpreadClusters( const SparseClusterSet &spreadCluster ); /// Clusters the VPL from all lights (these VPLs may have been clustered with other @@ -321,7 +327,7 @@ namespace Ogre void freeMemory(); void setEnableDebugMarkers( bool bEnable ); - bool getEnableDebugMarkers() const { return mEnableDebugMarkers; } + bool getEnableDebugMarkers() const { return mEnableDebugMarkers; } /** Whether to evaluate diffuse & detail map textures. Disabling textures can speed up build() time and significantly reduce @@ -333,14 +339,14 @@ namespace Ogre Whether to enable or disable using diffuse textures (and detail maps). */ void setUseTextures( bool bUseTextures ); - bool getUseTextures() const { return mUseTextures; } + bool getUseTextures() const { return mUseTextures; } /** Whether to use Irradiance Volume instead of VPLs. @param bUseIrradianceVolume Whether to use Irradiance Volume. */ - void setUseIrradianceVolume(bool bUseIrradianceVolume); - bool getUseIrradianceVolume() const { return mUseIrradianceVolume; } + void setUseIrradianceVolume( bool bUseIrradianceVolume ); + bool getUseIrradianceVolume() const { return mUseIrradianceVolume; } /** Outputs suggested parameters for a volumetric texture that will encompass all VPLs. They are suggestions, you don't have to follow them. @@ -367,12 +373,9 @@ namespace Ogre The suggested depth for the volume texture times. Volume's depth in units will be: outVolumeOrigin.z + mCellSize * outNumBlocksZ; */ - void suggestIrradianceVolumeParameters( const Vector3 &inCellSize, - Vector3 &outVolumeOrigin, - Real &outLightMaxPower, - uint32 &outNumBlocksX, - uint32 &outNumBlocksY, - uint32 &outNumBlocksZ ); + void suggestIrradianceVolumeParameters( const Vector3 &inCellSize, Vector3 &outVolumeOrigin, + Real &outLightMaxPower, uint32 &outNumBlocksX, + uint32 &outNumBlocksY, uint32 &outNumBlocksZ ); /** @param volume @@ -383,15 +386,14 @@ namespace Ogre Whether to fade the attenuation with distance (not physically based). See ForwardPlusBase::setFadeAttenuationRange */ - void fillIrradianceVolume( IrradianceVolume *volume, - Vector3 cellSize, Vector3 volumeOrigin, Real lightMaxPower, - bool fadeAttenuationOverDistance ); + void fillIrradianceVolume( IrradianceVolume *volume, Vector3 cellSize, Vector3 volumeOrigin, + Real lightMaxPower, bool fadeAttenuationOverDistance ); }; /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/IrradianceField/OgreIfdProbeVisualizer.h b/Components/Hlms/Pbs/include/IrradianceField/OgreIfdProbeVisualizer.h index 8ccfe9917d4..1d53bb29f5a 100644 --- a/Components/Hlms/Pbs/include/IrradianceField/OgreIfdProbeVisualizer.h +++ b/Components/Hlms/Pbs/include/IrradianceField/OgreIfdProbeVisualizer.h @@ -51,9 +51,9 @@ namespace Ogre // Overrides from Renderable virtual const LightList &getLights() const; - virtual void getRenderOperation( v1::RenderOperation &op, bool casterPass ); - virtual void getWorldTransforms( Matrix4 *xform ) const; - virtual bool getCastsShadows() const; + virtual void getRenderOperation( v1::RenderOperation &op, bool casterPass ); + virtual void getWorldTransforms( Matrix4 *xform ) const; + virtual bool getCastsShadows() const; }; } // namespace Ogre diff --git a/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceField.h b/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceField.h index 29be482fd73..690dc227166 100644 --- a/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceField.h +++ b/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceField.h @@ -31,9 +31,8 @@ THE SOFTWARE. #include "OgreHlmsPbsPrerequisites.h" -#include "OgreId.h" - #include "Math/Simple/OgreAabb.h" +#include "OgreId.h" #include "OgreIdString.h" #include "OgrePixelFormatGpu.h" #include "OgreShaderPrimitives.h" @@ -49,10 +48,10 @@ namespace Ogre struct _OgreHlmsPbsExport RasterParams { - IdString mWorkspaceName; + IdString mWorkspaceName; PixelFormatGpu mPixelFormat; - float mCameraNear; - float mCameraFar; + float mCameraNear; + float mCameraFar; RasterParams(); }; @@ -104,6 +103,7 @@ namespace Ogre void createSubsamples(); uint32 getTotalNumProbes() const; + void getDepthProbeFullResolution( uint32 &outWidth, uint32 &outHeight ) const; void getIrradProbeFullResolution( uint32 &outWidth, uint32 &outHeight ) const; @@ -152,15 +152,15 @@ namespace Ogre protected: struct IrradianceFieldGenParams { - float invNumRaysPerPixel; - float invNumRaysPerIrradiancePixel; - float unused0; + float invNumRaysPerPixel; + float invNumRaysPerIrradiancePixel; + float unused0; uint32 probesPerRow; // Used by integration CS - float coneAngleTan; + float coneAngleTan; uint32 numProcessedProbes; - float vctStartBias; - float vctInvStartBias; + float vctStartBias; + float vctInvStartBias; // float invFieldResolution; uint4 numProbes_threadsPerRow; @@ -197,37 +197,37 @@ namespace Ogre TextureGpu *mDepthVarianceTex; CompositorWorkspace *mGenerationWorkspace; - HlmsComputeJob *mGenerationJob; - HlmsComputeJob *mDepthIntegrationJob; - HlmsComputeJob *mColourIntegrationJob; - HlmsComputeJob *mDepthMirrorBorderJob; - HlmsComputeJob *mColourMirrorBorderJob; + HlmsComputeJob * mGenerationJob; + HlmsComputeJob * mDepthIntegrationJob; + HlmsComputeJob * mColourIntegrationJob; + HlmsComputeJob * mDepthMirrorBorderJob; + HlmsComputeJob * mColourMirrorBorderJob; IrradianceFieldGenParams mIfGenParams; - ConstBufferPacked *mIfGenParamsBuffer; - TexBufferPacked *mDirectionsBuffer; - TexBufferPacked *mDepthTapsIntegrationBuffer; - TexBufferPacked *mColourTapsIntegrationBuffer; - ConstBufferPacked *mIfdDepthBorderMirrorParamsBuffer; - ConstBufferPacked *mIfdColourBorderMirrorParamsBuffer; + ConstBufferPacked * mIfGenParamsBuffer; + TexBufferPacked * mDirectionsBuffer; + TexBufferPacked * mDepthTapsIntegrationBuffer; + TexBufferPacked * mColourTapsIntegrationBuffer; + ConstBufferPacked * mIfdDepthBorderMirrorParamsBuffer; + ConstBufferPacked * mIfdColourBorderMirrorParamsBuffer; IrradianceFieldRaster *mIfRaster; DebugVisualizationMode mDebugVisualizationMode; - uint8 mDebugTessellation; - IfdProbeVisualizer *mDebugIfdProbeVisualizer; + uint8 mDebugTessellation; + IfdProbeVisualizer * mDebugIfdProbeVisualizer; - Root *mRoot; + Root * mRoot; SceneManager *mSceneManager; - bool mAlreadyWarned; + bool mAlreadyWarned; void fillDirections( float *RESTRICT_ALIAS outBuffer ); static TexBufferPacked *setupIntegrationTaps( VaoManager *vaoManager, uint32 probeRes, uint32 fullWidth, HlmsComputeJob *integrationJob, ConstBufferPacked *ifGenParamsBuffer, - uint32 &outMaxIntegrationTapsPerPixel ); - static uint32 countNumIntegrationTaps( uint32 probeRes ); + uint32 & outMaxIntegrationTapsPerPixel ); + static uint32 countNumIntegrationTaps( uint32 probeRes ); /** * @brief fillIntegrationWeights @@ -236,11 +236,11 @@ namespace Ogre */ static void fillIntegrationWeights( float2 *RESTRICT_ALIAS outBuffer, uint32 probeRes, uint32 maxTapsPerPixel ); - void setIrradianceFieldGenParams(); + void setIrradianceFieldGenParams(); void setupBorderMirrorParams( uint32 borderedRes, uint32 fullWidth, ConstBufferPacked *ifdBorderMirrorParamsBuffer, - HlmsComputeJob *job ); + HlmsComputeJob * job ); void setTextureToDebugVisualizer(); @@ -291,9 +291,9 @@ namespace Ogre tessellation = 9u -> 130560 vertices tessellation = 16u -> 2.147.418.112 vertices */ - void setDebugVisualization( IrradianceField::DebugVisualizationMode mode, - SceneManager *sceneManager, uint8 tessellation ); - bool getDebugVisualizationMode() const; + void setDebugVisualization( IrradianceField::DebugVisualizationMode mode, + SceneManager *sceneManager, uint8 tessellation ); + bool getDebugVisualizationMode() const; uint8 getDebugTessellation() const; TextureGpu *getIrradianceTex() const { return mIrradianceTex; } diff --git a/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceFieldRaster.h b/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceFieldRaster.h index cbdd58160cb..acdfbd7f902 100644 --- a/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceFieldRaster.h +++ b/Components/Hlms/Pbs/include/IrradianceField/OgreIrradianceFieldRaster.h @@ -69,14 +69,14 @@ namespace Ogre { IrradianceField *mCreator; - TextureGpu *mCubemap; - TextureGpu *mDepthCubemap; + TextureGpu * mCubemap; + TextureGpu * mDepthCubemap; CompositorWorkspace *mRenderWorkspace; CompositorWorkspace *mConvertToIfdWorkspace; CompositorWorkspace *mIfdIntegrationWorkspace; - HlmsComputeJob *mConvertToIfdJob; - ShaderParams *mShaderParamsConvertToIfd; + HlmsComputeJob * mConvertToIfdJob; + ShaderParams * mShaderParamsConvertToIfd; ShaderParams::Param *mProbeIdxParam; ShaderParams::Param *mProjectionABParam; ShaderParams::Param *mNumProbesParam; diff --git a/Components/Hlms/Pbs/include/LightProfiles/OgreIesLoader.h b/Components/Hlms/Pbs/include/LightProfiles/OgreIesLoader.h index 33cb4d6a841..b8733d1aacd 100644 --- a/Components/Hlms/Pbs/include/LightProfiles/OgreIesLoader.h +++ b/Components/Hlms/Pbs/include/LightProfiles/OgreIesLoader.h @@ -67,7 +67,7 @@ namespace Ogre float mBallastFactor; float mBallastLampPhotometricFactor; - LampConeType::LampConeType mLampConeType; + LampConeType::LampConeType mLampConeType; LampHorizType::LampHorizType mLampHorizType; FastArray mAngleData; diff --git a/Components/Hlms/Pbs/include/LightProfiles/OgreLightProfiles.h b/Components/Hlms/Pbs/include/LightProfiles/OgreLightProfiles.h index f5a80468b23..8beb6ec92d8 100644 --- a/Components/Hlms/Pbs/include/LightProfiles/OgreLightProfiles.h +++ b/Components/Hlms/Pbs/include/LightProfiles/OgreLightProfiles.h @@ -45,11 +45,11 @@ namespace Ogre */ class _OgreHlmsPbsExport LightProfiles : public UtilityAlloc { - FastArray mIesData; + FastArray mIesData; map::type mIesNameMap; - TextureGpu *mLightProfilesTexture; + TextureGpu * mLightProfilesTexture; - HlmsPbs *mHlmsPbs; + HlmsPbs * mHlmsPbs; TextureGpuManager *mTextureGpuManager; void destroyTexture(); diff --git a/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h b/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h index a90374c0052..12f61e55a25 100644 --- a/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h +++ b/Components/Hlms/Pbs/include/OgreHlmsJsonPbs.h @@ -27,43 +27,44 @@ THE SOFTWARE. */ #if !OGRE_NO_JSON -#ifndef _OgreHlmsJsonPbs_H_ -#define _OgreHlmsJsonPbs_H_ +# ifndef _OgreHlmsJsonPbs_H_ +# define _OgreHlmsJsonPbs_H_ -#include "OgreHlmsPbsPrerequisites.h" -#include "OgreHlmsJson.h" -#include "OgreHlmsPbsDatablock.h" -#include "OgreHeaderPrefix.h" +# include "OgreHlmsPbsPrerequisites.h" + +# include "OgreHlmsJson.h" +# include "OgreHlmsPbsDatablock.h" + +# include "OgreHeaderPrefix.h" namespace Ogre { /** \addtogroup Component - * @{ - */ + * @{ + */ /** \addtogroup Material - * @{ - */ + * @{ + */ class _OgreHlmsPbsExport HlmsJsonPbs { - HlmsManager *mHlmsManager; - TextureGpuManager *mTextureManager; - HlmsJsonListener *mListener; - String mAdditionalExtension; + HlmsManager * mHlmsManager; + TextureGpuManager *mTextureManager; + HlmsJsonListener * mListener; + String mAdditionalExtension; - static HlmsPbsDatablock::Workflows parseWorkflow( const char *value ); - static PbsBrdf::PbsBrdf parseBrdf( const char *value ); + static HlmsPbsDatablock::Workflows parseWorkflow( const char *value ); + static PbsBrdf::PbsBrdf parseBrdf( const char *value ); static HlmsPbsDatablock::TransparencyModes parseTransparencyMode( const char *value ); - static PbsBlendModes parseBlendMode( const char *value ); + static PbsBlendModes parseBlendMode( const char *value ); static void parseFresnelMode( const char *value, bool &outIsColoured, bool &outUseIOR ); static void parseOffset( const rapidjson::Value &jsonArray, Vector4 &offsetScale ); static void parseScale( const rapidjson::Value &jsonArray, Vector4 &offsetScale ); - static inline Vector3 parseVector3Array( const rapidjson::Value &jsonArray ); - static inline Vector4 parseVector4Array( const rapidjson::Value &jsonArray ); + static inline Vector3 parseVector3Array( const rapidjson::Value &jsonArray ); + static inline Vector4 parseVector4Array( const rapidjson::Value &jsonArray ); static inline ColourValue parseColourValueArray( - const rapidjson::Value &jsonArray, - const ColourValue &defaultValue = ColourValue::White ); + const rapidjson::Value &jsonArray, const ColourValue &defaultValue = ColourValue::White ); void loadTexture( const rapidjson::Value &json, const HlmsJson::NamedBlocks &blocks, PbsTextureTypes textureType, HlmsPbsDatablock *datablock, @@ -74,23 +75,19 @@ namespace Ogre static void toQuotedStr( HlmsPbsDatablock::TransparencyModes value, String &outString ); void saveFresnel( const HlmsPbsDatablock *datablock, String &outString ); - void saveTexture( const char *blockName, - PbsTextureTypes textureType, + void saveTexture( const char *blockName, PbsTextureTypes textureType, const HlmsPbsDatablock *datablock, String &outString, - bool writeTexture=true ); - void saveTexture( float value, const char *blockName, - PbsTextureTypes textureType, + bool writeTexture = true ); + void saveTexture( float value, const char *blockName, PbsTextureTypes textureType, const HlmsPbsDatablock *datablock, String &outString, - bool writeTexture=true ); - void saveTexture( const Vector3 &value, const char *blockName, - PbsTextureTypes textureType, - const HlmsPbsDatablock *datablock, String &outString, - bool writeTexture=true, const ColourValue &bgColour=ColourValue::ZERO ); + bool writeTexture = true ); + void saveTexture( const Vector3 &value, const char *blockName, PbsTextureTypes textureType, + const HlmsPbsDatablock *datablock, String &outString, bool writeTexture = true, + const ColourValue &bgColour = ColourValue::ZERO ); void saveTexture( const Vector3 &value, const ColourValue &bgDiffuse, const char *blockName, - PbsTextureTypes textureType, - bool writeValue, bool writeBgDiffuse, bool scalarValue, - bool isFresnel, bool writeTexture, + PbsTextureTypes textureType, bool writeValue, bool writeBgDiffuse, + bool scalarValue, bool isFresnel, bool writeTexture, const HlmsPbsDatablock *datablock, String &outString ); public: @@ -101,17 +98,17 @@ namespace Ogre HlmsDatablock *datablock, const String &resourceGroup ); void saveMaterial( const HlmsDatablock *datablock, String &outString ); - static void collectSamplerblocks( const HlmsDatablock *datablock, - set::type &outSamplerblocks ); + static void collectSamplerblocks( const HlmsDatablock * datablock, + set::type &outSamplerblocks ); }; /** @} */ /** @} */ -} +} // namespace Ogre -#include "OgreHeaderSuffix.h" +# include "OgreHeaderSuffix.h" -#endif +# endif #endif diff --git a/Components/Hlms/Pbs/include/OgreHlmsPbs.h b/Components/Hlms/Pbs/include/OgreHlmsPbs.h index ea61c48eeb4..40fc5cc9305 100644 --- a/Components/Hlms/Pbs/include/OgreHlmsPbs.h +++ b/Components/Hlms/Pbs/include/OgreHlmsPbs.h @@ -29,12 +29,14 @@ THE SOFTWARE. #define _OgreHlmsPbs_H_ #include "OgreHlmsPbsPrerequisites.h" -#include "OgreHlmsBufferManager.h" + #include "OgreConstBufferPool.h" +#include "OgreHlmsBufferManager.h" #include "OgreMatrix4.h" -#include "OgreHeaderPrefix.h" #include "OgreRoot.h" +#include "OgreHeaderPrefix.h" + namespace Ogre { class CompositorShadowNode; @@ -44,11 +46,11 @@ namespace Ogre #endif /** \addtogroup Component - * @{ - */ + * @{ + */ /** \addtogroup Material - * @{ - */ + * @{ + */ class HlmsPbsDatablock; @@ -110,86 +112,85 @@ namespace Ogre }; protected: - typedef vector::type ConstBufferPackedVec; - typedef vector::type HlmsDatablockVec; + typedef vector::type ConstBufferPackedVec; + typedef vector::type HlmsDatablockVec; struct PassData { - FastArray shadowMaps; - FastArray vertexShaderSharedBuffer; - FastArray pixelShaderSharedBuffer; + FastArray shadowMaps; + FastArray vertexShaderSharedBuffer; + FastArray pixelShaderSharedBuffer; Matrix4 viewMatrix; }; PassData mPreparedPass; ConstBufferPackedVec mPassBuffers; - ConstBufferPackedVec mLight0Buffers; // lights - ConstBufferPackedVec mLight1Buffers; // areaApproxLights - ConstBufferPackedVec mLight2Buffers; // areaLtcLights - HlmsSamplerblock const *mShadowmapSamplerblock; /// GL3+ only when not using depth textures - HlmsSamplerblock const *mShadowmapCmpSamplerblock; /// For depth textures & D3D11 - HlmsSamplerblock const *mShadowmapEsmSamplerblock; /// For ESM. - HlmsSamplerblock const *mCurrentShadowmapSamplerblock; + ConstBufferPackedVec mLight0Buffers; // lights + ConstBufferPackedVec mLight1Buffers; // areaApproxLights + ConstBufferPackedVec mLight2Buffers; // areaLtcLights + HlmsSamplerblock const *mShadowmapSamplerblock; /// GL3+ only when not using depth textures + HlmsSamplerblock const *mShadowmapCmpSamplerblock; /// For depth textures & D3D11 + HlmsSamplerblock const *mShadowmapEsmSamplerblock; /// For ESM. + HlmsSamplerblock const *mCurrentShadowmapSamplerblock; ParallaxCorrectedCubemapBase *mParallaxCorrectedCubemap; - float mPccVctMinDistance; - float mInvPccVctInvDistance; + float mPccVctMinDistance; + float mInvPccVctInvDistance; - uint32 mCurrentPassBuffer; /// Resets to zero every new frame. + uint32 mCurrentPassBuffer; /// Resets to zero every new frame. - TexBufferPacked *mGridBuffer; - ReadOnlyBufferPacked *mGlobalLightListBuffer; + TexBufferPacked * mGridBuffer; + ReadOnlyBufferPacked *mGlobalLightListBuffer; + float mMaxSpecIblMipmap; + uint16 mTexBufUnitSlotEnd; + uint32 mTexUnitSlotStart; - float mMaxSpecIblMipmap; - uint16 mTexBufUnitSlotEnd; - uint32 mTexUnitSlotStart; - - TextureGpuVec const *mPrePassTextures; - TextureGpu *mPrePassMsaaDepthTexture; + TextureGpuVec const *mPrePassTextures; + TextureGpu * mPrePassMsaaDepthTexture; /// Used by techniques: SS Reflections, SS Refractions - TextureGpu *mDepthTexture; - TextureGpu *mSsrTexture; - TextureGpu *mDepthTextureNoMsaa; - TextureGpu *mRefractionsTexture; - IrradianceVolume *mIrradianceVolume; - VctLighting *mVctLighting; - IrradianceField *mIrradianceField; + TextureGpu * mDepthTexture; + TextureGpu * mSsrTexture; + TextureGpu * mDepthTextureNoMsaa; + TextureGpu * mRefractionsTexture; + IrradianceVolume *mIrradianceVolume; + VctLighting * mVctLighting; + IrradianceField * mIrradianceField; #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS - //TODO: After texture refactor it should be possible to abstract this, - //so we don't have to be aware of PlanarReflections class. - PlanarReflections *mPlanarReflections; - HlmsSamplerblock const *mPlanarReflectionsSamplerblock; + // TODO: After texture refactor it should be possible to abstract this, + // so we don't have to be aware of PlanarReflections class. + PlanarReflections * mPlanarReflections; + HlmsSamplerblock const *mPlanarReflectionsSamplerblock; /// Whether the current active pass can use mPlanarReflections (i.e. we can't /// use the reflections if they were built for a different camera angle) - bool mHasPlanarReflections; - uint8 mLastBoundPlanarReflection; + bool mHasPlanarReflections; + uint8 mLastBoundPlanarReflection; #endif - TextureGpu *mAreaLightMasks; - HlmsSamplerblock const *mAreaLightMasksSamplerblock; - LightArray mAreaLights; + TextureGpu * mAreaLightMasks; + HlmsSamplerblock const *mAreaLightMasksSamplerblock; + LightArray mAreaLights; bool mUsingAreaLightMasks; - TextureGpu *mLightProfilesTexture; + TextureGpu *mLightProfilesTexture; - bool mSkipRequestSlotInChangeRS; + bool mSkipRequestSlotInChangeRS; /// LTC matrix texture also contains BRDF LUT for specular IBL. - TextureGpu *mLtcMatrixTexture; + TextureGpu *mLtcMatrixTexture; bool mDecalsDiffuseMergedEmissive; - TextureGpu *mDecalsTextures[3]; - HlmsSamplerblock const *mDecalsSamplerblock; + TextureGpu * mDecalsTextures[3]; + HlmsSamplerblock const *mDecalsSamplerblock; ConstBufferPool::BufferPool const *mLastBoundPool; float mConstantBiasScale; - bool mHasSeparateSamplers; + bool mHasSeparateSamplers; DescriptorSetTexture const *mLastDescTexture; DescriptorSetSampler const *mLastDescSampler; - uint8 mReservedTexBufferSlots; // Includes ReadOnly - uint8 mReservedTexSlots; // These get added to mReservedTexBufferSlots + uint8 mReservedTexBufferSlots; // Includes ReadOnly + uint8 mReservedTexSlots; // These get added to mReservedTexBufferSlots #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY bool mFineLightMaskGranularity; #endif @@ -208,21 +209,20 @@ namespace Ogre bool mUseLightBuffers; - ShadowFilter mShadowFilter; - uint16 mEsmK; /// K parameter for ESM. + ShadowFilter mShadowFilter; + uint16 mEsmK; /// K parameter for ESM. AmbientLightMode mAmbientLightMode; virtual void setupRootLayout( RootLayout &rootLayout ); - virtual const HlmsCache* createShaderCacheEntry( uint32 renderableHash, - const HlmsCache &passCache, - uint32 finalHash, + virtual const HlmsCache *createShaderCacheEntry( uint32 renderableHash, + const HlmsCache &passCache, uint32 finalHash, const QueuedRenderable &queuedRenderable ); - virtual HlmsDatablock* createDatablockImpl( IdString datablockName, + virtual HlmsDatablock *createDatablockImpl( IdString datablockName, const HlmsMacroblock *macroblock, const HlmsBlendblock *blendblock, - const HlmsParamVec ¶mVec ); + const HlmsParamVec & paramVec ); void setDetailMapProperties( HlmsPbsDatablock *datablock, PiecesMap *inOutPieces, const bool bCasterPass ); @@ -241,10 +241,10 @@ namespace Ogre virtual void destroyAllBuffers(); - FORCEINLINE uint32 fillBuffersFor( const HlmsCache *cache, - const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - CommandBuffer *commandBuffer, bool isV1 ); + FORCEINLINE uint32 fillBuffersFor( const HlmsCache * cache, + const QueuedRenderable &queuedRenderable, bool casterPass, + uint32 lastCacheHash, CommandBuffer *commandBuffer, + bool isV1 ); public: HlmsPbs( Archive *dataFolder, ArchiveVec *libraryFolders ); @@ -252,26 +252,22 @@ namespace Ogre virtual void _changeRenderSystem( RenderSystem *newRs ); - virtual void analyzeBarriers( BarrierSolver &barrierSolver, + virtual void analyzeBarriers( BarrierSolver & barrierSolver, ResourceTransitionArray &resourceTransitions, Camera *renderingCamera, const bool bCasterPass ); - virtual HlmsCache preparePassHash( const Ogre::CompositorShadowNode *shadowNode, - bool casterPass, bool dualParaboloid, - SceneManager *sceneManager ); + virtual HlmsCache preparePassHash( const Ogre::CompositorShadowNode *shadowNode, bool casterPass, + bool dualParaboloid, SceneManager *sceneManager ); virtual uint32 fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - uint32 lastTextureHash ); - - virtual uint32 fillBuffersForV1( const HlmsCache *cache, - const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - CommandBuffer *commandBuffer ); - virtual uint32 fillBuffersForV2( const HlmsCache *cache, - const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - CommandBuffer *commandBuffer ); + bool casterPass, uint32 lastCacheHash, uint32 lastTextureHash ); + + virtual uint32 fillBuffersForV1( const HlmsCache * cache, + const QueuedRenderable &queuedRenderable, bool casterPass, + uint32 lastCacheHash, CommandBuffer *commandBuffer ); + virtual uint32 fillBuffersForV2( const HlmsCache * cache, + const QueuedRenderable &queuedRenderable, bool casterPass, + uint32 lastCacheHash, CommandBuffer *commandBuffer ); virtual void postCommandBufferExecution( CommandBuffer *commandBuffer ); virtual void frameEnded(); @@ -299,9 +295,10 @@ namespace Ogre @param outDataFolderPath Path (as a String) used for creating the "dataFolder" Archive the constructor will need @param outLibraryFoldersPaths - Vector of String used for creating the ArchiveVector "libraryFolders" the constructor will need + Vector of String used for creating the ArchiveVector "libraryFolders" the constructor will + need */ - static void getDefaultPaths( String& outDataFolderPath, StringVector& outLibraryFoldersPaths ); + static void getDefaultPaths( String &outDataFolderPath, StringVector &outLibraryFoldersPaths ); #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY /// Toggles whether light masks will be obeyed per object by doing: @@ -312,8 +309,10 @@ namespace Ogre /// You may want to see ForwardPlusBase::setFineLightMaskGranularity /// for control over Forward+ lights. void setFineLightMaskGranularity( bool useFineGranularity ) - { mFineLightMaskGranularity = useFineGranularity; } - bool getFineLightMaskGranularity() const{ return mFineLightMaskGranularity; } + { + mFineLightMaskGranularity = useFineGranularity; + } + bool getFineLightMaskGranularity() const { return mFineLightMaskGranularity; } #endif /** Toggles whether light-space position is calculated in vertex or pixel shader. @@ -337,7 +336,7 @@ namespace Ogre bool getShadowReceiversInPixelShader() const { return mShadowReceiversInPixelShader; } void setDebugPssmSplits( bool bDebug ); - bool getDebugPssmSplits() const { return mDebugPssmSplits; } + bool getDebugPssmSplits() const { return mDebugPssmSplits; } /** Toggle whether the roughness value (set via material parameters and via roughness textures) is perceptual or raw. @@ -356,8 +355,8 @@ namespace Ogre void setPerceptualRoughness( bool bPerceptualRoughness ); bool getPerceptualRoughness() const; - void setShadowSettings( ShadowFilter filter ); - ShadowFilter getShadowFilter() const { return mShadowFilter; } + void setShadowSettings( ShadowFilter filter ); + ShadowFilter getShadowFilter() const { return mShadowFilter; } /** Sets the 'K' parameter of ESM filter. Defaults to 600. Small values will give weak shadows, and light bleeding (specially if the @@ -374,11 +373,11 @@ namespace Ogre @param K In range (0; infinite). */ - void setEsmK( uint16 K ); - uint16 getEsmK() const { return mEsmK; } + void setEsmK( uint16 K ); + uint16 getEsmK() const { return mEsmK; } - void setAmbientLightMode( AmbientLightMode mode ); - AmbientLightMode getAmbientLightMode() const { return mAmbientLightMode; } + void setAmbientLightMode( AmbientLightMode mode ); + AmbientLightMode getAmbientLightMode() const { return mAmbientLightMode; } /** Sets PCC @remarks @@ -413,21 +412,27 @@ namespace Ogre Errors between pccVctMinDistance & pccVctMaxDistance will be faded smoothly Use negative pccVctMaxDistance to always use VCT */ - void setParallaxCorrectedCubemap( ParallaxCorrectedCubemapBase *pcc, - float pccVctMinDistance = 1.0f, - float pccVctMaxDistance = 2.0f ); - ParallaxCorrectedCubemapBase* getParallaxCorrectedCubemap() const - { return mParallaxCorrectedCubemap; } + void setParallaxCorrectedCubemap( ParallaxCorrectedCubemapBase *pcc, + float pccVctMinDistance = 1.0f, + float pccVctMaxDistance = 2.0f ); + ParallaxCorrectedCubemapBase *getParallaxCorrectedCubemap() const + { + return mParallaxCorrectedCubemap; + } void setIrradianceVolume( IrradianceVolume *irradianceVolume ) - { mIrradianceVolume = irradianceVolume; } - IrradianceVolume* getIrradianceVolume() const { return mIrradianceVolume; } + { + mIrradianceVolume = irradianceVolume; + } + IrradianceVolume *getIrradianceVolume() const { return mIrradianceVolume; } - void setVctLighting( VctLighting *vctLighting ) { mVctLighting = vctLighting; } - VctLighting* getVctLighting() { return mVctLighting; } + void setVctLighting( VctLighting *vctLighting ) { mVctLighting = vctLighting; } + VctLighting *getVctLighting() { return mVctLighting; } void setIrradianceField( IrradianceField *irradianceField ) - { mIrradianceField = irradianceField; } + { + mIrradianceField = irradianceField; + } IrradianceField *getIrradianceField() { return mIrradianceField; } /** When false, we will use 4 cones for diffuse VCT. @@ -437,42 +442,43 @@ namespace Ogre Default value is false @param vctFullConeCount */ - void setVctFullConeCount( bool vctFullConeCount ) { mVctFullConeCount = vctFullConeCount; } - bool getVctFullConeCount() const { return mVctFullConeCount; } + void setVctFullConeCount( bool vctFullConeCount ) { mVctFullConeCount = vctFullConeCount; } + bool getVctFullConeCount() const { return mVctFullConeCount; } - void setAreaLightMasks( TextureGpu *areaLightMask ); - TextureGpu* getAreaLightMasks() const { return mAreaLightMasks; } + void setAreaLightMasks( TextureGpu *areaLightMask ); + TextureGpu *getAreaLightMasks() const { return mAreaLightMasks; } - void setLightProfilesTexture( TextureGpu *lightProfilesTex ); - TextureGpu *getLightProfilesTexture() const { return mLightProfilesTexture; } + void setLightProfilesTexture( TextureGpu *lightProfilesTex ); + TextureGpu *getLightProfilesTexture() const { return mLightProfilesTexture; } #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS - void setPlanarReflections( PlanarReflections *planarReflections ); - PlanarReflections* getPlanarReflections() const; + void setPlanarReflections( PlanarReflections *planarReflections ); + PlanarReflections *getPlanarReflections() const; #endif #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT void setUseObbRestraints( bool areaApprox, bool areaLtc ); - bool getUseObbRestraintsAreaApprox() const { return mUseObbRestraintAreaApprox; } - bool getUseObbRestraintsAreaLtc() const { return mUseObbRestraintAreaLtc; } + bool getUseObbRestraintsAreaApprox() const { return mUseObbRestraintAreaApprox; } + bool getUseObbRestraintsAreaLtc() const { return mUseObbRestraintAreaLtc; } #endif - void setUseLightBuffers(bool b); + void setUseLightBuffers( bool b ); bool getUseLightBuffers() { return mUseLightBuffers; } #if !OGRE_NO_JSON /// @copydoc Hlms::_loadJson virtual void _loadJson( const rapidjson::Value &jsonValue, const HlmsJson::NamedBlocks &blocks, HlmsDatablock *datablock, const String &resourceGroup, - HlmsJsonListener *listener, const String &additionalTextureExtension ) const; + HlmsJsonListener *listener, + const String & additionalTextureExtension ) const; /// @copydoc Hlms::_saveJson virtual void _saveJson( const HlmsDatablock *datablock, String &outString, HlmsJsonListener *listener, - const String &additionalTextureExtension ) const; + const String & additionalTextureExtension ) const; /// @copydoc Hlms::_collectSamplerblocks - virtual void _collectSamplerblocks( set::type &outSamplerblocks, - const HlmsDatablock *datablock ) const; + virtual void _collectSamplerblocks( set::type &outSamplerblocks, + const HlmsDatablock * datablock ) const; #endif }; @@ -494,6 +500,7 @@ namespace Ogre static const IdString NumSamplers; static const IdString DiffuseMapGrayscale; static const IdString EmissiveMapGrayscale; + static const char *DiffuseMap; static const char *NormalMapTex; static const char *SpecularMap; @@ -620,7 +627,7 @@ namespace Ogre /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/OgreHlmsPbsDatablock.h b/Components/Hlms/Pbs/include/OgreHlmsPbsDatablock.h index a442918ad06..ee58d609eb6 100644 --- a/Components/Hlms/Pbs/include/OgreHlmsPbsDatablock.h +++ b/Components/Hlms/Pbs/include/OgreHlmsPbsDatablock.h @@ -29,13 +29,14 @@ THE SOFTWARE. #define _OgreHlmsPbsDatablock_H_ #include "OgreHlmsPbsPrerequisites.h" + #include "OgreHlmsDatablock.h" #define _OgreHlmsTextureBaseClassExport _OgreHlmsPbsExport #define OGRE_HLMS_TEXTURE_BASE_CLASS HlmsPbsBaseTextureDatablock #define OGRE_HLMS_TEXTURE_BASE_MAX_TEX NUM_PBSM_TEXTURE_TYPES #define OGRE_HLMS_CREATOR_CLASS HlmsPbs - #include "OgreHlmsTextureBaseClass.h" +#include "OgreHlmsTextureBaseClass.h" #undef _OgreHlmsTextureBaseClassExport #undef OGRE_HLMS_TEXTURE_BASE_CLASS #undef OGRE_HLMS_TEXTURE_BASE_MAX_TEX @@ -46,128 +47,129 @@ THE SOFTWARE. namespace Ogre { /** \addtogroup Core - * @{ - */ + * @{ + */ /** \addtogroup Resources - * @{ - */ + * @{ + */ namespace PbsBrdf { - enum PbsBrdf - { - FLAG_UNCORRELATED = 0x80000000, - FLAG_SPERATE_DIFFUSE_FRESNEL = 0x40000000, - FLAG_LEGACY_MATH = 0x20000000, - FLAG_FULL_LEGACY = 0x08000000, - BRDF_MASK = 0x00000FFF, - - /// Most physically accurate BRDF we have. Good for representing - /// the majority of materials. - /// Uses: - /// * Roughness/Distribution/NDF term: GGX - /// * Geometric/Visibility term: Smith GGX Height-Correlated - /// * Normalized Disney Diffuse BRDF,see - /// "Moving Frostbite to Physically Based Rendering" from - /// Sebastien Lagarde & Charles de Rousiers - Default = 0x00000000, - - /// Implements Cook-Torrance BRDF. - /// Uses: - /// * Roughness/Distribution/NDF term: Beckmann - /// * Geometric/Visibility term: Cook-Torrance - /// * Lambertian Diffuse. - /// - /// Ideal for silk (use high roughness values), synthetic fabric - CookTorrance = 0x00000001, - - /// Implements Normalized Blinn Phong using a normalization - /// factor of (n + 8) / (8 * pi) - /// The main reason to use this BRDF is performance. It's cheaper, - /// while still looking somewhat similar to Default. - /// If you still need more performance, see BlinnPhongLegacy - BlinnPhong = 0x00000002, - - /// Same as Default, but the geometry term is not height-correlated - /// which most notably causes edges to be dimmer and is less correct. - /// Unity (Marmoset too?) use an uncorrelated term, so you may want to - /// use this BRDF to get the closest look for a nice exchangeable - /// pipeline workflow. - DefaultUncorrelated = Default|FLAG_UNCORRELATED, - - /// Same as Default but the fresnel of the diffuse is calculated - /// differently. Normally the diffuse component would be multiplied against - /// the inverse of the specular's fresnel to maintain energy conservation. - /// This has the nice side effect that to achieve a perfect mirror effect, - /// you just need to raise the fresnel term to 1; which is very intuitive - /// to artists (specially if using coloured fresnel) - /// - /// When using this BRDF, the diffuse fresnel will be calculated differently, - /// causing the diffuse component to still affect the colour even when - /// the fresnel = 1 (although subtly). To achieve a perfect mirror you will - /// have to set the fresnel to 1 *and* the diffuse colour to black; - /// which can be unintuitive for artists. - /// - /// This BRDF is very useful for representing surfaces with complex refractions - /// and reflections like glass, transparent plastics, fur, and surface with - /// refractions and multiple rescattering that cannot be represented well - /// with the default BRDF. - DefaultSeparateDiffuseFresnel = Default|FLAG_SPERATE_DIFFUSE_FRESNEL, - - /// @see DefaultSeparateDiffuseFresnel. This is the same - /// but the Cook Torrance model is used instead. - /// - /// Ideal for shiny objects like glass toy marbles, some types of rubber. - /// silk, synthetic fabric. - CookTorranceSeparateDiffuseFresnel = CookTorrance|FLAG_SPERATE_DIFFUSE_FRESNEL, - - /// Like DefaultSeparateDiffuseFresnel, but uses BlinnPhong as base. - BlinnPhongSeparateDiffuseFresnel = BlinnPhong|FLAG_SPERATE_DIFFUSE_FRESNEL, - - /// Implements traditional / the original non-PBR blinn phong: - /// * Looks more like a 2000-2005's game - /// * Ignores fresnel completely. - /// * Works with Roughness in range (0; 1]. We automatically convert - /// this parameter for you to shininess. - /// * Assumes your Light power is set to PI (or a multiple) like with - /// most other Brdfs. - /// * Diffuse & Specular will automatically be - /// multiplied/divided by PI for you (assuming you - /// set your Light power to PI). - /// The main scenario to use this BRDF is: - /// * Performance. This is the fastest BRDF. - /// * You were using Default, but are ok with how this one looks, - /// so you switch to this one instead. - BlinnPhongLegacyMath = BlinnPhong|FLAG_LEGACY_MATH, - - /// Implements traditional / the original non-PBR blinn phong: - /// * Looks more like a 2000-2005's game - /// * Ignores fresnel completely. - /// * Roughness is actually the shininess parameter; which is in range (0; inf) - /// although most used ranges are in (0; 500]. - /// * Assumes your Light power is set to 1.0. - /// * Diffuse & Specular is unmodified. - /// There are two possible reasons to use this BRDF: - /// * Performance. This is the fastest BRDF. - /// * You're porting your app from Ogre 1.x and want to maintain that - /// Fixed-Function look for some odd reason, and your materials - /// already dealt in shininess, and your lights are already calibrated. - /// - /// Important: If switching from Default to BlinnPhongFullLegacy, you'll probably see - /// that your scene is too bright. This is probably because Default divides diffuse - /// by PI and you usually set your lights' power to a multiple of PI to compensate. - /// If your scene is too bright, kist divide your lights by PI. - /// BlinnPhongLegacyMath performs that conversion for you automatically at - /// material level instead of doing it at light level. - BlinnPhongFullLegacy = BlinnPhongLegacyMath|FLAG_FULL_LEGACY, - }; + enum PbsBrdf + { + FLAG_UNCORRELATED = 0x80000000, + FLAG_SPERATE_DIFFUSE_FRESNEL = 0x40000000, + FLAG_LEGACY_MATH = 0x20000000, + FLAG_FULL_LEGACY = 0x08000000, + BRDF_MASK = 0x00000FFF, + + /// Most physically accurate BRDF we have. Good for representing + /// the majority of materials. + /// Uses: + /// * Roughness/Distribution/NDF term: GGX + /// * Geometric/Visibility term: Smith GGX Height-Correlated + /// * Normalized Disney Diffuse BRDF,see + /// "Moving Frostbite to Physically Based Rendering" from + /// Sebastien Lagarde & Charles de Rousiers + Default = 0x00000000, + + /// Implements Cook-Torrance BRDF. + /// Uses: + /// * Roughness/Distribution/NDF term: Beckmann + /// * Geometric/Visibility term: Cook-Torrance + /// * Lambertian Diffuse. + /// + /// Ideal for silk (use high roughness values), synthetic fabric + CookTorrance = 0x00000001, + + /// Implements Normalized Blinn Phong using a normalization + /// factor of (n + 8) / (8 * pi) + /// The main reason to use this BRDF is performance. It's cheaper, + /// while still looking somewhat similar to Default. + /// If you still need more performance, see BlinnPhongLegacy + BlinnPhong = 0x00000002, + + /// Same as Default, but the geometry term is not height-correlated + /// which most notably causes edges to be dimmer and is less correct. + /// Unity (Marmoset too?) use an uncorrelated term, so you may want to + /// use this BRDF to get the closest look for a nice exchangeable + /// pipeline workflow. + DefaultUncorrelated = Default | FLAG_UNCORRELATED, + + /// Same as Default but the fresnel of the diffuse is calculated + /// differently. Normally the diffuse component would be multiplied against + /// the inverse of the specular's fresnel to maintain energy conservation. + /// This has the nice side effect that to achieve a perfect mirror effect, + /// you just need to raise the fresnel term to 1; which is very intuitive + /// to artists (specially if using coloured fresnel) + /// + /// When using this BRDF, the diffuse fresnel will be calculated differently, + /// causing the diffuse component to still affect the colour even when + /// the fresnel = 1 (although subtly). To achieve a perfect mirror you will + /// have to set the fresnel to 1 *and* the diffuse colour to black; + /// which can be unintuitive for artists. + /// + /// This BRDF is very useful for representing surfaces with complex refractions + /// and reflections like glass, transparent plastics, fur, and surface with + /// refractions and multiple rescattering that cannot be represented well + /// with the default BRDF. + DefaultSeparateDiffuseFresnel = Default | FLAG_SPERATE_DIFFUSE_FRESNEL, + + /// @see DefaultSeparateDiffuseFresnel. This is the same + /// but the Cook Torrance model is used instead. + /// + /// Ideal for shiny objects like glass toy marbles, some types of rubber. + /// silk, synthetic fabric. + CookTorranceSeparateDiffuseFresnel = CookTorrance | FLAG_SPERATE_DIFFUSE_FRESNEL, + + /// Like DefaultSeparateDiffuseFresnel, but uses BlinnPhong as base. + BlinnPhongSeparateDiffuseFresnel = BlinnPhong | FLAG_SPERATE_DIFFUSE_FRESNEL, + + /// Implements traditional / the original non-PBR blinn phong: + /// * Looks more like a 2000-2005's game + /// * Ignores fresnel completely. + /// * Works with Roughness in range (0; 1]. We automatically convert + /// this parameter for you to shininess. + /// * Assumes your Light power is set to PI (or a multiple) like with + /// most other Brdfs. + /// * Diffuse & Specular will automatically be + /// multiplied/divided by PI for you (assuming you + /// set your Light power to PI). + /// The main scenario to use this BRDF is: + /// * Performance. This is the fastest BRDF. + /// * You were using Default, but are ok with how this one looks, + /// so you switch to this one instead. + BlinnPhongLegacyMath = BlinnPhong | FLAG_LEGACY_MATH, + + /// Implements traditional / the original non-PBR blinn phong: + /// * Looks more like a 2000-2005's game + /// * Ignores fresnel completely. + /// * Roughness is actually the shininess parameter; which is in range (0; inf) + /// although most used ranges are in (0; 500]. + /// * Assumes your Light power is set to 1.0. + /// * Diffuse & Specular is unmodified. + /// There are two possible reasons to use this BRDF: + /// * Performance. This is the fastest BRDF. + /// * You're porting your app from Ogre 1.x and want to maintain that + /// Fixed-Function look for some odd reason, and your materials + /// already dealt in shininess, and your lights are already calibrated. + /// + /// Important: If switching from Default to BlinnPhongFullLegacy, you'll probably see + /// that your scene is too bright. This is probably because Default divides diffuse + /// by PI and you usually set your lights' power to a multiple of PI to compensate. + /// If your scene is too bright, kist divide your lights by PI. + /// BlinnPhongLegacyMath performs that conversion for you automatically at + /// material level instead of doing it at light level. + BlinnPhongFullLegacy = BlinnPhongLegacyMath | FLAG_FULL_LEGACY, + }; } /** Contains information needed by PBS (Physically Based Shading) for OpenGL 3+ & D3D11+ - */ + */ class _OgreHlmsPbsExport HlmsPbsDatablock : public HlmsPbsBaseTextureDatablock { friend class HlmsPbs; + public: enum TransparencyModes { @@ -210,47 +212,47 @@ namespace Ogre protected: /// [0] = Regular one. /// [1] = Used during shadow mapping - //uint16 mFullParametersBytes[2]; - uint8 mUvSource[NUM_PBSM_SOURCES]; - uint8 mBlendModes[4]; - uint8 mFresnelTypeSizeBytes; //4 if mFresnel is float, 12 if it is vec3 - bool mTwoSided; - bool mUseAlphaFromTextures; - uint8 mWorkflow; - bool mReceiveShadows; - uint8 mCubemapIdxInDescSet; - bool mUseEmissiveAsLightmap; - bool mUseDiffuseMapAsGrayscale; + // uint16 mFullParametersBytes[2]; + uint8 mUvSource[NUM_PBSM_SOURCES]; + uint8 mBlendModes[4]; + uint8 mFresnelTypeSizeBytes; // 4 if mFresnel is float, 12 if it is vec3 + bool mTwoSided; + bool mUseAlphaFromTextures; + uint8 mWorkflow; + bool mReceiveShadows; + uint8 mCubemapIdxInDescSet; + bool mUseEmissiveAsLightmap; + bool mUseDiffuseMapAsGrayscale; TransparencyModes mTransparencyMode; - float mBgDiffuse[4]; - float mkDr, mkDg, mkDb; //kD - float _padding0; - float mkSr, mkSg, mkSb; //kS - float mRoughness; - float mFresnelR, mFresnelG, mFresnelB; //F0 - float mTransparencyValue; - float mDetailNormalWeight[4]; - float mDetailWeight[4]; - float mDetailsOffsetScale[4][4]; - float mEmissive[3]; - float mNormalMapWeight; - float mRefractionStrength; - float mClearCoat; - float mClearCoatRoughness; - float _padding1; - float mUserValue[3][4]; //can be used in custom pieces - //uint16 mTexIndices[NUM_PBSM_TEXTURE_TYPES]; + float mBgDiffuse[4]; + float mkDr, mkDg, mkDb; // kD + float _padding0; + float mkSr, mkSg, mkSb; // kS + float mRoughness; + float mFresnelR, mFresnelG, mFresnelB; // F0 + float mTransparencyValue; + float mDetailNormalWeight[4]; + float mDetailWeight[4]; + float mDetailsOffsetScale[4][4]; + float mEmissive[3]; + float mNormalMapWeight; + float mRefractionStrength; + float mClearCoat; + float mClearCoatRoughness; + float _padding1; + float mUserValue[3][4]; // can be used in custom pieces + // uint16 mTexIndices[NUM_PBSM_TEXTURE_TYPES]; CubemapProbe *mCubemapProbe; /// @see PbsBrdf::PbsBrdf - uint32 mBrdf; + uint32 mBrdf; virtual void cloneImpl( HlmsDatablock *datablock ) const; virtual bool bakeTextures( bool hasSeparateSamplers ); - void scheduleConstBufferUpdate(); + void scheduleConstBufferUpdate(); virtual void uploadToConstBuffer( char *dstPtr, uint8 dirtyFlags ); virtual void notifyOptimizationStrategyChanged(); @@ -358,34 +360,33 @@ namespace Ogre When set to false transparency calculations ignore the alpha channel in the textures */ - HlmsPbsDatablock( IdString name, HlmsPbs *creator, - const HlmsMacroblock *macroblock, - const HlmsBlendblock *blendblock, - const HlmsParamVec ¶ms ); + HlmsPbsDatablock( IdString name, HlmsPbs *creator, const HlmsMacroblock *macroblock, + const HlmsBlendblock *blendblock, const HlmsParamVec ¶ms ); virtual ~HlmsPbsDatablock(); /// Sets the diffuse background colour. When no diffuse texture is present, this /// solid colour replaces it, and can act as a background for the detail maps. - void setBackgroundDiffuse( const ColourValue &bgDiffuse ); + void setBackgroundDiffuse( const ColourValue &bgDiffuse ); ColourValue getBackgroundDiffuse() const; - /// Sets the diffuse colour (final multiplier). The colour will be divided by PI for energy conservation. - void setDiffuse( const Vector3 &diffuseColour ); + /// Sets the diffuse colour (final multiplier). The colour will be divided by PI for energy + /// conservation. + void setDiffuse( const Vector3 &diffuseColour ); Vector3 getDiffuse() const; /// Sets the specular colour. - void setSpecular( const Vector3 &specularColour ); + void setSpecular( const Vector3 &specularColour ); Vector3 getSpecular() const; /// Sets the roughness - void setRoughness( float roughness ); + void setRoughness( float roughness ); float getRoughness() const; /// Sets emissive colour (e.g. a firefly). Emissive colour has no physical basis. /// Though in HDR, if you're working in lumens, this value should probably be in lumens too. /// To disable emissive, setEmissive( Vector3::ZERO ) and unset any texture /// in PBSM_EMISSIVE slot. - void setEmissive( const Vector3 &emissiveColour ); + void setEmissive( const Vector3 &emissiveColour ); Vector3 getEmissive() const; /// Returns true iif getEmissive is non-zero bool hasEmissiveConstant() const; @@ -410,7 +411,7 @@ namespace Ogre it could cause a stall. @param bEnableMetallic */ - void setWorkflow( Workflows workflow ); + void setWorkflow( Workflows workflow ); Workflows getWorkflow() const; /** Sets the metalness in a metallic workflow. @@ -420,7 +421,7 @@ namespace Ogre @param metalness Value in range [0; 1] */ - void setMetalness( float metalness ); + void setMetalness( float metalness ); float getMetalness() const; /** Calculates fresnel (F0 in most books) based on the IOR. @@ -461,7 +462,7 @@ namespace Ogre using HlmsPbsBaseTextureDatablock::setTexture; void setTexture( PbsTextureTypes texUnit, const String &name, - const HlmsSamplerblock *refParams=0 ); + const HlmsSamplerblock *refParams = 0 ); /** Sets which UV set to use for the given texture. Calling this function triggers a HlmsDatablock::flushRenderables. @@ -545,7 +546,7 @@ namespace Ogre ZW = Constains the UV scale. Default value is Vector4( 0, 0, 1, 1 ) */ - void setDetailMapOffsetScale( uint8 detailMap, const Vector4 &offsetScale ); + void setDetailMapOffsetScale( uint8 detailMap, const Vector4 &offsetScale ); Vector4 getDetailMapOffsetScale( uint8 detailMap ) const; /** Allows support for two sided lighting. Disabled by default (faster) @@ -562,8 +563,8 @@ namespace Ogre While oneSidedShadowCast == CULL_NONE is usually the "correct" option, setting oneSidedShadowCast=CULL_ANTICLOCKWISE can prevent ugly self-shadowing on interiors. */ - void setTwoSidedLighting( bool twoSided, bool changeMacroblock=true, - CullingMode oneSidedShadowCast=CULL_ANTICLOCKWISE ); + void setTwoSidedLighting( bool twoSided, bool changeMacroblock = true, + CullingMode oneSidedShadowCast = CULL_ANTICLOCKWISE ); bool getTwoSidedLighting() const; virtual bool hasCustomShadowMacroblock() const; @@ -599,9 +600,9 @@ namespace Ogre void setTransparency( float transparency, TransparencyModes mode = Transparent, bool useAlphaFromTextures = true, bool changeBlendblock = true ); - float getTransparency() const { return mTransparencyValue; } - TransparencyModes getTransparencyMode() const { return mTransparencyMode; } - bool getUseAlphaFromTextures() const { return mUseAlphaFromTextures; } + float getTransparency() const { return mTransparencyValue; } + TransparencyModes getTransparencyMode() const { return mTransparencyMode; } + bool getUseAlphaFromTextures() const { return mUseAlphaFromTextures; } /** Sets the strength of the refraction, i.e. how much displacement in screen space. @@ -613,8 +614,8 @@ namespace Ogre we have to fallback to regular alpha blending due to the screen space pixel landing outside the screen) */ - void setRefractionStrength( float strength ); - float getRefractionStrength() const { return mRefractionStrength; } + void setRefractionStrength( float strength ); + float getRefractionStrength() const { return mRefractionStrength; } /** Sets the strength of the of the clear coat layer and its roughness. @param strength @@ -622,10 +623,10 @@ namespace Ogre useful to control transitions between parts of the surface that have a clear coat layers and parts that don't. */ - void setClearCoat( float clearCoat ); - void setClearCoatRoughness( float roughness ); - float getClearCoat() const { return mClearCoat; } - float getClearCoatRoughness() const { return mClearCoatRoughness; } + void setClearCoat( float clearCoat ); + void setClearCoatRoughness( float roughness ); + float getClearCoat() const { return mClearCoat; } + float getClearCoatRoughness() const { return mClearCoatRoughness; } /** When false, objects with this material will not receive shadows (independent of whether they case shadows or not) @@ -643,7 +644,7 @@ namespace Ogre @param userValueIdx Which userValue to modify, in the range [0; 3) */ - void setUserValue( uint8 userValueIdx, const Vector4 &value ); + void setUserValue( uint8 userValueIdx, const Vector4 &value ); Vector4 getUserValue( uint8 userValueIdx ) const; /** When set, it treats the emissive map as a lightmap; which means it will @@ -711,12 +712,12 @@ namespace Ogre The probe that should affect this material to enable manual mode. Null pointer to disable manual mode and switch to auto. */ - void setCubemapProbe( CubemapProbe *probe ); - CubemapProbe* getCubemapProbe() const; + void setCubemapProbe( CubemapProbe *probe ); + CubemapProbe *getCubemapProbe() const; /// Changes the BRDF in use. Calling this function may trigger an /// HlmsDatablock::flushRenderables - void setBrdf( PbsBrdf::PbsBrdf brdf ); + void setBrdf( PbsBrdf::PbsBrdf brdf ); uint32 getBrdf() const; /** Helper function to import & convert values from Unity (specular workflow). @@ -743,13 +744,13 @@ namespace Ogre You could create an alias however, and thus have two copies of the same texture with different loading parameters. */ - bool suggestUsingSRGB( PbsTextureTypes type ) const; + bool suggestUsingSRGB( PbsTextureTypes type ) const; uint32 suggestFiltersForType( PbsTextureTypes type ) const; virtual ColourValue getDiffuseColour() const; virtual ColourValue getEmissiveColour() const; - virtual TextureGpu* getDiffuseTexture() const; - virtual TextureGpu* getEmissiveTexture() const; + virtual TextureGpu *getDiffuseTexture() const; + virtual TextureGpu *getEmissiveTexture() const; virtual void notifyTextureChanged( TextureGpu *texture, TextureGpuListener::Reason reason, void *extraData ); @@ -763,7 +764,7 @@ namespace Ogre /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/OgreHlmsPbsPrerequisites.h b/Components/Hlms/Pbs/include/OgreHlmsPbsPrerequisites.h index 19cedf3f2bb..f39463fb0c4 100644 --- a/Components/Hlms/Pbs/include/OgreHlmsPbsPrerequisites.h +++ b/Components/Hlms/Pbs/include/OgreHlmsPbsPrerequisites.h @@ -31,28 +31,28 @@ THE SOFTWARE. #include "OgrePrerequisites.h" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WINRT -# if defined( OGRE_STATIC_LIB ) || defined( OGRE_PBS__STATIC_LIB ) -# define _OgreHlmsPbsExport -# else -# if defined( OgreHlmsPbs_EXPORTS ) -# define _OgreHlmsPbsExport __declspec( dllexport ) -# else -# if defined( __MINGW32__ ) -# define _OgreHlmsPbsExport -# else -# define _OgreHlmsPbsExport __declspec( dllimport ) -# endif -# endif -# endif -#elif defined ( OGRE_GCC_VISIBILITY ) -# if !defined( OGRE_STATIC_LIB ) -# define _OgreHlmsPbsExport __attribute__ ((visibility("default"))) -# else -# define _OgreHlmsPbsExport __attribute__ ((visibility("hidden"))) -# endif +# if defined( OGRE_STATIC_LIB ) || defined( OGRE_PBS__STATIC_LIB ) +# define _OgreHlmsPbsExport +# else +# if defined( OgreHlmsPbs_EXPORTS ) +# define _OgreHlmsPbsExport __declspec( dllexport ) +# else +# if defined( __MINGW32__ ) +# define _OgreHlmsPbsExport +# else +# define _OgreHlmsPbsExport __declspec( dllimport ) +# endif +# endif +# endif +#elif defined( OGRE_GCC_VISIBILITY ) +# if !defined( OGRE_STATIC_LIB ) +# define _OgreHlmsPbsExport __attribute__( ( visibility( "default" ) ) ) +# else +# define _OgreHlmsPbsExport __attribute__( ( visibility( "hidden" ) ) ) +# endif #else -# define _OgreHlmsPbsExport -#endif +# define _OgreHlmsPbsExport +#endif namespace Ogre { @@ -108,6 +108,6 @@ namespace Ogre class ParallaxCorrectedCubemapAuto; class ParallaxCorrectedCubemapBase; class VctLighting; -} +} // namespace Ogre #endif diff --git a/Components/Hlms/Pbs/include/OgreIrradianceVolume.h b/Components/Hlms/Pbs/include/OgreIrradianceVolume.h index 4ca90fba8bf..43ff43af928 100644 --- a/Components/Hlms/Pbs/include/OgreIrradianceVolume.h +++ b/Components/Hlms/Pbs/include/OgreIrradianceVolume.h @@ -29,50 +29,52 @@ THE SOFTWARE. #define _OgreIrradianceVolume_H_ #include "OgreHlmsPbsPrerequisites.h" -#include "OgreHlmsBufferManager.h" + #include "OgreConstBufferPool.h" -#include "OgreRay.h" +#include "OgreHlmsBufferManager.h" #include "OgreRawPtr.h" +#include "OgreRay.h" + #include "OgreHeaderPrefix.h" namespace Ogre { /** \addtogroup Component - * @{ - */ + * @{ + */ /** \addtogroup Material - * @{ - */ + * @{ + */ class _OgreHlmsPbsExport IrradianceVolume { private: - HlmsManager *mHlmsManager; + HlmsManager *mHlmsManager; - uint32 mNumBlocksX; - uint32 mNumBlocksY; - uint32 mNumBlocksZ; + uint32 mNumBlocksX; + uint32 mNumBlocksY; + uint32 mNumBlocksZ; /// Value kept for storing original creation parameters. It's not used after creation. bool mFadeAttenuationOverDistace; /// Tweaks how strong Irradiance Volume should be. /// In range (0; inf) - float mPowerScale; + float mPowerScale; /// Value kept for storing original creation parameters; /// as in every frame it just gets multiplied against mPowerScale float mIrradianceMaxPower; Vector3 mIrradianceOrigin; Vector3 mIrradianceCellSize; - TextureGpu *mIrradianceVolume; - HlmsSamplerblock const *mIrradianceSamplerblock; + TextureGpu * mIrradianceVolume; + HlmsSamplerblock const *mIrradianceSamplerblock; - float* mVolumeData; - float* mBlurredVolumeData; + float *mVolumeData; + float *mBlurredVolumeData; /// Cached data for faster changeVolumeData() - size_t mRowPitch; - size_t mSlicePitch; + size_t mRowPitch; + size_t mSlicePitch; public: void createIrradianceVolumeTexture( uint32 numBlocksX, uint32 numBlocksY, uint32 numBlocksZ ); @@ -82,55 +84,53 @@ namespace Ogre void updateIrradianceVolumeTexture(); void freeMemory(); - void changeVolumeData(uint32 x, uint32 y, uint32 z, uint32 direction_id, const Vector3& delta); + void changeVolumeData( uint32 x, uint32 y, uint32 z, uint32 direction_id, const Vector3 &delta ); - static void gaussFilter( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + static void gaussFilter( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth ); - static void gaussFilterX( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + static void gaussFilterX( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth, - const float * RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); - static void gaussFilterY( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + const float *RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); + static void gaussFilterY( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth, - const float * RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); - static void gaussFilterZ( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + const float *RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); + static void gaussFilterZ( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth, - const float * RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); + const float *RESTRICT_ALIAS kernel, int kernelStart, int kernelEnd ); public: IrradianceVolume( HlmsManager *hlmsManager ); ~IrradianceVolume(); - float getIrradianceMaxPower() const { return mIrradianceMaxPower; } + float getIrradianceMaxPower() const { return mIrradianceMaxPower; } /// Not really used. It's only use is keeping track of creation parameters. - void setIrradianceMaxPower(float power) { mIrradianceMaxPower = power; } + void setIrradianceMaxPower( float power ) { mIrradianceMaxPower = power; } - const Vector3& getIrradianceOrigin() const { return mIrradianceOrigin; } - void setIrradianceOrigin(const Vector3& origin) { mIrradianceOrigin = origin; } + const Vector3 &getIrradianceOrigin() const { return mIrradianceOrigin; } + void setIrradianceOrigin( const Vector3 &origin ) { mIrradianceOrigin = origin; } - const Vector3& getIrradianceCellSize() const { return mIrradianceCellSize; } - void setIrradianceCellSize(const Vector3& cellSize) { mIrradianceCellSize = cellSize; } + const Vector3 &getIrradianceCellSize() const { return mIrradianceCellSize; } + void setIrradianceCellSize( const Vector3 &cellSize ) { mIrradianceCellSize = cellSize; } /// Not really used. It's only use is keeping track of creation parameters. - void setFadeAttenuationOverDistace( bool fade ) { mFadeAttenuationOverDistace = fade; } - bool getFadeAttenuationOverDistace() const { return mFadeAttenuationOverDistace; } + void setFadeAttenuationOverDistace( bool fade ) { mFadeAttenuationOverDistace = fade; } + bool getFadeAttenuationOverDistace() const { return mFadeAttenuationOverDistace; } - float getPowerScale() const { return mPowerScale; } - void setPowerScale(float power) { mPowerScale = power; } + float getPowerScale() const { return mPowerScale; } + void setPowerScale( float power ) { mPowerScale = power; } uint32 getNumBlocksX() const { return mNumBlocksX; } uint32 getNumBlocksY() const { return mNumBlocksY; } uint32 getNumBlocksZ() const { return mNumBlocksZ; } - TextureGpu* getIrradianceVolumeTexture() const { return mIrradianceVolume; } - const HlmsSamplerblock* getIrradSamplerblock() const { return mIrradianceSamplerblock; } - - + TextureGpu * getIrradianceVolumeTexture() const { return mIrradianceVolume; } + const HlmsSamplerblock *getIrradSamplerblock() const { return mIrradianceSamplerblock; } }; /** @} */ /** @} */ -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctCascadedVoxelizer.h b/Components/Hlms/Pbs/include/Vct/OgreVctCascadedVoxelizer.h index 4e1f678a605..a3e02949f8a 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctCascadedVoxelizer.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctCascadedVoxelizer.h @@ -50,10 +50,10 @@ namespace Ogre /// performance) bool bCorrectAreaLightShadows; - bool bAutoMultiplier; /// @see VctLighting::update - float thinWallCounter; /// @see VctLighting::update - float rayMarchStepScale; /// @see VctLighting::update - uint32 lightMask; /// @see VctLighting::update + bool bAutoMultiplier; /// @see VctLighting::update + float thinWallCounter; /// @see VctLighting::update + float rayMarchStepScale; /// @see VctLighting::update + uint32 lightMask; /// @see VctLighting::update /// The resolution to set to voxelizer uint32 resolution[3]; @@ -116,17 +116,17 @@ namespace Ogre { protected: FastArray mCascadeSettings; - FastArray mCascades; + FastArray mCascades; Vector3 mCameraPosition; VoxelizedMeshCache *mMeshCache; - SceneManager *mSceneManager; + SceneManager * mSceneManager; CompositorManager2 *mCompositorManager; - uint32 mNumBounces; /// @see VctLighting::update - bool mAnisotropic; /// @see VctLighting::update + uint32 mNumBounces; /// @see VctLighting::update + bool mAnisotropic; /// @see VctLighting::update bool mFirstBuild; bool mConsistentCascadeSteps; @@ -153,7 +153,7 @@ namespace Ogre /// automatically void autoCalculateStepSizes( const Vector3 stepSize ); - size_t getNumCascades() const { return mCascadeSettings.size(); } + size_t getNumCascades() const { return mCascadeSettings.size(); } VctCascadeSetting &getCascade( size_t idx ) { return mCascadeSettings[idx]; } /** Selects how we determine when we need to (partially) rebuild the voxels @@ -264,7 +264,7 @@ namespace Ogre /// CompositorWorkspaceListener override virtual void allWorkspacesBeforeBeginUpdate(); - void setCameraPosition( const Vector3 &cameraPosition ); + void setCameraPosition( const Vector3 &cameraPosition ); const Vector3 &getCameraPosition() const { return mCameraPosition; } VctLighting *getVctLighting( size_t idx ) { return mCascades[idx]; } diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctImageVoxelizer.h b/Components/Hlms/Pbs/include/Vct/OgreVctImageVoxelizer.h index 16bb88d856c..f64284abe73 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctImageVoxelizer.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctImageVoxelizer.h @@ -70,10 +70,10 @@ namespace Ogre struct Batch { FastArray instances; // one per octant - FastArray textures; + FastArray textures; }; - typedef FastArray BatchArray; + typedef FastArray BatchArray; typedef FastArray ItemArray; VoxelizedMeshCache *mMeshCache; @@ -88,10 +88,10 @@ namespace Ogre /// On other API/GPUs we may need to split the dispatch into multiple /// ones; the worst case scenario we'll have 1 batch per mesh in scene. BatchArray mBatches; - ItemArray mItems; - bool mItemOrderDirty; + ItemArray mItems; + bool mItemOrderDirty; - uint32 mTexMeshesPerBatch; // 3 * meshes per batch + uint32 mTexMeshesPerBatch; // 3 * meshes per batch HlmsComputeJob *mImageVoxelizerJob; HlmsComputeJob *mPartialClearJob; @@ -109,10 +109,10 @@ namespace Ogre { uint32 x, y, z; uint32 width, height, depth; - Aabb region; + Aabb region; float *RESTRICT_ALIAS instanceBuffer; // Temporary - uint32 diffAxis; // Used in buildRelative + uint32 diffAxis; // Used in buildRelative }; FastArray mOctants; @@ -145,6 +145,7 @@ namespace Ogre void createVoxelTextures(); void createAltVoxelTextures(); void setVoxelTexturesToJobs(); + virtual void destroyVoxelTextures(); void createInstanceBuffers(); diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctLighting.h b/Components/Hlms/Pbs/include/Vct/OgreVctLighting.h index 63851fe2b83..f0f84c1f549 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctLighting.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctLighting.h @@ -71,15 +71,15 @@ namespace Ogre /// we wouldn't be able to support anisotropic mips for high resolution voxels. /// But more importantly, we would waste 1/4th of memory (actually 1/2 of memory /// because GPUs like GCN round memory consumption to the next power of 2). - TextureGpu *mLightVoxel[4]; - HlmsSamplerblock const *mSamplerblockTrilinear; + TextureGpu * mLightVoxel[4]; + HlmsSamplerblock const *mSamplerblockTrilinear; - VctVoxelizerSourceBase *mVoxelizer; - bool mVoxelizerTexturesChanged; - bool mVoxelizerListenersRemoved; + VctVoxelizerSourceBase *mVoxelizer; + bool mVoxelizerTexturesChanged; + bool mVoxelizerListenersRemoved; - HlmsComputeJob *mLightInjectionJob; - ConstBufferPacked *mLightsConstBuffer; + HlmsComputeJob * mLightInjectionJob; + ConstBufferPacked *mLightsConstBuffer; /// Anisotropic mipmap generation consists of 2 main steps: /// @@ -88,39 +88,39 @@ namespace Ogre /// /// Step 2 takes mLightVoxel[i].mip[n] and computes mLightVoxel[i].mip[n+1] /// where i is in range [1; 3] and n is the number of mipmaps in those textures. - HlmsComputeJob *mAnisoGeneratorStep0; - FastArray mAnisoGeneratorStep1; + HlmsComputeJob * mAnisoGeneratorStep0; + FastArray mAnisoGeneratorStep1; - HlmsComputeJob *mLightVctBounceInject; - TextureGpu *mLightBounce; + HlmsComputeJob *mLightVctBounceInject; + TextureGpu * mLightBounce; - float mBakingMultiplier; - float mInvBakingMultiplier; + float mBakingMultiplier; + float mInvBakingMultiplier; - float mUpperHemisphere[3]; - float mLowerHemisphere[3]; + float mUpperHemisphere[3]; + float mLowerHemisphere[3]; float mDefaultLightDistThreshold; - bool mAnisotropic; + bool mAnisotropic; /// When we do multiple bounces, cascades can be used to improve accuracy - FastArray mExtraCascades; + FastArray mExtraCascades; ShaderParams::Param *mNumLights; ShaderParams::Param *mRayMarchStepSize; ShaderParams::Param *mVoxelCellSize; ShaderParams::Param *mDirCorrectionRatioThinWallCounter; ShaderParams::Param *mInvVoxelResolution; - ShaderParams *mShaderParams; + ShaderParams * mShaderParams; typedef vector::type ParamVec; - ParamVec mLocalBounceShaderParams; - ShaderParams::Param *mBounceVoxelCellSize; - ShaderParams::Param *mBounceInvVoxelResolution; - ShaderParams::Param *mBounceIterationDampening; - ShaderParams::Param *mBounceStartBiasInvBiasCascadeMaxLod; + ParamVec mLocalBounceShaderParams; + ShaderParams::Param * mBounceVoxelCellSize; + ShaderParams::Param * mBounceInvVoxelResolution; + ShaderParams::Param * mBounceIterationDampening; + ShaderParams::Param * mBounceStartBiasInvBiasCascadeMaxLod; ShaderParams::Param *mBounceFromPreviousProbeToNext; /// Used when cascades > 1 - ShaderParams *mBounceShaderParams; + ShaderParams * mBounceShaderParams; ResourceTransitionArray mResourceTransitions; @@ -153,7 +153,7 @@ namespace Ogre PUBLIC VARIABLE. This variable can be altered directly. Changes are reflected immediately. */ - float mSpecularSdfQuality; + float mSpecularSdfQuality; /** Sets the intensity/brightness of the GI. e.g. to make the GI 2x brighter, set it to 2.0 To make the GI darker, set it to 0.5 @@ -165,17 +165,16 @@ namespace Ogre @remark PUBLIC VARIABLE. This variable can be altered directly. Changes are reflected immediately. */ - float mMultiplier; + float mMultiplier; protected: - VoxelVisualizer *mDebugVoxelVisualizer; ShaderParams::Param *addLocalBounceShaderParam( const char *name ); void restoreSwappedTextures(); - float addLight( ShaderVctLight * RESTRICT_ALIAS vctLight, Light *light, + float addLight( ShaderVctLight *RESTRICT_ALIAS vctLight, Light *light, const Vector3 &voxelOrigin, const Vector3 &invVoxelSize ); void createTextures(); @@ -250,13 +249,13 @@ namespace Ogre Changes to this value take effect after calling VctLighting::update and autoMultiplier must be set to false */ - void setBakingMultiplier( float bakingMult ); - float getBakingMultiplier() const { return mBakingMultiplier; } + void setBakingMultiplier( float bakingMult ); + float getBakingMultiplier() const { return mBakingMultiplier; } /// If you've set setBakingMultiplier but haven't yet called VctLighting::update /// with autoMultiplier = false, this function returns the baking multiplier that /// is currently in use (beware of floating point accuracy differences) - float getCurrentBakingMultiplier() const { return 1.0f / mInvBakingMultiplier; } + float getCurrentBakingMultiplier() const { return 1.0f / mInvBakingMultiplier; } /** @param sceneManager @@ -288,9 +287,9 @@ namespace Ogre are supposed to be shadowed won't be shadowed) @param lightMask */ - void update( SceneManager *sceneManager, uint32 numBounces, - float thinWallCounter=1.0f, bool autoMultiplier=true, - float rayMarchStepScale=1.0f, uint32 lightMask=0xffffffff ); + void update( SceneManager *sceneManager, uint32 numBounces, float thinWallCounter = 1.0f, + bool autoMultiplier = true, float rayMarchStepScale = 1.0f, + uint32 lightMask = 0xffffffff ); /// When VctImageVoxelizer::buildRelative is called; voxelizer's textures /// (albedo, normal, emissive) may be swapped for a copy. @@ -304,8 +303,7 @@ namespace Ogre size_t getConstBufferSize() const; - void fillConstBufferData( const Matrix4 &viewMatrix, - float * RESTRICT_ALIAS passBufferPtr ) const; + void fillConstBufferData( const Matrix4 &viewMatrix, float *RESTRICT_ALIAS passBufferPtr ) const; bool shouldEnableSpecularSdfQuality() const; @@ -328,7 +326,7 @@ namespace Ogre *must* be called again to repopulate the light data. */ void setAnisotropic( bool bAnisotropic ); - bool isAnisotropic() const { return mAnisotropic; } + bool isAnisotropic() const { return mAnisotropic; } /** Extremely similar version of SceneManager::setAmbientLight In fact the hemisphereDir parameter is shared and set in SceneManager::setAmbientLight @@ -343,22 +341,22 @@ namespace Ogre @param lowerHemisphere lowerHemisphere should be set to the ground colour */ - void setAmbient( const ColourValue& upperHemisphere, const ColourValue& lowerHemisphere ); + void setAmbient( const ColourValue &upperHemisphere, const ColourValue &lowerHemisphere ); - TextureGpu** getLightVoxelTextures() { return mLightVoxel; } + TextureGpu **getLightVoxelTextures() { return mLightVoxel; } TextureGpu **getLightVoxelTextures( const size_t cascadeIdx ); - uint32 getNumVoxelTextures() const { return mAnisotropic ? 4u : 1u; } - const HlmsSamplerblock* getBindTrilinearSamplerblock() - { return mSamplerblockTrilinear; } + uint32 getNumVoxelTextures() const { return mAnisotropic ? 4u : 1u; } + + const HlmsSamplerblock *getBindTrilinearSamplerblock() { return mSamplerblockTrilinear; } - const VctVoxelizerSourceBase* getVoxelizer() const { return mVoxelizer; } + const VctVoxelizerSourceBase *getVoxelizer() const { return mVoxelizer; } - //TextureGpuListener overloads + // TextureGpuListener overloads virtual void notifyTextureChanged( TextureGpu *texture, TextureGpuListener::Reason reason, void *extraData ); - virtual bool shouldStayLoaded( TextureGpu *texture ) { return false; } + virtual bool shouldStayLoaded( TextureGpu *texture ) { return false; } }; -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctMaterial.h b/Components/Hlms/Pbs/include/Vct/OgreVctMaterial.h index 775b7842ab5..0a6d51d8ad4 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctMaterial.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctMaterial.h @@ -29,6 +29,7 @@ THE SOFTWARE. #define _OgreVctMaterial_H_ #include "OgreHlmsPbsPrerequisites.h" + #include "OgreId.h" #include "ogrestd/map.h" @@ -44,58 +45,62 @@ namespace Ogre public: struct DatablockConversionResult { - uint32 slotIdx; - ConstBufferPacked *constBuffer; - uint16 diffuseTexIdx; - uint16 emissiveTexIdx; + uint32 slotIdx; + ConstBufferPacked *constBuffer; + uint16 diffuseTexIdx; + uint16 emissiveTexIdx; DatablockConversionResult() : - slotIdx( (uint32)-1 ), constBuffer( 0 ), + slotIdx( (uint32)-1 ), + constBuffer( 0 ), diffuseTexIdx( std::numeric_limits::max() ), - emissiveTexIdx( std::numeric_limits::max() ) {} + emissiveTexIdx( std::numeric_limits::max() ) + { + } - bool hasDiffuseTex() const - { return diffuseTexIdx != std::numeric_limits::max(); } - bool hasEmissiveTex() const - { return emissiveTexIdx != std::numeric_limits::max(); } + bool hasDiffuseTex() const { return diffuseTexIdx != std::numeric_limits::max(); } + bool hasEmissiveTex() const { return emissiveTexIdx != std::numeric_limits::max(); } }; protected: - typedef set::type HlmsDatablockSet; + typedef set::type HlmsDatablockSet; struct MaterialBucket { - ConstBufferPacked *buffer; - bool hasDiffuse; - bool hasEmissive; - HlmsDatablockSet datablocks; + ConstBufferPacked *buffer; + bool hasDiffuse; + bool hasEmissive; + HlmsDatablockSet datablocks; }; typedef vector::type BucketVec; - typedef map::type DatablockConversionResultMap; + typedef map::type DatablockConversionResultMap; + DatablockConversionResultMap mDatablockConversionResults; BucketVec mBuckets; - VaoManager *mVaoManager; - - typedef map::type TextureToPoolEntryMap; - uint16 mNumUsedPoolSlices; - TextureGpu *mTexturePool; - TextureGpuManager *mTextureGpuManager; - CompositorManager2 *mCompositorManager; - TextureGpu *mDownsampleTex; - Pass *mDownsampleMatPass2DArray; - Pass *mDownsampleMatPass2D; - CompositorWorkspace *mDownsampleWorkspace2DArray; - CompositorWorkspace *mDownsampleWorkspace2D; - TextureToPoolEntryMap mTextureToPoolEntry; - - DatablockConversionResult addDatablockToBucket( HlmsDatablock *datablock, + VaoManager *mVaoManager; + + typedef map::type TextureToPoolEntryMap; + + uint16 mNumUsedPoolSlices; + TextureGpu * mTexturePool; + TextureGpuManager * mTextureGpuManager; + CompositorManager2 * mCompositorManager; + TextureGpu * mDownsampleTex; + Pass * mDownsampleMatPass2DArray; + Pass * mDownsampleMatPass2D; + CompositorWorkspace * mDownsampleWorkspace2DArray; + CompositorWorkspace * mDownsampleWorkspace2D; + TextureToPoolEntryMap mTextureToPoolEntry; + + DatablockConversionResult addDatablockToBucket( HlmsDatablock * datablock, MaterialBucket &bucket ); + uint16 getPoolSliceIdxForTexture( TextureGpu *texture ); void resizeTexturePool(); - MaterialBucket* findFreeBucketFor( HlmsDatablock *datablock ); + MaterialBucket *findFreeBucketFor( HlmsDatablock *datablock ); public: VctMaterial( IdType id, VaoManager *vaoManager, CompositorManager2 *compositorManager, @@ -110,9 +115,9 @@ namespace Ogre /// initTempResources must already have been called. DatablockConversionResult addDatablock( HlmsDatablock *datablock ); - TextureGpu* getTexturePool() const { return mTexturePool; } + TextureGpu *getTexturePool() const { return mTexturePool; } }; -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizer.h b/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizer.h index 8fe3b8dee36..aa4527b975e 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizer.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizer.h @@ -33,7 +33,7 @@ THE SOFTWARE. #include "Vao/OgreVertexBufferDownloadHelper.h" #ifdef OGRE_FORCE_VCT_VOXELIZER_DETERMINISTIC - #include "OgreMesh2.h" +# include "OgreMesh2.h" #endif #include "OgreHeaderPrefix.h" @@ -46,22 +46,22 @@ namespace Ogre { enum VoxelizerJobSetting { - Index32bit = 1u << 0u, - CompressedVertexFormat = 1u << 1u, - HasDiffuseTex = 1u << 2u, - HasEmissiveTex = 1u << 3u, + Index32bit = 1u << 0u, + CompressedVertexFormat = 1u << 1u, + HasDiffuseTex = 1u << 2u, + HasEmissiveTex = 1u << 3u, }; } struct VoxelizerBucket { - HlmsComputeJob *job; - ConstBufferPacked *materialBuffer; - UavBufferPacked *vertexBuffer; - UavBufferPacked *indexBuffer; - bool needsTexPool; + HlmsComputeJob * job; + ConstBufferPacked *materialBuffer; + UavBufferPacked * vertexBuffer; + UavBufferPacked * indexBuffer; + bool needsTexPool; - bool operator < ( const VoxelizerBucket &other ) const + bool operator<( const VoxelizerBucket &other ) const { if( this->job != other.job ) return this->job < other.job; @@ -115,35 +115,35 @@ namespace Ogre protected: struct MappedBuffers { - float * RESTRICT_ALIAS uncompressedVertexBuffer; - size_t index16BufferOffset; - size_t index32BufferOffset; + float *RESTRICT_ALIAS uncompressedVertexBuffer; + size_t index16BufferOffset; + size_t index32BufferOffset; }; struct PartitionedSubMesh { - uint32 vbOffset; - uint32 ibOffset; - uint32 numIndices; - uint32 aabbSubMeshIdx; + uint32 vbOffset; + uint32 ibOffset; + uint32 numIndices; + uint32 aabbSubMeshIdx; }; struct QueuedSubMesh { - //Due to an infrastructure bug, we're commenting out the 'STREAM_DOWNLOAD' path - //The goal was to queue up several transfer GPU -> staging area, then map - //the staging area. However this backfired as each AsyncTicket will hold its own - //StagingBuffer (and each one is at least 4MB) instead of sharing it. This balloons - //memory consumption and still needs to map staging buffers a lot, defeating part of - //its purpose. - //Since fixing it would take a lot of time, it has been ifdef'ed out and instead - //we download the data and immediately map it. This causes more stalls but is - //far more memory friendly. + // Due to an infrastructure bug, we're commenting out the 'STREAM_DOWNLOAD' path + // The goal was to queue up several transfer GPU -> staging area, then map + // the staging area. However this backfired as each AsyncTicket will hold its own + // StagingBuffer (and each one is at least 4MB) instead of sharing it. This balloons + // memory consumption and still needs to map staging buffers a lot, defeating part of + // its purpose. + // Since fixing it would take a lot of time, it has been ifdef'ed out and instead + // we download the data and immediately map it. This causes more stalls but is + // far more memory friendly. #ifdef STREAM_DOWNLOAD VertexBufferDownloadHelper downloadHelper; #else - size_t downloadVertexStart; - size_t downloadNumVertices; + size_t downloadVertexStart; + size_t downloadNumVertices; #endif FastArray partSubMeshes; }; @@ -152,10 +152,10 @@ namespace Ogre struct QueuedMesh { - bool bCompressed; - uint32 numItems; - uint32 indexCountSplit; - QueuedSubMeshArray submeshes; + bool bCompressed; + uint32 numItems; + uint32 indexCountSplit; + QueuedSubMeshArray submeshes; }; typedef map::type v1MeshPtrMap; @@ -164,40 +164,40 @@ namespace Ogre #else typedef map::type MeshPtrMap; #endif - typedef FastArray ItemArray; + typedef FastArray ItemArray; - v1MeshPtrMap mMeshesV1; - MeshPtrMap mMeshesV2; + v1MeshPtrMap mMeshesV1; + MeshPtrMap mMeshesV2; - ItemArray mItems; + ItemArray mItems; /// HlmsComputeJob have internal caches, thus we could dynamically change properties /// and let the internal cache handle whether a compute job needs to be compiled. /// /// However the way we will be using may abuse the cache too much, thus we pre-set /// all variants as long as the number of variants is manageable. - HlmsComputeJob *mComputeJobs[1u<<4u]; - HlmsComputeJob *mAabbCalculator[1u<<2u]; - HlmsComputeJob *mAabbWorldSpaceJob; + HlmsComputeJob *mComputeJobs[1u << 4u]; + HlmsComputeJob *mAabbCalculator[1u << 2u]; + HlmsComputeJob *mAabbWorldSpaceJob; - uint32 mTotalNumInstances; - float *mCpuInstanceBuffer; - UavBufferPacked *mInstanceBuffer; + uint32 mTotalNumInstances; + float * mCpuInstanceBuffer; + UavBufferPacked * mInstanceBuffer; ReadOnlyBufferPacked *mInstanceBufferAsTex; - UavBufferPacked *mVertexBufferCompressed; - UavBufferPacked *mVertexBufferUncompressed; - UavBufferPacked *mIndexBuffer16; - UavBufferPacked *mIndexBuffer32; - //Aabb Calculator - uint32 mNumUncompressedPartSubMeshes16; - uint32 mNumUncompressedPartSubMeshes32; - uint32 mNumCompressedPartSubMeshes16; - uint32 mNumCompressedPartSubMeshes32; + UavBufferPacked * mVertexBufferCompressed; + UavBufferPacked * mVertexBufferUncompressed; + UavBufferPacked * mIndexBuffer16; + UavBufferPacked * mIndexBuffer32; + // Aabb Calculator + uint32 mNumUncompressedPartSubMeshes16; + uint32 mNumUncompressedPartSubMeshes32; + uint32 mNumCompressedPartSubMeshes16; + uint32 mNumCompressedPartSubMeshes32; TexBufferPacked *mGpuPartitionedSubMeshes; UavBufferPacked *mMeshAabb; - bool mNeedsAlbedoMipmaps; - bool mNeedsAllMipmaps; + bool mNeedsAlbedoMipmaps; + bool mNeedsAllMipmaps; uint32 mNumVerticesCompressed; uint32 mNumVerticesUncompressed; @@ -210,36 +210,36 @@ namespace Ogre struct QueuedInstance { - MovableObject *movableObject; - uint32 vertexBufferStart; - uint32 indexBufferStart; - uint32 numIndices; - uint32 aabbSubMeshIdx; - uint32 materialIdx; - bool needsAabbUpdate; + MovableObject *movableObject; + uint32 vertexBufferStart; + uint32 indexBufferStart; + uint32 numIndices; + uint32 aabbSubMeshIdx; + uint32 materialIdx; + bool needsAabbUpdate; }; struct BucketData { typedef map::type InstancesPerOctantIdxMap; - FastArray queuedInst; - InstancesPerOctantIdxMap numInstancesAfterCulling; + FastArray queuedInst; + InstancesPerOctantIdxMap numInstancesAfterCulling; }; - typedef map< VoxelizerBucket, BucketData >::type VoxelizerBucketMap; - VoxelizerBucketMap mBuckets; + typedef map::type VoxelizerBucketMap; + VoxelizerBucketMap mBuckets; VctMaterial *mVctMaterial; /// Whether mRegionToVoxelize is manually set or autocalculated - bool mAutoRegion; + bool mAutoRegion; /// Limit to mRegionToVoxelize in case mAutoRegion is true - Aabb mMaxRegion; + Aabb mMaxRegion; struct Octant { uint32 x, y, z; uint32 width, height, depth; - Aabb region; + Aabb region; }; FastArray mOctants; @@ -268,11 +268,11 @@ namespace Ogre void buildMeshBuffers(); void createVoxelTextures(); - void placeItemsInBuckets(); + void placeItemsInBuckets(); size_t countSubMeshPartitionsIn( Item *item ) const; - void createInstanceBuffers(); - void destroyInstanceBuffers(); - void fillInstanceBuffers(); + void createInstanceBuffers(); + void destroyInstanceBuffers(); + void fillInstanceBuffers(); void computeMeshAabbs(); @@ -301,7 +301,7 @@ namespace Ogre Use std::numeric_limits::max to avoid partitioning at all. */ - void addItem( Item *item, bool bCompressed, uint32 indexCountSplit=0u ); + void addItem( Item *item, bool bCompressed, uint32 indexCountSplit = 0u ); /** Removes an item added via VctVoxelizer::addItem @remarks @@ -328,9 +328,8 @@ namespace Ogre @param maxRegion Maximum size of the regions are allowed to cover (mostly useful when autoRegion = true) */ - void setRegionToVoxelize( bool autoRegion, - const Aabb ®ionToVoxelize, - const Aabb &maxRegion=Aabb::BOX_INFINITE ); + void setRegionToVoxelize( bool autoRegion, const Aabb ®ionToVoxelize, + const Aabb &maxRegion = Aabb::BOX_INFINITE ); /// Does nothing if VctVoxelizer::setRegionToVoxelize( false, ... ) was called. void autoCalculateRegion(); @@ -347,7 +346,7 @@ namespace Ogre void build( SceneManager *sceneManager ); }; -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizerSourceBase.h b/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizerSourceBase.h index 51522bc86db..f57fa47166d 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizerSourceBase.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVctVoxelizerSourceBase.h @@ -61,13 +61,13 @@ namespace Ogre TextureGpu *mNormalVox; TextureGpu *mAccumValVox; - RenderSystem *mRenderSystem; - VaoManager *mVaoManager; - HlmsManager *mHlmsManager; + RenderSystem * mRenderSystem; + VaoManager * mVaoManager; + HlmsManager * mHlmsManager; TextureGpuManager *mTextureGpuManager; DebugVisualizationMode mDebugVisualizationMode; - VoxelVisualizer *mDebugVoxelVisualizer; + VoxelVisualizer * mDebugVoxelVisualizer; uint32 mWidth; uint32 mHeight; @@ -76,14 +76,14 @@ namespace Ogre Aabb mRegionToVoxelize; virtual void destroyVoxelTextures(); - void setTextureToDebugVisualizer(); + void setTextureToDebugVisualizer(); public: VctVoxelizerSourceBase( IdType id, RenderSystem *renderSystem, HlmsManager *hlmsManager ); virtual ~VctVoxelizerSourceBase(); void setDebugVisualization( VctVoxelizerSourceBase::DebugVisualizationMode mode, - SceneManager *sceneManager ); + SceneManager * sceneManager ); VctVoxelizerSourceBase::DebugVisualizationMode getDebugVisualizationMode() const; Vector3 getVoxelOrigin() const; @@ -96,8 +96,8 @@ namespace Ogre TextureGpu *getEmissiveVox() { return mEmissiveVox; } TextureGpuManager *getTextureGpuManager(); - RenderSystem *getRenderSystem(); - HlmsManager *getHlmsManager(); + RenderSystem * getRenderSystem(); + HlmsManager * getHlmsManager(); }; } // namespace Ogre diff --git a/Components/Hlms/Pbs/include/Vct/OgreVoxelVisualizer.h b/Components/Hlms/Pbs/include/Vct/OgreVoxelVisualizer.h index d36cdafea70..423dea32083 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVoxelVisualizer.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVoxelVisualizer.h @@ -16,22 +16,22 @@ namespace Ogre void createBuffers(); public: - VoxelVisualizer( IdType id, ObjectMemoryManager *objectMemoryManager, - SceneManager* manager, uint8 renderQueueId ); + VoxelVisualizer( IdType id, ObjectMemoryManager *objectMemoryManager, SceneManager *manager, + uint8 renderQueueId ); virtual ~VoxelVisualizer(); void setTrackingVoxel( TextureGpu *opacityTex, TextureGpu *texture, bool anyColour ); - //Overrides from MovableObject - virtual const String& getMovableType() const; + // Overrides from MovableObject + virtual const String &getMovableType() const; - //Overrides from Renderable - virtual const LightList& getLights() const; - virtual void getRenderOperation( v1::RenderOperation& op, bool casterPass ); - virtual void getWorldTransforms( Matrix4* xform ) const; - virtual bool getCastsShadows() const; + // Overrides from Renderable + virtual const LightList &getLights() const; + virtual void getRenderOperation( v1::RenderOperation &op, bool casterPass ); + virtual void getWorldTransforms( Matrix4 *xform ) const; + virtual bool getCastsShadows() const; }; -} +} // namespace Ogre #include "OgreHeaderSuffix.h" diff --git a/Components/Hlms/Pbs/include/Vct/OgreVoxelizedMeshCache.h b/Components/Hlms/Pbs/include/Vct/OgreVoxelizedMeshCache.h index 83e708cbbb9..3ec2ff3751c 100644 --- a/Components/Hlms/Pbs/include/Vct/OgreVoxelizedMeshCache.h +++ b/Components/Hlms/Pbs/include/Vct/OgreVoxelizedMeshCache.h @@ -51,8 +51,8 @@ namespace Ogre public: struct VoxelizedMesh { - uint64 hash[2]; - String meshName; + uint64 hash[2]; + String meshName; TextureGpu *albedoVox; TextureGpu *normalVox; TextureGpu *emissiveVox; @@ -61,12 +61,12 @@ namespace Ogre protected: typedef map::type MeshCacheMap; - uint32 mMeshWidth; - uint32 mMeshHeight; - uint32 mMeshDepth; - uint32 mMeshMaxWidth; - uint32 mMeshMaxHeight; - uint32 mMeshMaxDepth; + uint32 mMeshWidth; + uint32 mMeshHeight; + uint32 mMeshDepth; + uint32 mMeshMaxWidth; + uint32 mMeshMaxHeight; + uint32 mMeshMaxDepth; Ogre::Vector3 mMeshDimensionPerPixel; MeshCacheMap mMeshes; diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp index 785a5804c9f..1edbde42ae5 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreCubemapProbe.cpp @@ -30,18 +30,18 @@ THE SOFTWARE. #include "Cubemaps/OgreCubemapProbe.h" -#include "Cubemaps/OgreParallaxCorrectedCubemapBase.h" -#include "Cubemaps/OgreParallaxCorrectedCubemap.h" -#include "OgreTextureGpuManager.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreLogManager.h" -#include "OgreLwString.h" -#include "OgreId.h" #include "Compositor/OgreCompositorManager2.h" #include "Compositor/OgreCompositorWorkspace.h" +#include "Cubemaps/OgreParallaxCorrectedCubemap.h" +#include "Cubemaps/OgreParallaxCorrectedCubemapBase.h" #include "OgreCamera.h" -#include "OgreSceneManager.h" +#include "OgreId.h" #include "OgreInternalCubemapProbe.h" +#include "OgreLogManager.h" +#include "OgreLwString.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreSceneManager.h" +#include "OgreTextureGpuManager.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreVaoManager.h" @@ -98,13 +98,12 @@ namespace Ogre { if( mNumDatablockUsers && !mConstBufferForManualProbes ) { - OGRE_ASSERT_LOW(!mCreator->getAutomaticMode()); + OGRE_ASSERT_LOW( !mCreator->getAutomaticMode() ); SceneManager *sceneManager = mCreator->getSceneManager(); VaoManager *vaoManager = sceneManager->getDestinationRenderSystem()->getVaoManager(); mConstBufferForManualProbes = vaoManager->createConstBuffer( - ParallaxCorrectedCubemap::getConstBufferSizeStatic(), - BT_DEFAULT, 0, false ); + ParallaxCorrectedCubemap::getConstBufferSizeStatic(), BT_DEFAULT, 0, false ); mCreator->_addManuallyActiveProbe( this ); } mDirty = true; @@ -145,7 +144,7 @@ namespace Ogre if( mTexture && mTexture->getResidencyStatus() != GpuResidency::OnStorage && !mCreator->getAutomaticMode() ) { - mTexture->_transitionTo( GpuResidency::OnStorage, (uint8*)0 ); + mTexture->_transitionTo( GpuResidency::OnStorage, (uint8 *)0 ); } if( mCamera ) @@ -167,7 +166,7 @@ namespace Ogre { SceneManager *sceneManager = mCreator->getSceneManager(); TextureGpuManager *textureManager = - sceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + sceneManager->getDestinationRenderSystem()->getTextureGpuManager(); textureManager->destroyTexture( mTexture ); } mTexture = 0; @@ -188,9 +187,10 @@ namespace Ogre } else { - LogManager::getSingleton().logMessage( "Warning: CubemapProbe::acquireTextureAuto failed. " - "You ran out of slots in the cubemap array. " - "Disabling this probe" ); + LogManager::getSingleton().logMessage( + "Warning: CubemapProbe::acquireTextureAuto failed. " + "You ran out of slots in the cubemap array. " + "Disabling this probe" ); } } //----------------------------------------------------------------------------------- @@ -219,7 +219,7 @@ namespace Ogre mInternalProbe = sceneManager->_createCubemapProbe( sceneType ); SceneNode *sceneNode = - sceneManager->getRootSceneNode( sceneType )->createChildSceneNode( sceneType ); + sceneManager->getRootSceneNode( sceneType )->createChildSceneNode( sceneType ); sceneNode->attachObject( mInternalProbe ); sceneNode->setIndestructibleByClearScene( true ); @@ -247,8 +247,8 @@ namespace Ogre sceneNode->setStatic( mStatic ); SceneManager *sceneManager = mCreator->getSceneManager(); - SceneNode *rootNode = sceneManager->getRootSceneNode( mStatic ? SCENE_STATIC : - SCENE_DYNAMIC ); + SceneNode *rootNode = + sceneManager->getRootSceneNode( mStatic ? SCENE_STATIC : SCENE_DYNAMIC ); rootNode->addChild( sceneNode ); } } @@ -270,12 +270,12 @@ namespace Ogre sceneNode->setOrientation( qRot ); mCreator->fillConstBufferData( *this, Matrix4::IDENTITY, Matrix3::IDENTITY, - reinterpret_cast( mInternalProbe->mGpuData ) ); + reinterpret_cast( mInternalProbe->mGpuData ) ); - uint32 finalValue = uint32(mPriority << 16u) | mCubemapArrayIdx; + uint32 finalValue = uint32( mPriority << 16u ) | mCubemapArrayIdx; memcpy( &mInternalProbe->mGpuData[3][3], &finalValue, sizeof( finalValue ) ); - Vector3 probeToAreaCenterOffsetLS = mInvOrientation * (mArea.mCenter - mProbeShape.mCenter); + Vector3 probeToAreaCenterOffsetLS = mInvOrientation * ( mArea.mCenter - mProbeShape.mCenter ); mInternalProbe->mGpuData[4][3] = probeToAreaCenterOffsetLS.x; mInternalProbe->mGpuData[5][3] = probeToAreaCenterOffsetLS.y; mInternalProbe->mGpuData[6][3] = probeToAreaCenterOffsetLS.z; @@ -308,8 +308,8 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - void CubemapProbe::setTextureParams( uint32 width, uint32 height, bool useManual, - PixelFormatGpu pf, bool isStatic, SampleDescription sampleDesc ) + void CubemapProbe::setTextureParams( uint32 width, uint32 height, bool useManual, PixelFormatGpu pf, + bool isStatic, SampleDescription sampleDesc ) { if( !mCreator->getAutomaticMode() ) { @@ -327,7 +327,7 @@ namespace Ogre destroyTexture(); char tmpBuffer[64]; - LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); texName.a( "CubemapProbe_", Id::generateNewId() ); uint32 flags = TextureFlags::RenderToTexture; @@ -344,7 +344,7 @@ namespace Ogre SceneManager *sceneManager = mCreator->getSceneManager(); TextureGpuManager *textureManager = - sceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + sceneManager->getDestinationRenderSystem()->getTextureGpuManager(); mTexture = textureManager->createTexture( texName.c_str(), GpuPageOutStrategy::Discard, flags, TextureTypes::TypeCube ); mTexture->setResolution( width, height ); @@ -367,18 +367,17 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - void CubemapProbe::initWorkspace( float cameraNear, float cameraFar, - IdString workspaceDefOverride, + void CubemapProbe::initWorkspace( float cameraNear, float cameraFar, IdString workspaceDefOverride, const CompositorChannelVec &additionalChannels, uint8 executionMask ) { - assert( (mTexture != 0 || mCreator->getAutomaticMode()) && "Call setTextureParams first!" ); + assert( ( mTexture != 0 || mCreator->getAutomaticMode() ) && "Call setTextureParams first!" ); destroyWorkspace(); acquireTextureAuto(); if( !mTexture ) - return; //acquireTextureAuto failed. There are no available slots + return; // acquireTextureAuto failed. There are no available slots CompositorWorkspaceDef const *workspaceDef = mCreator->getDefaultWorkspaceDef(); CompositorManager2 *compositorManager = workspaceDef->getCompositorManager(); @@ -388,12 +387,11 @@ namespace Ogre mWorkspaceDefName = workspaceDef->getName(); SceneManager *sceneManager = mCreator->getSceneManager(); - mCamera = sceneManager->createCamera( mTexture->getNameStr() + - StringConverter::toString( mCubemapArrayIdx ), - true, true ); - mCamera->setFOVy( Degree(90) ); + mCamera = sceneManager->createCamera( + mTexture->getNameStr() + StringConverter::toString( mCubemapArrayIdx ), true, true ); + mCamera->setFOVy( Degree( 90 ) ); mCamera->setAspectRatio( 1 ); - mCamera->setFixedYawAxis(false); + mCamera->setFixedYawAxis( false ); mCamera->setNearClipDistance( cameraNear ); mCamera->setFarClipDistance( cameraFar ); @@ -414,7 +412,7 @@ namespace Ogre if( mStatic ) { - //Set camera to skip light culling (efficiency) + // Set camera to skip light culling (efficiency) mCamera->setLightCullingVisibility( false, false ); } else @@ -423,7 +421,7 @@ namespace Ogre } if( !mCreator->getAutomaticMode() ) - mTexture->_transitionTo( GpuResidency::Resident, (uint8*)0 ); + mTexture->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); CompositorChannelVec channels; channels.reserve( 2u + additionalChannels.size() ); @@ -437,30 +435,25 @@ namespace Ogre if( !mStatic && !mCreator->getAutomaticMode() ) { - mClearWorkspace = - compositorManager->addWorkspace( sceneManager, channels, - mCamera, - "AutoGen_ParallaxCorrectedCubemapClear_Workspace", - false ); + mClearWorkspace = compositorManager->addWorkspace( + sceneManager, channels, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace", + false ); } } //----------------------------------------------------------------------------------- - bool CubemapProbe::isInitialized() const - { - return mWorkspace != 0; - } + bool CubemapProbe::isInitialized() const { return mWorkspace != 0; } //----------------------------------------------------------------------------------- void CubemapProbe::set( const Vector3 &cameraPos, const Aabb &area, const Vector3 &areaInnerRegion, const Matrix3 &orientation, const Aabb &probeShape ) { - mProbeCameraPos = cameraPos; - mArea = area; - mAreaInnerRegion = areaInnerRegion; - mOrientation = orientation; - mInvOrientation = mOrientation.Inverse(); - mProbeShape = probeShape; - - //Add some padding. + mProbeCameraPos = cameraPos; + mArea = area; + mAreaInnerRegion = areaInnerRegion; + mOrientation = orientation; + mInvOrientation = mOrientation.Inverse(); + mProbeShape = probeShape; + + // Add some padding. Real padding = 1.005f; mArea.mHalfSize *= padding; mProbeShape.mHalfSize *= padding; @@ -473,20 +466,20 @@ namespace Ogre areaLocalToShape.mCenter = mInvOrientation * areaLocalToShape.mCenter; areaLocalToShape.mCenter += mProbeShape.mCenter; - if( (!mProbeShape.contains( mArea ) && !mCreator->getAutomaticMode()) || - (!mProbeShape.intersects( mArea ) && mCreator->getAutomaticMode()) ) + if( ( !mProbeShape.contains( mArea ) && !mCreator->getAutomaticMode() ) || + ( !mProbeShape.intersects( mArea ) && mCreator->getAutomaticMode() ) ) { if( !mCreator->getAutomaticMode() ) { LogManager::getSingleton().logMessage( - "WARNING: Area must be fully inside probe's shape otherwise " - "artifacts appear. Forcing area to be inside probe" ); + "WARNING: Area must be fully inside probe's shape otherwise " + "artifacts appear. Forcing area to be inside probe" ); } else { LogManager::getSingleton().logMessage( - "WARNING: Area must intersect with the probe's shape otherwise " - "PCC will not have any effect. Forcing intersection" ); + "WARNING: Area must intersect with the probe's shape otherwise " + "PCC will not have any effect. Forcing intersection" ); } Vector3 vMin = mArea.getMinimum() * 0.98f; Vector3 vMax = mArea.getMaximum() * 0.98f; @@ -510,7 +503,7 @@ namespace Ogre } else { - //We're not initialized yet, but still save the intention... + // We're not initialized yet, but still save the intention... mStatic = isStatic; } } @@ -526,14 +519,11 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - uint16_t CubemapProbe::getPriority() const - { - return mPriority; - } + uint16_t CubemapProbe::getPriority() const { return mPriority; } //----------------------------------------------------------------------------------- Real CubemapProbe::getNDF( const Vector3 &posLS ) const { - //Work in the upper left corner of the box. (Like Aabb::distance) + // Work in the upper left corner of the box. (Like Aabb::distance) Vector3 dist; dist.x = Math::Abs( posLS.x ); dist.y = Math::Abs( posLS.y ); @@ -542,8 +532,8 @@ namespace Ogre const Vector3 innerRange = mArea.mHalfSize * mAreaInnerRegion; const Vector3 outerRange = mArea.mHalfSize; - //1e-6f avoids division by zero. - Vector3 ndf = (dist - innerRange) / (outerRange - innerRange + Real(1e-6f)); + // 1e-6f avoids division by zero. + Vector3 ndf = ( dist - innerRange ) / ( outerRange - innerRange + Real( 1e-6f ) ); return std::max( std::max( ndf.x, ndf.y ), ndf.z ); } @@ -568,11 +558,9 @@ namespace Ogre SceneManager *sceneManager = mCreator->getSceneManager(); CompositorChannelVec channels( mWorkspace->getExternalRenderTargets() ); - mClearWorkspace = - compositorManager->addWorkspace( sceneManager, channels, - mCamera, - "AutoGen_ParallaxCorrectedCubemapClear_Workspace", - false ); + mClearWorkspace = compositorManager->addWorkspace( + sceneManager, channels, mCamera, "AutoGen_ParallaxCorrectedCubemapClear_Workspace", + false ); } mClearWorkspace->_update(); @@ -618,8 +606,7 @@ namespace Ogre SceneManager *sceneManager = mCreator->getSceneManager(); VaoManager *vaoManager = sceneManager->getDestinationRenderSystem()->getVaoManager(); mConstBufferForManualProbes = vaoManager->createConstBuffer( - ParallaxCorrectedCubemap::getConstBufferSizeStatic(), - BT_DEFAULT, 0, false ); + ParallaxCorrectedCubemap::getConstBufferSizeStatic(), BT_DEFAULT, 0, false ); mCreator->_addManuallyActiveProbe( this ); } } @@ -643,11 +630,11 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - const SceneNode* CubemapProbe::getInternalCubemapProbeSceneNode() const + const SceneNode *CubemapProbe::getInternalCubemapProbeSceneNode() const { SceneNode const *retVal = 0; if( mInternalProbe ) retVal = mInternalProbe->getParentSceneNode(); return retVal; } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp index bd819834a54..f385d1521ab 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemap.cpp @@ -31,40 +31,37 @@ THE SOFTWARE. #include "Cubemaps/OgreParallaxCorrectedCubemap.h" #include "Compositor/OgreCompositorManager2.h" -#include "Compositor/OgreCompositorWorkspaceDef.h" -#include "Compositor/OgreCompositorWorkspace.h" #include "Compositor/OgreCompositorNodeDef.h" +#include "Compositor/OgreCompositorWorkspace.h" +#include "Compositor/OgreCompositorWorkspaceDef.h" #include "Compositor/Pass/PassClear/OgreCompositorPassClearDef.h" #include "Compositor/Pass/PassQuad/OgreCompositorPassQuadDef.h" #include "Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h" -#include "OgreHlmsPbs.h" -#include "OgreRoot.h" #include "OgreCamera.h" -#include "OgreSceneManager.h" -#include "OgreRenderQueue.h" -#include "OgreTextureGpuManager.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreHlmsManager.h" -#include "OgreHlms.h" #include "OgreDepthBuffer.h" -#include "OgreMaterialManager.h" -#include "OgreTechnique.h" +#include "OgreHlms.h" +#include "OgreHlmsManager.h" +#include "OgreHlmsPbs.h" +#include "OgreItem.h" #include "OgreLwString.h" -#include "OgreMeshManager2.h" +#include "OgreMaterialManager.h" #include "OgreMesh2.h" +#include "OgreMeshManager2.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreRenderQueue.h" +#include "OgreRoot.h" +#include "OgreSceneManager.h" #include "OgreSubMesh2.h" -#include "OgreItem.h" +#include "OgreTechnique.h" +#include "OgreTextureGpuManager.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreStagingBuffer.h" #include "Vao/OgreVaoManager.h" namespace Ogre { - const char *cSuffixes[6] = - { - "PX", "NX", - "PY", "NY", - "PZ", "NZ", + const char *cSuffixes[6] = { + "PX", "NX", "PY", "NY", "PZ", "NZ", }; ParallaxCorrectedCubemap::ParallaxCorrectedCubemap( IdType id, Root *root, @@ -90,31 +87,32 @@ namespace Ogre mProxyQueryMask( proxyQueryMask ), mReservedRqId( reservedRqId ) { - memset( mProbeNDFs, 0, sizeof(mProbeNDFs) ); - memset( mProbeBlendFactors, 0, sizeof(mProbeBlendFactors) ); - memset( mCollectedProbes, 0, sizeof(mCollectedProbes) ); - memset( mBlendCubemapTUs, 0, sizeof(mBlendCubemapTUs) ); - memset( mCopyCubemapTUs, 0, sizeof(mCopyCubemapTUs) ); - memset( mProxyItems, 0, sizeof(mProxyItems) ); - memset( mProxyNodes, 0, sizeof(mProxyNodes) ); + memset( mProbeNDFs, 0, sizeof( mProbeNDFs ) ); + memset( mProbeBlendFactors, 0, sizeof( mProbeBlendFactors ) ); + memset( mCollectedProbes, 0, sizeof( mCollectedProbes ) ); + memset( mBlendCubemapTUs, 0, sizeof( mBlendCubemapTUs ) ); + memset( mCopyCubemapTUs, 0, sizeof( mCopyCubemapTUs ) ); + memset( mProxyItems, 0, sizeof( mProxyItems ) ); + memset( mProxyNodes, 0, sizeof( mProxyNodes ) ); createProxyGeometry(); createCubemapBlendWorkspaceDefinition(); - //Save the TextureUnitStates for setting the cubemap probes for blending every frame. + // Save the TextureUnitStates for setting the cubemap probes for blending every frame. char tmpBuffer[64]; - LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); { materialName = "Cubemap/BlendProjectCubemap"; const size_t matNameSize = materialName.size(); - for( size_t i=0; i(); - Pass *pass = material->getTechnique(0)->getPass(0); + MaterialPtr material = MaterialManager::getSingleton() + .load( materialName.c_str(), + ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ) + .staticCast(); + Pass *pass = material->getTechnique( 0 )->getPass( 0 ); mBlendCubemapParamsVs[i] = pass->getVertexProgramParameters(); mBlendCubemapParams[i] = pass->getFragmentProgramParameters(); @@ -126,14 +124,15 @@ namespace Ogre materialName = "Cubemap/CopyCubemap_"; const size_t matNameSize = materialName.size(); - for( size_t i=0; i<6; ++i ) + for( size_t i = 0; i < 6; ++i ) { materialName.resize( matNameSize ); materialName.a( cSuffixes[i] ); - MaterialPtr material = MaterialManager::getSingleton().load( - materialName.c_str(), ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ). - staticCast(); - Pass *pass = material->getTechnique(0)->getPass(0); + MaterialPtr material = MaterialManager::getSingleton() + .load( materialName.c_str(), + ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME ) + .staticCast(); + Pass *pass = material->getTechnique( 0 )->getPass( 0 ); mCopyCubemapParams[i] = pass->getFragmentProgramParameters(); mCopyCubemapTUs[i] = pass->getTextureUnitState( 0 ); @@ -141,9 +140,8 @@ namespace Ogre } mBlankProbe.setTextureParams( 1, 1 ); - mBlankProbe.set( Vector3::ZERO, Aabb( Vector3::ZERO, Vector3::UNIT_SCALE ), - Vector3::ZERO, Matrix3::IDENTITY, - Aabb( Vector3::ZERO, Vector3::UNIT_SCALE ) ); + mBlankProbe.set( Vector3::ZERO, Aabb( Vector3::ZERO, Vector3::UNIT_SCALE ), Vector3::ZERO, + Matrix3::IDENTITY, Aabb( Vector3::ZERO, Vector3::UNIT_SCALE ) ); mBlankProbe.mDirty = false; HlmsManager *hlmsManager = mRoot->getHlmsManager(); @@ -163,7 +161,7 @@ namespace Ogre if( mBindTexture ) { TextureGpuManager *textureGpuManager = - mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); textureGpuManager->destroyTexture( mBindTexture ); mBindTexture = 0; } @@ -195,9 +193,9 @@ namespace Ogre { { TextureGpuManager *textureGpuManager = - mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); TempRttVec::const_iterator itor = mTmpRtt.begin(); - TempRttVec::const_iterator end = mTmpRtt.end(); + TempRttVec::const_iterator end = mTmpRtt.end(); while( itor != end ) { textureGpuManager->destroyTexture( itor->texture ); @@ -214,12 +212,12 @@ namespace Ogre destroyProxyItems(); char tmpBuffer[64]; - LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); materialName = "Cubemap/BlendProjectCubemap"; const size_t matNameSize = materialName.size(); - //Create the Items using that geometry - for( size_t i=0; icreateItem( mProxyMesh, SCENE_DYNAMIC ); mProxyNodes[i] = mSceneManager->getRootSceneNode()->createChildSceneNode(); @@ -237,7 +235,7 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::destroyProxyItems() { - for( size_t i=0; igetProjectionMatrix() * trackedCamera->getViewMatrix(); } //----------------------------------------------------------------------------------- - void ParallaxCorrectedCubemap::setEnabled( bool bEnabled, uint32 maxWidth, - uint32 maxHeight, PixelFormatGpu pixelFormat ) + void ParallaxCorrectedCubemap::setEnabled( bool bEnabled, uint32 maxWidth, uint32 maxHeight, + PixelFormatGpu pixelFormat ) { if( bEnabled == getEnabled() ) return; @@ -282,19 +280,16 @@ namespace Ogre if( bEnabled ) { TextureGpuManager *textureGpuManager = - mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); mBindTexture = textureGpuManager->createTexture( - "ParallaxCorrectedCubemap Blend Result " + - StringConverter::toString( getId() ), - GpuPageOutStrategy::Discard, - TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps, - TextureTypes::TypeCube ); + "ParallaxCorrectedCubemap Blend Result " + StringConverter::toString( getId() ), + GpuPageOutStrategy::Discard, + TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps, TextureTypes::TypeCube ); mBindTexture->setResolution( maxWidth, maxHeight ); mBindTexture->setPixelFormat( pixelFormat ); - mBindTexture->setNumMipmaps( PixelFormatGpuUtils::getMaxMipmapCount( maxWidth, - maxHeight ) ); + mBindTexture->setNumMipmaps( PixelFormatGpuUtils::getMaxMipmapCount( maxWidth, maxHeight ) ); mBindTexture->_setDepthBufferDefaults( DepthBuffer::POOL_NO_DEPTH, false, PFG_UNKNOWN ); - mBindTexture->_transitionTo( GpuResidency::Resident, (uint8*)0 ); + mBindTexture->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); createCubemapBlendWorkspace(); @@ -318,50 +313,45 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - bool ParallaxCorrectedCubemap::getEnabled() const - { - return mBlendWorkspace != 0; - } + bool ParallaxCorrectedCubemap::getEnabled() const { return mBlendWorkspace != 0; } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::loadResource( Resource *resource ) { - Mesh *mesh = static_cast( resource ); + Mesh *mesh = static_cast( resource ); - //Create the mesh geometry - const Vector3 c_vertices[8] = - { + // Create the mesh geometry + const Vector3 c_vertices[8] = { + // clang-format off Vector3( -1, -1, 1 ), Vector3( 1, -1, 1 ), Vector3( 1, 1, 1 ), Vector3( -1, 1, 1 ), Vector3( -1, -1, -1 ), Vector3( 1, -1, -1 ), Vector3( 1, 1, -1 ), Vector3( -1, 1, -1 ) + // clang-format on }; - const uint16 c_indexData[3 * 2 * 6] = - { - 2, 1, 0, 0, 3, 2, //Front face - 4, 5, 6, 6, 7, 4, //Back face + const uint16 c_indexData[3 * 2 * 6] = { + 2, 1, 0, 0, 3, 2, // Front face + 4, 5, 6, 6, 7, 4, // Back face - 6, 2, 3, 3, 7, 6, //Top face - 0, 1, 5, 5, 4, 0, //Bottom face + 6, 2, 3, 3, 7, 6, // Top face + 0, 1, 5, 5, 4, 0, // Bottom face - 3, 0, 4, 4, 7, 3, //Left face - 1, 2, 6, 6, 5, 1, //Right face + 3, 0, 4, 4, 7, 3, // Left face + 1, 2, 6, 6, 5, 1, // Right face }; VertexElement2Vec vertexElements; vertexElements.push_back( VertexElement2( VET_FLOAT3, VES_POSITION ) ); VaoManager *vaoManager = mSceneManager->getDestinationRenderSystem()->getVaoManager(); - VertexBufferPacked *vertexBuffer = vaoManager->createVertexBuffer( vertexElements, 8, - BT_IMMUTABLE, - (void*)c_vertices, false ); - IndexBufferPacked *indexBuffer = vaoManager->createIndexBuffer( IndexBufferPacked::IT_16BIT, - 3 * 2 * 6, BT_IMMUTABLE, - (void*)c_indexData, false ); + VertexBufferPacked *vertexBuffer = + vaoManager->createVertexBuffer( vertexElements, 8, BT_IMMUTABLE, (void *)c_vertices, false ); + IndexBufferPacked *indexBuffer = vaoManager->createIndexBuffer( + IndexBufferPacked::IT_16BIT, 3 * 2 * 6, BT_IMMUTABLE, (void *)c_indexData, false ); VertexBufferPackedVec vertexBuffers( 1, vertexBuffer ); - VertexArrayObject *vao = vaoManager->createVertexArrayObject( vertexBuffers, indexBuffer, - OT_TRIANGLE_LIST ); + VertexArrayObject *vao = + vaoManager->createVertexArrayObject( vertexBuffers, indexBuffer, OT_TRIANGLE_LIST ); SubMesh *subMesh = mesh->createSubMesh(); - for( int i=0; imVao[i].push_back( vao ); subMesh->mMaterialName = "Cubemap/BlendProjectCubemap0"; @@ -371,8 +361,8 @@ namespace Ogre void ParallaxCorrectedCubemap::createProxyGeometry() { mProxyMesh = MeshManager::getSingleton().createManual( - "AutoGen_ParallaxCorrectedCubemap_" + StringConverter::toString( getId() ) + - "_Proxy", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, this ); + "AutoGen_ParallaxCorrectedCubemap_" + StringConverter::toString( getId() ) + "_Proxy", + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, this ); RenderQueue *renderQueue = mSceneManager->getRenderQueue(); renderQueue->setRenderQueueMode( mReservedRqId, RenderQueue::FAST ); @@ -397,34 +387,34 @@ namespace Ogre String workspaceName = "AutoGen_ParallaxCorrectedCubemapBlending_Workspace"; CompositorManager2 *compositorManager = mDefaultWorkspaceDef->getCompositorManager(); CompositorWorkspaceDef *workspaceDef = - compositorManager->getWorkspaceDefinitionNoThrow( workspaceName ); + compositorManager->getWorkspaceDefinitionNoThrow( workspaceName ); if( !workspaceDef ) { - //Create blending workspace definition (blending multiple probes) - CompositorNodeDef *nodeDef = compositorManager->addNodeDefinition( - "AutoGen_ParallaxCorrectedCubemapBlending_Node" ); - //Input texture + // Create blending workspace definition (blending multiple probes) + CompositorNodeDef *nodeDef = + compositorManager->addNodeDefinition( "AutoGen_ParallaxCorrectedCubemapBlending_Node" ); + // Input texture nodeDef->addTextureSourceName( "BlendedProbeRT", 0, TextureDefinitionBase::TEXTURE_INPUT ); nodeDef->setNumTargetPass( 6 ); - for( uint32 i=0; i<6; ++i ) + for( uint32 i = 0; i < 6; ++i ) { CompositorTargetDef *targetDef = nodeDef->addTargetPass( "BlendedProbeRT", i ); targetDef->setNumPasses( i == 5 ? 2 : 1 ); { { - CompositorPassSceneDef *passScene = static_cast - ( targetDef->addPass( PASS_SCENE ) ); + CompositorPassSceneDef *passScene = + static_cast( targetDef->addPass( PASS_SCENE ) ); passScene->mIdentifier = 10u + i; passScene->mCameraCubemapReorient = true; passScene->mFirstRQ = mReservedRqId; - passScene->mLastRQ = mReservedRqId + 1u; + passScene->mLastRQ = mReservedRqId + 1u; passScene->mEnableForwardPlus = false; passScene->mIncludeOverlays = false; - passScene->mVisibilityMask = mProxyVisibilityMask; + passScene->mVisibilityMask = mProxyVisibilityMask; passScene->mLoadActionColour[0] = LoadAction::Clear; - passScene->mClearColour[0] = ColourValue::Black; + passScene->mClearColour[0] = ColourValue::Black; } if( i == 5 ) { @@ -436,35 +426,35 @@ namespace Ogre CompositorWorkspaceDef *workDef = compositorManager->addWorkspaceDefinition( workspaceName ); workDef->connectExternal( 0, nodeDef->getName(), 0 ); - //Create copy workspace definition (just one probe) + // Create copy workspace definition (just one probe) workspaceName = "AutoGen_ParallaxCorrectedCubemapCopy_Workspace"; - nodeDef = compositorManager->addNodeDefinition( - "AutoGen_ParallaxCorrectedCubemapCopy_Node" ); - //Input texture + nodeDef = + compositorManager->addNodeDefinition( "AutoGen_ParallaxCorrectedCubemapCopy_Node" ); + // Input texture nodeDef->addTextureSourceName( "CopyProbeRT", 0, TextureDefinitionBase::TEXTURE_INPUT ); nodeDef->setNumTargetPass( 6 ); char tmpBuffer[64]; - LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString materialName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); materialName = "Cubemap/CopyCubemap_"; const size_t matNameSize = materialName.size(); - for( uint32 i=0; i<6; ++i ) + for( uint32 i = 0; i < 6; ++i ) { CompositorTargetDef *targetDef = nodeDef->addTargetPass( "CopyProbeRT", i ); targetDef->setNumPasses( i == 5 ? 2 : 1 ); { { - CompositorPassQuadDef *passQuad = static_cast - ( targetDef->addPass( PASS_QUAD ) ); + CompositorPassQuadDef *passQuad = + static_cast( targetDef->addPass( PASS_QUAD ) ); materialName.resize( matNameSize ); materialName.a( cSuffixes[i] ); passQuad->mIdentifier = 10u + i; passQuad->mMaterialName = materialName.c_str(); passQuad->mAnalyzeAllTextureLayouts = true; - passQuad->mLoadActionColour[0] = LoadAction::Clear; - passQuad->mClearColour[0] = ColourValue::Black; + passQuad->mLoadActionColour[0] = LoadAction::Clear; + passQuad->mClearColour[0] = ColourValue::Black; } if( i == 5 ) { @@ -476,23 +466,22 @@ namespace Ogre workDef = compositorManager->addWorkspaceDefinition( workspaceName ); workDef->connectExternal( 0, nodeDef->getName(), 0 ); - - //Create clear workspace definition (to clear dirty probes) + // Create clear workspace definition (to clear dirty probes) workspaceName = "AutoGen_ParallaxCorrectedCubemapClear_Workspace"; - nodeDef = compositorManager->addNodeDefinition( - "AutoGen_ParallaxCorrectedCubemapClear_Node" ); - //Input texture + nodeDef = + compositorManager->addNodeDefinition( "AutoGen_ParallaxCorrectedCubemapClear_Node" ); + // Input texture nodeDef->addTextureSourceName( "ProbeRT", 0, TextureDefinitionBase::TEXTURE_INPUT ); nodeDef->setNumTargetPass( 6 ); - for( uint32 i=0; i<6; ++i ) + for( uint32 i = 0; i < 6; ++i ) { CompositorTargetDef *targetDef = nodeDef->addTargetPass( "ProbeRT", i ); targetDef->setNumPasses( 1 ); { { - CompositorPassClearDef *passClear = static_cast - ( targetDef->addPass( PASS_CLEAR ) ); + CompositorPassClearDef *passClear = + static_cast( targetDef->addPass( PASS_CLEAR ) ); passClear->mClearColour[0] = ColourValue::Black; } } @@ -505,12 +494,11 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::createCubemapBlendWorkspace() { - mBlendProxyCamera = mSceneManager->createCamera( "ParallaxCorrectedCubemap for blending " + - StringConverter::toString( getId() ), - false ); - mBlendProxyCamera->setFOVy( Degree(90) ); + mBlendProxyCamera = mSceneManager->createCamera( + "ParallaxCorrectedCubemap for blending " + StringConverter::toString( getId() ), false ); + mBlendProxyCamera->setFOVy( Degree( 90 ) ); mBlendProxyCamera->setAspectRatio( 1 ); - mBlendProxyCamera->setFixedYawAxis(false); + mBlendProxyCamera->setFixedYawAxis( false ); mBlendProxyCamera->setNearClipDistance( 0.01 ); mBlendProxyCamera->setFarClipDistance( 0.0 ); @@ -519,19 +507,13 @@ namespace Ogre IdString workspaceName( "AutoGen_ParallaxCorrectedCubemapBlending_Workspace" ); CompositorManager2 *compositorManager = mDefaultWorkspaceDef->getCompositorManager(); - mBlendWorkspace = compositorManager->addWorkspace( mSceneManager, - channels, - mBlendProxyCamera, - workspaceName, - false ); + mBlendWorkspace = compositorManager->addWorkspace( mSceneManager, channels, mBlendProxyCamera, + workspaceName, false ); mBlendWorkspace->addListener( this ); workspaceName = "AutoGen_ParallaxCorrectedCubemapCopy_Workspace"; - mCopyWorkspace = compositorManager->addWorkspace( mSceneManager, - channels, - mBlendProxyCamera, - workspaceName, - false ); + mCopyWorkspace = compositorManager->addWorkspace( mSceneManager, channels, mBlendProxyCamera, + workspaceName, false ); mCopyWorkspace->addListener( this ); } //----------------------------------------------------------------------------------- @@ -555,7 +537,7 @@ namespace Ogre { assert( mNumCollectedProbes < OGRE_MAX_CUBE_PROBES ); - for( size_t i=mNumCollectedProbes; imInvOrientation; mFinalProbe.mProbeShape = mCollectedProbes[probeIdx]->mProbeShape; - const bool requiresTrilinear = mCollectedProbes[probeIdx]->mTexture->getNumMipmaps() != - mBindTexture->getNumMipmaps(); - for( size_t i=0; i<6; ++i ) + const bool requiresTrilinear = + mCollectedProbes[probeIdx]->mTexture->getNumMipmaps() != mBindTexture->getNumMipmaps(); + for( size_t i = 0; i < 6; ++i ) { mCopyCubemapTUs[i]->setTexture( mCollectedProbes[probeIdx]->mTexture ); - mCopyCubemapTUs[i]->_setSamplerblock( requiresTrilinear ? mSamplerblockTrilinear : - mSamplerblockPoint ); + mCopyCubemapTUs[i]->_setSamplerblock( requiresTrilinear ? mSamplerblockTrilinear + : mSamplerblockPoint ); } } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::checkStagingBufferIsBigEnough() { - //Check the staging buffer is big enough to avoid a stall + // Check the staging buffer is big enough to avoid a stall VaoManager *vaoManager = mSceneManager->getDestinationRenderSystem()->getVaoManager(); const size_t neededBytes = mManuallyActiveProbes.size() * getConstBufferSize() * - vaoManager->getDynamicBufferMultiplier() * std::max( 1u, - mLastPassNumViewMatrices ); + vaoManager->getDynamicBufferMultiplier() * + std::max( 1u, mLastPassNumViewMatrices ); - if( (!mStagingBuffer && !mManuallyActiveProbes.empty()) || + if( ( !mStagingBuffer && !mManuallyActiveProbes.empty() ) || neededBytes > mStagingBuffer->getMaxSize() ) { if( mStagingBuffer ) @@ -664,11 +645,11 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::findClosestProbe() { - //When we're not inside of any probe, select the 'closest' one. - //We do that by projecting the AABBs into the camera and determining - //which AABBs occupy more visible volume (approximation) + // When we're not inside of any probe, select the 'closest' one. + // We do that by projecting the AABBs into the camera and determining + // which AABBs occupy more visible volume (approximation) CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); const uint32 systemMask = mMask; @@ -682,7 +663,7 @@ namespace Ogre { CubemapProbe *probe = *itor; - if( probe->mEnabled && (probe->mMask & systemMask) ) + if( probe->mEnabled && ( probe->mMask & systemMask ) ) { Vector3 vMin = probe->mArea.getMinimum(); Vector3 vMax = probe->mArea.getMaximum(); @@ -692,11 +673,11 @@ namespace Ogre Vector3 psMin = Vector3::UNIT_SCALE, psMax = -Vector3::UNIT_SCALE; - for( int i=0; i<8; ++i ) + for( int i = 0; i < 8; ++i ) { Vector4 transformedVert( probe->mOrientation * corners[i] ); transformedVert = viewProjMatrix * transformedVert; - transformedVert.w = std::max( transformedVert.w, Real(1e-6f) ); + transformedVert.w = std::max( transformedVert.w, Real( 1e-6f ) ); transformedVert /= transformedVert.w; Vector3 psVertex( transformedVert.ptr() ); @@ -707,21 +688,21 @@ namespace Ogre psMax.makeCeil( psVertex ); } - //Check the probe isn't behind us. + // Check the probe isn't behind us. if( psMax.z > -1.0f ) { - //psMin.z is in range [-1; 1]; bring it to range [0; 1] and square it - //in an attempt to fight Z's behavior (Z grows a lot when close to, - //camera grows little when far from camera) + // psMin.z is in range [-1; 1]; bring it to range [0; 1] and square it + // in an attempt to fight Z's behavior (Z grows a lot when close to, + // camera grows little when far from camera) psMin.z = psMin.z * 0.5f + 0.5f; psMax.z = psMax.z * 0.5f + 0.5f; psMin.z *= psMin.z; psMax.z *= psMax.z; - Real area = (psMax.x - psMin.x) * (psMax.y - psMin.y) * (psMax.z - psMin.z); + Real area = ( psMax.x - psMin.x ) * ( psMax.y - psMin.y ) * ( psMax.z - psMin.z ); if( area > mProbeNDFs[0] ) { - mProbeNDFs[0] = area; + mProbeNDFs[0] = area; mCollectedProbes[0] = probe; mNumCollectedProbes = 1; } @@ -742,7 +723,7 @@ namespace Ogre mCurrentMip = 0; - for( size_t i=0; i::max(); @@ -751,7 +732,7 @@ namespace Ogre mNumCollectedProbes = 0; CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); const uint32 systemMask = mMask; @@ -759,15 +740,15 @@ namespace Ogre { CubemapProbe *probe = *itor; - const Vector3 posLS = probe->mInvOrientation * (mTrackedPosition - probe->mArea.mCenter); + const Vector3 posLS = probe->mInvOrientation * ( mTrackedPosition - probe->mArea.mCenter ); const Aabb areaLS = probe->getAreaLS(); - if( areaLS.contains( posLS ) && probe->mEnabled && (probe->mMask & systemMask) ) + if( areaLS.contains( posLS ) && probe->mEnabled && ( probe->mMask & systemMask ) ) { const Real ndf = probe->getNDF( posLS ); if( ndf > 0 ) { - //Collect this probe, ensuring we collect the ones with the lowest NDF. + // Collect this probe, ensuring we collect the ones with the lowest NDF. uint32 probeIdx = mNumCollectedProbes; if( mNumCollectedProbes >= OGRE_MAX_CUBE_PROBES ) @@ -775,8 +756,8 @@ namespace Ogre Real highestNdf = -1; int highestNdfIdx = OGRE_MAX_CUBE_PROBES; - //Drop the probe with the highest NDF (note: we may drop this probe) - for( size_t i=0; i= highestNdf ) { @@ -790,16 +771,16 @@ namespace Ogre if( probeIdx < OGRE_MAX_CUBE_PROBES ) { - mProbeNDFs[probeIdx] = ndf; - mCollectedProbes[probeIdx] = probe; + mProbeNDFs[probeIdx] = ndf; + mCollectedProbes[probeIdx] = probe; ++mNumCollectedProbes; mNumCollectedProbes = std::min( mNumCollectedProbes, OGRE_MAX_CUBE_PROBES ); } } else { - //Early out. Use ONLY this probe. - mProbeNDFs[0] = ndf; + // Early out. Use ONLY this probe. + mProbeNDFs[0] = ndf; mCollectedProbes[0] = probe; mNumCollectedProbes = 1; itor = end; @@ -813,15 +794,15 @@ namespace Ogre if( mNumCollectedProbes == 0 ) findClosestProbe(); - for( size_t i=mNumCollectedProbes; i mProbeBlendFactors[highestIdx] ) highestIdx = i; @@ -835,11 +816,11 @@ namespace Ogre } } - //TODO: Update could be done over several frames. - for( size_t i=0; i_prepareForRendering(); - for( size_t i=0; imOrientation ); mProxyNodes[i]->setPosition( mCollectedProbes[i]->mProbeShape.mCenter ); @@ -847,11 +828,11 @@ namespace Ogre mProxyNodes[i]->setOrientation( qRot ); mProxyItems[i]->setVisible( i < mNumCollectedProbes ); - //Divide by maxComponent to get better precision in the GPU. - const Real maxComponent = std::max( mCollectedProbes[i]->mProbeShape.mHalfSize.x, - std::max( - mCollectedProbes[i]->mProbeShape.mHalfSize.y, - mCollectedProbes[i]->mProbeShape.mHalfSize.z ) ); + // Divide by maxComponent to get better precision in the GPU. + const Real maxComponent = + std::max( mCollectedProbes[i]->mProbeShape.mHalfSize.x, + std::max( mCollectedProbes[i]->mProbeShape.mHalfSize.y, + mCollectedProbes[i]->mProbeShape.mHalfSize.z ) ); Matrix4 worldScaledMatrix; worldScaledMatrix.makeTransform( mCollectedProbes[i]->mProbeShape.mCenter / maxComponent, mCollectedProbes[i]->mProbeShape.mHalfSize / maxComponent, @@ -862,43 +843,42 @@ namespace Ogre mBlendCubemapParamsVs[i]->setNamedConstant( "probeCameraPosScaled", probeCameraPosScaled ); mBlendCubemapParams[i]->setNamedConstant( "weight", mProbeBlendFactors[i] ); - const bool requiresTrilinear = mCollectedProbes[i]->mTexture->getNumMipmaps() != - mBindTexture->getNumMipmaps(); + const bool requiresTrilinear = + mCollectedProbes[i]->mTexture->getNumMipmaps() != mBindTexture->getNumMipmaps(); mBlendCubemapTUs[i]->setTexture( mCollectedProbes[i]->mTexture ); - mBlendCubemapTUs[i]->_setSamplerblock( requiresTrilinear ? mSamplerblockTrilinear : - mSamplerblockPoint ); + mBlendCubemapTUs[i]->_setSamplerblock( requiresTrilinear ? mSamplerblockTrilinear + : mSamplerblockPoint ); } - //Project p0ToCam onto p0ToP1. -// Vector3 p0ToCam = mTrackedPosition - mCollectedProbes[0]->mProbeCameraPos; -// Vector3 p0ToP1 = mCollectedProbes[1]->mProbeCameraPos - mCollectedProbes[0]->mProbeCameraPos; -// p0ToP1.normalise(); -// Vector3 finalPos = p0ToP1 * p0ToP1.dotProduct( p0ToCam ) + mCollectedProbes[0]->mProbeCameraPos; + // Project p0ToCam onto p0ToP1. + // Vector3 p0ToCam = mTrackedPosition - mCollectedProbes[0]->mProbeCameraPos; + // Vector3 p0ToP1 = mCollectedProbes[1]->mProbeCameraPos - + // mCollectedProbes[0]->mProbeCameraPos; p0ToP1.normalise(); Vector3 finalPos = p0ToP1 * + // p0ToP1.dotProduct( p0ToCam ) + mCollectedProbes[0]->mProbeCameraPos; Vector3 finalPos = mCollectedProbes[0]->mProbeCameraPos; if( mNumCollectedProbes > 1 ) { - //When mNumCollectedProbes = 2 - //mProbeBlendFactors[0] is in range [0.5; 1] so we need to move it to range [0; 1] - //When mNumCollectedProbes = 3 - //mProbeBlendFactors[0] is in range [0.333; 1] so we need to move it to range [0; 1] - //When mNumCollectedProbes = 4 - //mProbeBlendFactors[0] is in range [0.25; 1] so we need to move it to range [0; 1] + // When mNumCollectedProbes = 2 + // mProbeBlendFactors[0] is in range [0.5; 1] so we need to move it to range [0; 1] + // When mNumCollectedProbes = 3 + // mProbeBlendFactors[0] is in range [0.333; 1] so we need to move it to range [0; 1] + // When mNumCollectedProbes = 4 + // mProbeBlendFactors[0] is in range [0.25; 1] so we need to move it to range [0; 1] finalPos = Math::lerp( mTrackedPosition, finalPos, - mProbeBlendFactors[0] * mNumCollectedProbes - Real(1.0) ); + mProbeBlendFactors[0] * mNumCollectedProbes - Real( 1.0 ) ); } - //TODO: restrict mTrackedPosition to a region between the 4 probes. + // TODO: restrict mTrackedPosition to a region between the 4 probes. const Quaternion qRot( mCollectedProbes[0]->mOrientation ); mBlendProxyCamera->setPosition( finalPos ); - //mBlendProxyCamera->setPosition( mTrackedPosition ); + // mBlendProxyCamera->setPosition( mTrackedPosition ); mBlendProxyCamera->setOrientation( qRot ); - mBlendedProbeNeedsUpdate = !(prevNumCollectedProbes <= 1 && - mNumCollectedProbes <= 1 && - prevNumCollectedProbes == mNumCollectedProbes && - mCollectedProbes[0] == prevProbe ); + mBlendedProbeNeedsUpdate = + !( prevNumCollectedProbes <= 1 && mNumCollectedProbes <= 1 && + prevNumCollectedProbes == mNumCollectedProbes && mCollectedProbes[0] == prevProbe ); if( !mManuallyActiveProbes.empty() ) checkStagingBufferIsBigEnough(); @@ -907,27 +887,27 @@ namespace Ogre void ParallaxCorrectedCubemap::updateExpensiveCollectedDirtyProbes( uint16 iterationThreshold ) { RenderSystem *renderSystem = mSceneManager->getDestinationRenderSystem(); - //HlmsManager *hlmsManager = mRoot->getHlmsManager(); + // HlmsManager *hlmsManager = mRoot->getHlmsManager(); const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask(); mSceneManager->setVisibilityMask( 0xffffffff ); - for( size_t i=0; imDirty || !mCollectedProbes[i]->mStatic) && + if( ( mCollectedProbes[i]->mDirty || !mCollectedProbes[i]->mStatic ) && mCollectedProbes[i]->mNumIterations > iterationThreshold ) { setFinalProbeTo( i ); - for( int j=0; jmNumIterations; ++j ) + for( int j = 0; j < mCollectedProbes[i]->mNumIterations; ++j ) { renderSystem->_beginFrameOnce(); mCopyWorkspace->_beginUpdate( true ); - if( j == 0 ) - mCollectedProbes[i]->_clearCubemap(); - mCopyWorkspace->_update(); - transitionBlendResultToTexture(); - mCollectedProbes[i]->_updateRender(); + if( j == 0 ) + mCollectedProbes[i]->_clearCubemap(); + mCopyWorkspace->_update(); + transitionBlendResultToTexture(); + mCollectedProbes[i]->_updateRender(); mCopyWorkspace->_endUpdate( true ); renderSystem->_update(); @@ -951,7 +931,7 @@ namespace Ogre const uint32 oldVisibilityMask = mSceneManager->getVisibilityMask(); mSceneManager->setVisibilityMask( 0xffffffff ); - for( size_t i=0; imDirty || !mCollectedProbes[i]->mStatic ) { @@ -959,7 +939,7 @@ namespace Ogre mCollectedProbes[i]->_clearCubemap(); - for( int j=0; jmNumIterations; ++j ) + for( int j = 0; j < mCollectedProbes[i]->mNumIterations; ++j ) { mCopyWorkspace->_update(); transitionBlendResultToTexture(); @@ -976,34 +956,32 @@ namespace Ogre setFinalProbeTo( 0 ); - for( size_t i=1; imProbeShape ); - Vector3 newMin = Math::lerp( mFinalProbe.mProbeShape.getMinimum(), - mergedProbe.getMinimum(), + Vector3 newMin = Math::lerp( mFinalProbe.mProbeShape.getMinimum(), mergedProbe.getMinimum(), weight * weight * weight ); - Vector3 newMax = Math::lerp( mFinalProbe.mProbeShape.getMaximum(), - mergedProbe.getMaximum(), + Vector3 newMax = Math::lerp( mFinalProbe.mProbeShape.getMaximum(), mergedProbe.getMaximum(), weight * weight * weight ); mFinalProbe.mProbeShape.setExtents( newMin, newMax ); } - //Warning to other devs: Don't mess with mFinalProbe.mProbeCameraPos here. - //Change mBlendProxyCamera->setPosition instead in updateSceneGraph. + // Warning to other devs: Don't mess with mFinalProbe.mProbeCameraPos here. + // Change mBlendProxyCamera->setPosition instead in updateSceneGraph. mFinalProbe.mProbeCameraPos = mBlendProxyCamera->getPosition(); if( mBlendedProbeNeedsUpdate ) @@ -1055,15 +1033,15 @@ namespace Ogre const uint32 systemMask = mMask; CubemapProbeVec::const_iterator itor = mProbes.begin(); - CubemapProbeVec::const_iterator end = mProbes.end(); + CubemapProbeVec::const_iterator end = mProbes.end(); while( itor != end ) { - if( (*itor)->mEnabled && ((*itor)->mMask & systemMask) ) + if( ( *itor )->mEnabled && ( ( *itor )->mMask & systemMask ) ) { - mTrackedPosition = (*itor)->mProbeCameraPos; + mTrackedPosition = ( *itor )->mProbeCameraPos; this->updateSceneGraph(); - for( size_t i=0; i_getFullTransformUpdated(); this->updateExpensiveCollectedDirtyProbes( 0 ); } @@ -1072,7 +1050,7 @@ namespace Ogre mSceneManager->clearFrameData(); - //Set to 0 so next time mBlendedProbeNeedsUpdate will be set to true correctly; + // Set to 0 so next time mBlendedProbeNeedsUpdate will be set to true correctly; mNumCollectedProbes = 0; } //----------------------------------------------------------------------------------- @@ -1088,21 +1066,20 @@ namespace Ogre StagingBuffer::DestinationVec destinations; - float * RESTRICT_ALIAS probeData = static_cast( - mStagingBuffer->map( neededBytes ) ); + float *RESTRICT_ALIAS probeData = + static_cast( mStagingBuffer->map( neededBytes ) ); size_t srcOffset = 0; CubemapProbeVec::const_iterator itor = mManuallyActiveProbes.begin(); - CubemapProbeVec::const_iterator end = mManuallyActiveProbes.end(); + CubemapProbeVec::const_iterator end = mManuallyActiveProbes.end(); while( itor != end ) { - destinations.push_back( StagingBuffer::Destination( (*itor)->mConstBufferForManualProbes, - 0, srcOffset, - getConstBufferSize() ) ); + destinations.push_back( StagingBuffer::Destination( + ( *itor )->mConstBufferForManualProbes, 0, srcOffset, getConstBufferSize() ) ); - ParallaxCorrectedCubemapBase:: - fillConstBufferData( **itor, viewMatrix, invViewMat3, probeData ); + ParallaxCorrectedCubemapBase::fillConstBufferData( **itor, viewMatrix, invViewMat3, + probeData ); probeData += getConstBufferSize() >> 2u; srcOffset += getConstBufferSize(); @@ -1116,24 +1093,21 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - size_t ParallaxCorrectedCubemap::getConstBufferSize() - { - return getConstBufferSizeStatic(); - } + size_t ParallaxCorrectedCubemap::getConstBufferSize() { return getConstBufferSizeStatic(); } //----------------------------------------------------------------------------------- size_t ParallaxCorrectedCubemap::getConstBufferSizeStatic() { - return 6u * 4u * sizeof(float); //CubemapProbe localProbe; + return 6u * 4u * sizeof( float ); // CubemapProbe localProbe; } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::fillConstBufferData( const Matrix4 &viewMatrix, - float * RESTRICT_ALIAS passBufferPtr ) const + float *RESTRICT_ALIAS passBufferPtr ) const { Matrix3 invViewMat3; viewMatrix.extract3x3Matrix( invViewMat3 ); invViewMat3 = invViewMat3.Inverse(); - ParallaxCorrectedCubemapBase:: - fillConstBufferData( mFinalProbe, viewMatrix, invViewMat3, passBufferPtr ); + ParallaxCorrectedCubemapBase::fillConstBufferData( mFinalProbe, viewMatrix, invViewMat3, + passBufferPtr ); } //----------------------------------------------------------------------------------- TextureGpu *ParallaxCorrectedCubemap::findRtt( const TextureGpu *baseParams, TempRttVec &container, @@ -1175,7 +1149,7 @@ namespace Ogre retVal->setPixelFormat( baseParams->getPixelFormat() ); retVal->setNumMipmaps( numMipmaps ); retVal->setSampleDescription( baseParams->getSampleDescription() ); - retVal->_transitionTo( GpuResidency::Resident, (uint8*)0 ); + retVal->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); tmpRtt.texture = retVal; tmpRtt.refCount = 1; @@ -1188,7 +1162,7 @@ namespace Ogre void ParallaxCorrectedCubemap::releaseRtt( const TextureGpu *rtt, TempRttVec &container ) { TempRttVec::iterator itor = container.begin(); - TempRttVec::iterator end = container.end(); + TempRttVec::iterator end = container.end(); while( itor != end && itor->texture != rtt ) ++itor; @@ -1199,14 +1173,14 @@ namespace Ogre if( !itor->refCount ) { TextureGpuManager *textureGpuManager = - mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); textureGpuManager->destroyTexture( itor->texture ); efficientVectorRemove( container, itor ); } } } //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemap::findTmpRtt( const TextureGpu *baseParams ) + TextureGpu *ParallaxCorrectedCubemap::findTmpRtt( const TextureGpu *baseParams ) { return findRtt( baseParams, mTmpRtt, TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps, true ); @@ -1217,7 +1191,7 @@ namespace Ogre releaseRtt( tmpRtt, mTmpRtt ); } //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemap::findIbl( const TextureGpu *baseParams ) + TextureGpu *ParallaxCorrectedCubemap::findIbl( const TextureGpu *baseParams ) { return findRtt( baseParams, mIblRtt, getIblTargetTextureFlags( baseParams->getPixelFormat() ), false ); @@ -1235,8 +1209,8 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemap::_removeManuallyActiveProbe( CubemapProbe *probe ) { - CubemapProbeVec::iterator itor = std::find( mManuallyActiveProbes.begin(), - mManuallyActiveProbes.end(), probe ); + CubemapProbeVec::iterator itor = + std::find( mManuallyActiveProbes.begin(), mManuallyActiveProbes.end(), probe ); if( itor != mManuallyActiveProbes.end() ) efficientVectorRemove( mManuallyActiveProbes, itor ); @@ -1252,7 +1226,7 @@ namespace Ogre { if( pass->getType() == PASS_SCENE && pass->getDefinition()->mIdentifier == 10u ) { - for( size_t i=0; imTexture->getNumMipmaps() ) / mBindTexture->getNumMipmaps(); @@ -1263,8 +1237,8 @@ namespace Ogre else if( pass->getType() == PASS_QUAD && pass->getDefinition()->mIdentifier == 10u ) { const float mipLevel = ( mCurrentMip * mCollectedProbes[0]->mTexture->getNumMipmaps() ) / - mBindTexture->getNumMipmaps(); - for( size_t i=0; i<6; ++i ) + mBindTexture->getNumMipmaps(); + for( size_t i = 0; i < 6; ++i ) mCopyCubemapParams[i]->setNamedConstant( "lodLevel", mipLevel ); ++mCurrentMip; } @@ -1274,7 +1248,7 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - bool ParallaxCorrectedCubemap::frameStarted( const FrameEvent& evt ) + bool ParallaxCorrectedCubemap::frameStarted( const FrameEvent &evt ) { if( !mPaused ) this->updateSceneGraph(); @@ -1292,4 +1266,4 @@ namespace Ogre if( !mPaused ) this->updateRender(); } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapAuto.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapAuto.cpp index 4fcf8590f88..228e262e9da 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapAuto.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapAuto.cpp @@ -31,30 +31,30 @@ THE SOFTWARE. #include "Cubemaps/OgreParallaxCorrectedCubemapAuto.h" #include "Compositor/OgreCompositorManager2.h" -#include "Compositor/OgreCompositorWorkspaceDef.h" -#include "Compositor/OgreCompositorWorkspace.h" #include "Compositor/OgreCompositorNodeDef.h" -#include "Compositor/Pass/PassQuad/OgreCompositorPassQuadDef.h" +#include "Compositor/OgreCompositorWorkspace.h" +#include "Compositor/OgreCompositorWorkspaceDef.h" #include "Compositor/Pass/PassQuad/OgreCompositorPassQuad.h" -#include "OgreHlmsPbs.h" +#include "Compositor/Pass/PassQuad/OgreCompositorPassQuadDef.h" #include "OgreBitwise.h" -#include "OgreRoot.h" #include "OgreCamera.h" -#include "OgreSceneManager.h" -#include "OgreTextureGpuManager.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreHlmsManager.h" -#include "OgreHlms.h" #include "OgreDepthBuffer.h" -#include "OgreTextureBox.h" -#include "OgreMaterialManager.h" -#include "OgreTechnique.h" +#include "OgreHlms.h" +#include "OgreHlmsManager.h" +#include "OgreHlmsPbs.h" +#include "OgreInternalCubemapProbe.h" +#include "OgreItem.h" #include "OgreLwString.h" -#include "OgreMeshManager2.h" +#include "OgreMaterialManager.h" #include "OgreMesh2.h" +#include "OgreMeshManager2.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreRoot.h" +#include "OgreSceneManager.h" #include "OgreSubMesh2.h" -#include "OgreItem.h" -#include "OgreInternalCubemapProbe.h" +#include "OgreTechnique.h" +#include "OgreTextureBox.h" +#include "OgreTextureGpuManager.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreStagingBuffer.h" @@ -72,8 +72,8 @@ namespace Ogre //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- ParallaxCorrectedCubemapAuto::ParallaxCorrectedCubemapAuto( - IdType id, Root *root, SceneManager *sceneManager, - const CompositorWorkspaceDef *probeWorkspcDef ) : + IdType id, Root *root, SceneManager *sceneManager, + const CompositorWorkspaceDef *probeWorkspcDef ) : ParallaxCorrectedCubemapBase( id, root, sceneManager, probeWorkspcDef, true ), mTrackedPosition( Vector3::ZERO ), mRenderTarget( 0 ), @@ -81,7 +81,7 @@ namespace Ogre mListener( 0 ) { const RenderSystemCapabilities *caps = - mSceneManager->getDestinationRenderSystem()->getCapabilities(); + mSceneManager->getDestinationRenderSystem()->getCapabilities(); mUseDpm2DArray = !caps->hasCapability( RSC_TEXTURE_CUBE_MAP_ARRAY ); } //----------------------------------------------------------------------------------- @@ -107,12 +107,12 @@ namespace Ogre mTrackedPosition = trackedCamera->getDerivedPosition(); } //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemapAuto::_acquireTextureSlot( uint16 &outTexSlot ) + TextureGpu *ParallaxCorrectedCubemapAuto::_acquireTextureSlot( uint16 &outTexSlot ) { OGRE_ASSERT_LOW( mBindTexture && "Must call ParallaxCorrectedCubemapAuto::setEnabled first!" ); vector::type::iterator itor = mReservedSlotBitset.begin(); - vector::type::iterator end = mReservedSlotBitset.end(); + vector::type::iterator end = mReservedSlotBitset.end(); TextureGpu *retVal = 0; uint32 firstBitSet = 64u; @@ -124,7 +124,7 @@ namespace Ogre uint32 idx = static_cast( itor - mReservedSlotBitset.begin() ); outTexSlot = static_cast( firstBitSet + 64u * idx ); retVal = mBindTexture; - *itor &= ~(((uint64)1ul) << firstBitSet); + *itor &= ~( ( (uint64)1ul ) << firstBitSet ); } ++itor; } @@ -136,16 +136,16 @@ namespace Ogre { OGRE_ASSERT_LOW( texture == mBindTexture ); - size_t idx = texSlot / 64u; + size_t idx = texSlot / 64u; uint64 mask = texSlot % 64u; - mask = ((uint64)1ul) << mask; + mask = ( (uint64)1ul ) << mask; OGRE_ASSERT_LOW( idx < mReservedSlotBitset.size() && "Slot is invalid. Out of bounds!" ); - OGRE_ASSERT_LOW( !(mReservedSlotBitset[idx] & mask) && "Slot was already released!" ); + OGRE_ASSERT_LOW( !( mReservedSlotBitset[idx] & mask ) && "Slot was already released!" ); mReservedSlotBitset[idx] |= mask; } //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemapAuto::findTmpRtt( const TextureGpu *baseParams ) + TextureGpu *ParallaxCorrectedCubemapAuto::findTmpRtt( const TextureGpu *baseParams ) { OGRE_ASSERT_LOW( mRenderTarget && "Must call ParallaxCorrectedCubemapAuto::setEnabled first!" ); return mRenderTarget; @@ -183,12 +183,12 @@ namespace Ogre cubemapArrayIdx *= 6u; const uint8 numMipmaps = ibl->getNumMipmaps(); - for( uint8 mip=0; mipgetEmptyBox( mip ); TextureBox dstBox = srcBox; srcBox.sliceStart = 0; @@ -197,33 +197,28 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - void ParallaxCorrectedCubemapAuto::setEnabled( bool bEnabled, uint32 width, - uint32 height, uint32 maxNumProbes, - PixelFormatGpu pixelFormat ) + void ParallaxCorrectedCubemapAuto::setEnabled( bool bEnabled, uint32 width, uint32 height, + uint32 maxNumProbes, PixelFormatGpu pixelFormat ) { if( bEnabled == getEnabled() ) return; TextureGpuManager *textureGpuManager = - mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); + mSceneManager->getDestinationRenderSystem()->getTextureGpuManager(); if( bEnabled ) { uint32 textureFlags = TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps | TextureFlags::DiscardableContent; - //Create Cubemap - mRenderTarget = - textureGpuManager->createTexture( - "ParallaxCorrectedCubemapAuto Target " + - StringConverter::toString( getId() ), - GpuPageOutStrategy::Discard, - textureFlags, - TextureTypes::TypeCube ); + // Create Cubemap + mRenderTarget = textureGpuManager->createTexture( + "ParallaxCorrectedCubemapAuto Target " + StringConverter::toString( getId() ), + GpuPageOutStrategy::Discard, textureFlags, TextureTypes::TypeCube ); mRenderTarget->setResolution( width, height ); mRenderTarget->setPixelFormat( pixelFormat ); mRenderTarget->setNumMipmaps( PixelFormatGpuUtils::getMaxMipmapCount( width, height ) ); - mRenderTarget->_transitionTo( GpuResidency::Resident, (uint8*)0 ); + mRenderTarget->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); const uint8 numMipmaps = getIblNumMipmaps( width, height ); @@ -259,13 +254,9 @@ namespace Ogre if( !mUseDpm2DArray ) numSlices *= 6u; - mBindTexture = - textureGpuManager->createTexture( - "ParallaxCorrectedCubemapAuto Array " + - StringConverter::toString( getId() ), - GpuPageOutStrategy::Discard, - TextureFlags::ManualTexture, - bindTextureType ); + mBindTexture = textureGpuManager->createTexture( + "ParallaxCorrectedCubemapAuto Array " + StringConverter::toString( getId() ), + GpuPageOutStrategy::Discard, TextureFlags::ManualTexture, bindTextureType ); mBindTexture->setResolution( mIblTarget->getWidth(), mIblTarget->getHeight(), numSlices ); mBindTexture->setPixelFormat( pixelFormat ); mBindTexture->setNumMipmaps( numMipmaps ); @@ -275,7 +266,7 @@ namespace Ogre mReservedSlotBitset.resize( alignToNextMultiple( maxNumProbes, 64u ) >> 6u, 0xffffffffffffffff ); if( remainder != 0u ) - mReservedSlotBitset.back() = ((uint64_t)1u << remainder) - 1u; + mReservedSlotBitset.back() = ( (uint64_t)1u << remainder ) - 1u; mRoot->addFrameListener( this ); CompositorManager2 *compositorManager = mDefaultWorkspaceDef->getCompositorManager(); @@ -285,16 +276,6 @@ namespace Ogre OGRE_ASSERT_HIGH( dynamic_cast( hlmsManager->getHlms( HLMS_PBS ) ) ); HlmsPbs *hlmsPbs = static_cast( hlmsManager->getHlms( HLMS_PBS ) ); hlmsPbs->_notifyIblSpecMipmap( mBindTexture->getNumMipmaps() ); - -// CubemapProbeVec::const_iterator itor = mProbes.begin(); -// CubemapProbeVec::const_iterator end = mProbes.end(); - -// while( itor != end ) -// { -// if( (*itor)->isInitialized() ) -// (*itor)->initWorkspace(); -// ++itor; -// } } else { @@ -304,11 +285,11 @@ namespace Ogre mRoot->removeFrameListener( this ); CubemapProbeVec::const_iterator itor = mProbes.begin(); - CubemapProbeVec::const_iterator end = mProbes.end(); + CubemapProbeVec::const_iterator end = mProbes.end(); while( itor != end ) { - (*itor)->destroyWorkspace(); + ( *itor )->destroyWorkspace(); ++itor; } @@ -332,17 +313,14 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - bool ParallaxCorrectedCubemapAuto::getEnabled() const - { - return mRenderTarget != 0; - } + bool ParallaxCorrectedCubemapAuto::getEnabled() const { return mRenderTarget != 0; } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapAuto::setUseDpm2DArray( bool useDpm2DArray ) { OGRE_ASSERT_LOW( !getEnabled() ); mUseDpm2DArray = useDpm2DArray; const RenderSystemCapabilities *caps = - mSceneManager->getDestinationRenderSystem()->getCapabilities(); + mSceneManager->getDestinationRenderSystem()->getCapabilities(); if( !caps->hasCapability( RSC_TEXTURE_CUBE_MAP_ARRAY ) ) mUseDpm2DArray = true; } @@ -354,17 +332,16 @@ namespace Ogre const uint32 systemMask = mMask; CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); while( itor != end ) { CubemapProbe *probe = *itor; - const Vector3 posLS = probe->mInvOrientation * (mTrackedPosition - probe->mArea.mCenter); + const Vector3 posLS = probe->mInvOrientation * ( mTrackedPosition - probe->mArea.mCenter ); const Aabb areaLS = probe->getAreaLS(); - if( ((areaLS.contains( posLS ) && !probe->mStatic) || probe->mDirty) && - probe->mEnabled && probe->mTexture && - (probe->mMask & systemMask) ) + if( ( ( areaLS.contains( posLS ) && !probe->mStatic ) || probe->mDirty ) && + probe->mEnabled && probe->mTexture && ( probe->mMask & systemMask ) ) { mDirtyProbes.push_back( probe ); } @@ -372,18 +349,18 @@ namespace Ogre if( probe->mInternalProbe ) { probe->mInternalProbe->setVisible( probe->mEnabled && probe->mTexture && - (probe->mMask & systemMask) != 0u ); + ( probe->mMask & systemMask ) != 0u ); } ++itor; } itor = mDirtyProbes.begin(); - end = mDirtyProbes.end(); + end = mDirtyProbes.end(); while( itor != end ) { - (*itor)->_prepareForRendering(); + ( *itor )->_prepareForRendering(); ++itor; } } @@ -396,7 +373,7 @@ namespace Ogre mSceneManager->setVisibilityMask( 0xffffffff ); CubemapProbeVec::iterator itor = mDirtyProbes.begin(); - CubemapProbeVec::iterator end = mDirtyProbes.end(); + CubemapProbeVec::iterator end = mDirtyProbes.end(); while( itor != end ) { @@ -414,9 +391,9 @@ namespace Ogre if( iterationThreshold > 0u ) { - //We have to remove only those that are no longer dirty + // We have to remove only those that are no longer dirty itor = efficientVectorRemove( mDirtyProbes, itor ); - end = mDirtyProbes.end(); + end = mDirtyProbes.end(); } else ++itor; @@ -427,8 +404,8 @@ namespace Ogre } } - //When iterationThreshold == 0; we're updating every probe, - //thus just clear them all at once + // When iterationThreshold == 0; we're updating every probe, + // thus just clear them all at once if( iterationThreshold == 0u ) mDirtyProbes.clear(); @@ -441,7 +418,7 @@ namespace Ogre mSceneManager->setVisibilityMask( 0xffffffff ); CubemapProbeVec::iterator itor = mDirtyProbes.begin(); - CubemapProbeVec::iterator end = mDirtyProbes.end(); + CubemapProbeVec::iterator end = mDirtyProbes.end(); while( itor != end ) { @@ -463,7 +440,7 @@ namespace Ogre mDirtyProbes.clear(); CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); while( itor != end ) { @@ -474,11 +451,11 @@ namespace Ogre } itor = mDirtyProbes.begin(); - end = mDirtyProbes.end(); + end = mDirtyProbes.end(); while( itor != end ) { - (*itor)->_prepareForRendering(); + ( *itor )->_prepareForRendering(); ++itor; } @@ -487,7 +464,7 @@ namespace Ogre mSceneManager->clearFrameData(); } //----------------------------------------------------------------------------------- - bool ParallaxCorrectedCubemapAuto::frameStarted( const FrameEvent& evt ) + bool ParallaxCorrectedCubemapAuto::frameStarted( const FrameEvent &evt ) { if( !mPaused ) this->updateSceneGraph(); @@ -508,21 +485,21 @@ namespace Ogre //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapAuto::passPreExecute( CompositorPass *pass ) { - //This is not really needed because we only copy LOD 0 then auto generate the mipmaps. - //However we left this code just in case we need to copy multiple LODs later again. + // This is not really needed because we only copy LOD 0 then auto generate the mipmaps. + // However we left this code just in case we need to copy multiple LODs later again. if( pass->getType() == PASS_QUAD && pass->getDefinition()->mIdentifier == c_cubmapToDpmIdentifier ) { - OGRE_ASSERT_HIGH( dynamic_cast( pass ) ); - CompositorPassQuad *passQuad = static_cast( pass ); + OGRE_ASSERT_HIGH( dynamic_cast( pass ) ); + CompositorPassQuad *passQuad = static_cast( pass ); Pass *matPass = passQuad->getPass(); GpuProgramParametersSharedPtr psParams = matPass->getFragmentProgramParameters(); - psParams->setNamedConstant( "lodLevel", static_cast( - pass->getRenderPassDesc()->mColour[0].mipLevel ) ); + psParams->setNamedConstant( + "lodLevel", static_cast( pass->getRenderPassDesc()->mColour[0].mipLevel ) ); } else { ParallaxCorrectedCubemapBase::passPreExecute( pass ); } } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapBase.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapBase.cpp index 6d5f14dc57a..8efb0b3dc46 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapBase.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgreParallaxCorrectedCubemapBase.cpp @@ -31,31 +31,31 @@ THE SOFTWARE. #include "Cubemaps/OgreParallaxCorrectedCubemapBase.h" #include "Compositor/OgreCompositorManager2.h" -#include "Compositor/OgreCompositorWorkspaceDef.h" -#include "Compositor/OgreCompositorWorkspace.h" #include "Compositor/OgreCompositorNodeDef.h" +#include "Compositor/OgreCompositorWorkspace.h" +#include "Compositor/OgreCompositorWorkspaceDef.h" #include "Compositor/Pass/PassClear/OgreCompositorPassClearDef.h" #include "Compositor/Pass/PassQuad/OgreCompositorPassQuad.h" #include "Compositor/Pass/PassQuad/OgreCompositorPassQuadDef.h" #include "Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h" -#include "OgreRoot.h" #include "OgreCamera.h" +#include "OgreDepthBuffer.h" +#include "OgreHlms.h" +#include "OgreHlmsManager.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreRoot.h" #include "OgreSceneManager.h" #include "OgreTextureGpuManager.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreHlmsManager.h" -#include "OgreHlms.h" -#include "OgreDepthBuffer.h" +#include "OgreLwString.h" #include "OgreMaterialManager.h" #include "OgreTechnique.h" -#include "OgreLwString.h" -#include "OgreMeshManager2.h" +#include "OgreItem.h" #include "OgreMesh2.h" +#include "OgreMeshManager2.h" #include "OgreSubMesh2.h" -#include "OgreItem.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreStagingBuffer.h" @@ -63,8 +63,8 @@ THE SOFTWARE. namespace Ogre { ParallaxCorrectedCubemapBase::ParallaxCorrectedCubemapBase( - IdType id, Root *root, SceneManager *sceneManager, - const CompositorWorkspaceDef *probeWorkspcDef, bool automaticMode ) : + IdType id, Root *root, SceneManager *sceneManager, const CompositorWorkspaceDef *probeWorkspcDef, + bool automaticMode ) : IdObject( id ), mBindTexture( 0 ), mSamplerblockTrilinear( 0 ), @@ -84,9 +84,8 @@ namespace Ogre samplerblock.mMipFilter = FO_LINEAR; mSamplerblockTrilinear = hlmsManager->getSamplerblock( samplerblock ); - MaterialPtr depthCompressor = - MaterialManager::getSingleton().getByName( - "PCC/DepthCompressor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); + MaterialPtr depthCompressor = MaterialManager::getSingleton().getByName( + "PCC/DepthCompressor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); if( depthCompressor ) { depthCompressor->load(); @@ -110,13 +109,13 @@ namespace Ogre void ParallaxCorrectedCubemapBase::_releaseManualHardwareResources() { for( CubemapProbeVec::iterator it = mProbes.begin(), end = mProbes.end(); it != end; ++it ) - (*it)->_releaseManualHardwareResources(); + ( *it )->_releaseManualHardwareResources(); } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapBase::_restoreManualHardwareResources() { for( CubemapProbeVec::iterator it = mProbes.begin(), end = mProbes.end(); it != end; ++it ) - (*it)->_restoreManualHardwareResources(); + ( *it )->_restoreManualHardwareResources(); updateAllDirtyProbes(); } @@ -146,7 +145,7 @@ namespace Ogre return numMipmaps; } //----------------------------------------------------------------------------------- - CubemapProbe* ParallaxCorrectedCubemapBase::createProbe() + CubemapProbe *ParallaxCorrectedCubemapBase::createProbe() { CubemapProbe *probe = OGRE_NEW CubemapProbe( this ); mProbes.push_back( probe ); @@ -170,7 +169,7 @@ namespace Ogre void ParallaxCorrectedCubemapBase::destroyAllProbes() { CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); while( itor != end ) { @@ -181,79 +180,72 @@ namespace Ogre mProbes.clear(); } //----------------------------------------------------------------------------------- - void ParallaxCorrectedCubemapBase::prepareForClearScene() - { - } + void ParallaxCorrectedCubemapBase::prepareForClearScene() {} //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapBase::restoreFromClearScene() { SceneNode *rootNode = mSceneManager->getRootSceneNode(); CubemapProbeVec::iterator itor = mProbes.begin(); - CubemapProbeVec::iterator end = mProbes.end(); + CubemapProbeVec::iterator end = mProbes.end(); while( itor != end ) { - (*itor)->restoreFromClearScene( rootNode ); + ( *itor )->restoreFromClearScene( rootNode ); ++itor; } } //----------------------------------------------------------------------------------- - void ParallaxCorrectedCubemapBase::_notifyPreparePassHash( const Matrix4 &viewMatrix ) - { - } + void ParallaxCorrectedCubemapBase::_notifyPreparePassHash( const Matrix4 &viewMatrix ) {} //----------------------------------------------------------------------------------- - size_t ParallaxCorrectedCubemapBase::getConstBufferSize() - { - return 0; - } + size_t ParallaxCorrectedCubemapBase::getConstBufferSize() { return 0; } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapBase::fillConstBufferData( const Matrix4 &viewMatrix, - float * RESTRICT_ALIAS passBufferPtr ) const + float *RESTRICT_ALIAS passBufferPtr ) const { } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapBase::fillConstBufferData( const CubemapProbe &probe, const Matrix4 &viewMatrix, const Matrix3 &invViewMat3, - float * RESTRICT_ALIAS passBufferPtr ) + float *RESTRICT_ALIAS passBufferPtr ) { const Matrix3 viewSpaceToProbeLocal = probe.mInvOrientation * invViewMat3; const Aabb &probeShape = probe.getProbeShape(); - Vector3 probeShapeCenterVS = viewMatrix * probeShape.mCenter; //View-space + Vector3 probeShapeCenterVS = viewMatrix * probeShape.mCenter; // View-space - //float4 row0_centerX; + // float4 row0_centerX; *passBufferPtr++ = viewSpaceToProbeLocal[0][0]; *passBufferPtr++ = viewSpaceToProbeLocal[0][1]; *passBufferPtr++ = viewSpaceToProbeLocal[0][2]; *passBufferPtr++ = probeShapeCenterVS.x; - //float4 row1_centerY; + // float4 row1_centerY; *passBufferPtr++ = viewSpaceToProbeLocal[0][3]; *passBufferPtr++ = viewSpaceToProbeLocal[0][4]; *passBufferPtr++ = viewSpaceToProbeLocal[0][5]; *passBufferPtr++ = probeShapeCenterVS.y; - //float4 row2_centerZ; + // float4 row2_centerZ; *passBufferPtr++ = viewSpaceToProbeLocal[0][6]; *passBufferPtr++ = viewSpaceToProbeLocal[0][7]; *passBufferPtr++ = viewSpaceToProbeLocal[0][8]; *passBufferPtr++ = probeShapeCenterVS.z; - //float4 halfSize; + // float4 halfSize; *passBufferPtr++ = probeShape.mHalfSize.x; *passBufferPtr++ = probeShape.mHalfSize.y; *passBufferPtr++ = probeShape.mHalfSize.z; *passBufferPtr++ = 1.0f; - //float4 cubemapPosLS; - const Vector3 cubemapPos = probe.mProbeCameraPos - probeShape.mCenter; - const Vector3 cubemapPosLS = probe.mInvOrientation * cubemapPos; + // float4 cubemapPosLS; + const Vector3 cubemapPos = probe.mProbeCameraPos - probeShape.mCenter; + const Vector3 cubemapPosLS = probe.mInvOrientation * cubemapPos; *passBufferPtr++ = cubemapPosLS.x; *passBufferPtr++ = cubemapPosLS.y; *passBufferPtr++ = cubemapPosLS.z; *passBufferPtr++ = 1.0f; - //float4 cubemapPosVS; + // float4 cubemapPosVS; const Vector3 cubemapPosVS = viewMatrix * cubemapPos; *passBufferPtr++ = cubemapPosVS.x; *passBufferPtr++ = cubemapPosVS.y; @@ -261,7 +253,7 @@ namespace Ogre *passBufferPtr++ = 1.0f; } //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemapBase::findTmpRtt( const TextureGpu *baseParams ) + TextureGpu *ParallaxCorrectedCubemapBase::findTmpRtt( const TextureGpu *baseParams ) { OGRE_EXCEPT( Exception::ERR_INVALID_CALL, "", "" ); return 0; @@ -282,11 +274,9 @@ namespace Ogre OGRE_EXCEPT( Exception::ERR_INVALID_CALL, "", "" ); } //----------------------------------------------------------------------------------- - void ParallaxCorrectedCubemapBase::_copyRenderTargetToCubemap( uint32 cubemapArrayIdx ) - { - } + void ParallaxCorrectedCubemapBase::_copyRenderTargetToCubemap( uint32 cubemapArrayIdx ) {} //----------------------------------------------------------------------------------- - TextureGpu* ParallaxCorrectedCubemapBase::_acquireTextureSlot( uint16 &outTexSlot ) + TextureGpu *ParallaxCorrectedCubemapBase::_acquireTextureSlot( uint16 &outTexSlot ) { OGRE_EXCEPT( Exception::ERR_INVALID_CALL, "", "" ); outTexSlot = 0; @@ -308,12 +298,9 @@ namespace Ogre OGRE_EXCEPT( Exception::ERR_INVALID_CALL, "", "" ); } //----------------------------------------------------------------------------------- - SceneManager* ParallaxCorrectedCubemapBase::getSceneManager() const - { - return mSceneManager; - } + SceneManager *ParallaxCorrectedCubemapBase::getSceneManager() const { return mSceneManager; } //----------------------------------------------------------------------------------- - const CompositorWorkspaceDef* ParallaxCorrectedCubemapBase::getDefaultWorkspaceDef() const + const CompositorWorkspaceDef *ParallaxCorrectedCubemapBase::getDefaultWorkspaceDef() const { return mDefaultWorkspaceDef; } @@ -324,15 +311,15 @@ namespace Ogre if( passDef->getType() != PASS_QUAD ) return; - OGRE_ASSERT_HIGH( dynamic_cast( pass ) ); - CompositorPassQuad *passQuad = static_cast( pass ); + OGRE_ASSERT_HIGH( dynamic_cast( pass ) ); + CompositorPassQuad *passQuad = static_cast( pass ); if( passQuad->getPass() == mPccCompressorPass ) { GpuProgramParametersSharedPtr psParams = mPccCompressorPass->getFragmentProgramParameters(); Ogre::Camera *camera = passQuad->getCamera(); Ogre::Vector2 projectionAB = camera->getProjectionParamsAB(); - //The division will keep "linearDepth" in the shader in the [0; 1] range. + // The division will keep "linearDepth" in the shader in the [0; 1] range. projectionAB.y /= camera->getFarClipDistance(); psParams->setNamedConstant( "projectionParams", projectionAB ); @@ -355,11 +342,11 @@ namespace Ogre } //----------------------------------------------------------------------------------- void ParallaxCorrectedCubemapBase::eventOccurred( const String &eventName, - const NameValuePairList *parameters ) + const NameValuePairList *parameters ) { if( eventName == "DeviceLost" ) _releaseManualHardwareResources(); else if( eventName == "DeviceRestored" ) _restoreManualHardwareResources(); } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Cubemaps/OgrePccPerPixelGridPlacement.cpp b/Components/Hlms/Pbs/src/Cubemaps/OgrePccPerPixelGridPlacement.cpp index 0129d468a01..95e2be6f89b 100644 --- a/Components/Hlms/Pbs/src/Cubemaps/OgrePccPerPixelGridPlacement.cpp +++ b/Components/Hlms/Pbs/src/Cubemaps/OgrePccPerPixelGridPlacement.cpp @@ -374,7 +374,6 @@ namespace Ogre void PccPerPixelGridPlacement::preCopyRenderTargetToCubemap( TextureGpu *renderTarget, uint32 cubemapArrayIdx ) { - TextureGpuManager *textureManager = renderTarget->getTextureManager(); AsyncTextureTicket *asyncTicket = textureManager->createAsyncTextureTicket( diff --git a/Components/Hlms/Pbs/src/InstantRadiosity/OgreInstantRadiosity.cpp b/Components/Hlms/Pbs/src/InstantRadiosity/OgreInstantRadiosity.cpp index 64f00d362ba..916dd640e73 100644 --- a/Components/Hlms/Pbs/src/InstantRadiosity/OgreInstantRadiosity.cpp +++ b/Components/Hlms/Pbs/src/InstantRadiosity/OgreInstantRadiosity.cpp @@ -29,88 +29,60 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "InstantRadiosity/OgreInstantRadiosity.h" -#include "OgreIrradianceVolume.h" -#include "OgreHlmsPbsDatablock.h" -#include "OgreHlmsPbs.h" -#include "OgreHlmsManager.h" -#include "OgreRay.h" +#include "Math/Array/OgreBooleanMask.h" +#include "OgreBitwise.h" +#include "OgreHlmsManager.h" +#include "OgreHlmsPbs.h" +#include "OgreHlmsPbsDatablock.h" +#include "OgreImage2.h" +#include "OgreIrradianceVolume.h" +#include "OgreItem.h" #include "OgreLight.h" +#include "OgreLwString.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreRay.h" #include "OgreSceneManager.h" +#include "OgreTextureGpu.h" #include "Vao/OgreAsyncTicket.h" #include "Vao/OgreIndexBufferPacked.h" #include "Vao/OgreVertexArrayObject.h" -#include "Math/Array/OgreBooleanMask.h" - -#include "OgreItem.h" -#include "OgreLwString.h" - -#include "OgreBitwise.h" -#include "OgreTextureGpu.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreImage2.h" - -#if (OGRE_COMPILER == OGRE_COMPILER_MSVC ||\ - OGRE_PLATFORM == OGRE_PLATFORM_ANDROID ||\ - OGRE_PLATFORM == OGRE_PLATFORM_APPLE ||\ - OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ||\ - OGRE_PLATFORM == OGRE_PLATFORM_FREEBSD) - #include -#else - #include -#endif +#include namespace Ogre { class RandomNumberGenerator { -#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID ||\ - OGRE_PLATFORM == OGRE_PLATFORM_APPLE ||\ - OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ||\ - ( OGRE_COMPILER == OGRE_COMPILER_MSVC && OGRE_COMP_VER >= 1910 ) ||\ - OGRE_PLATFORM == OGRE_PLATFORM_FREEBSD - std::mt19937 mRng; -#else - std::tr1::mt19937 mRng; -#endif + std::mt19937 mRng; public: - uint32 rand() { return mRng(); } + uint32 rand() { return mRng(); } /// Returns value in range [0; 1] - Real saturatedRand() - { - return rand() / (Real)mRng.max(); - } + Real saturatedRand() { return rand() / (Real)mRng.max(); } /// Returns value in range [-1; 1] - Real boxRand() - { - return saturatedRand() * Real(2.0) - Real(1.0); - } + Real boxRand() { return saturatedRand() * Real( 2.0 ) - Real( 1.0 ); } - Real rangeRand( Real min, Real max ) - { - return saturatedRand() * (max - min) + min; - } + Real rangeRand( Real min, Real max ) { return saturatedRand() * ( max - min ) + min; } Vector3 getRandomDir() { - const Real theta= Real(2.0) * Math::PI * saturatedRand(); - const Real z = boxRand(); + const Real theta = Real( 2.0 ) * Math::PI * saturatedRand(); + const Real z = boxRand(); - const Real sharedTerm = Math::Sqrt( Real(1.0) - z * z ); + const Real sharedTerm = Math::Sqrt( Real( 1.0 ) - z * z ); Vector3 retVal; retVal.x = sharedTerm * Math::Cos( theta ); retVal.y = sharedTerm * Math::Sin( theta ); retVal.z = z; -// Vector3 retVal; -// retVal.x = boxRand(); -// retVal.y = boxRand(); -// retVal.z = boxRand(); -// retVal.normalise(); + // Vector3 retVal; + // retVal.x = boxRand(); + // retVal.y = boxRand(); + // retVal.z = boxRand(); + // retVal.normalise(); return retVal; } @@ -118,8 +90,8 @@ namespace Ogre /// Returns values in range [-1; 1] both XY, inside a circle of radius 1. Vector2 getRandomPointInCircle() { - const Real theta= Real(2.0) * Math::PI * saturatedRand(); - const Real r = saturatedRand(); + const Real theta = Real( 2.0 ) * Math::PI * saturatedRand(); + const Real r = saturatedRand(); const Real sqrtR = Math::Sqrt( r ); @@ -132,10 +104,10 @@ namespace Ogre Vector3 getRandomDirInRange( Radian angle ) { - const Real theta= Real(2.0) * Math::PI * saturatedRand(); - const Real z = rangeRand( Math::Cos( angle ), 1.0f ); + const Real theta = Real( 2.0 ) * Math::PI * saturatedRand(); + const Real z = rangeRand( Math::Cos( angle ), 1.0f ); - const Real sharedTerm = Math::Sqrt( Real(1.0) - z * z ); + const Real sharedTerm = Math::Sqrt( Real( 1.0 ) - z * z ); Vector3 retVal; retVal.x = sharedTerm * Math::Cos( theta ); @@ -165,14 +137,14 @@ namespace Ogre mLastRq( 255 ), mVisibilityMask( 0xffffffff ), mLightMask( 0xffffffff ), - //mNumRays( 10000 ), + // mNumRays( 10000 ), mNumRays( 128 ), mNumRayBounces( 1 ), mSurvivingRayFraction( 0.5f ), mCellSize( 3 ), mBias( 0.982f ), mNumSpreadIterations( 1 ), - mSpreadThreshold( 0.0004 ), + mSpreadThreshold( Real( 0.0004 ) ), mVplMaxRange( 8 ), mVplConstAtten( 0.5 ), mVplLinearAtten( 0.5 ), @@ -195,54 +167,53 @@ namespace Ogre clear(); } //----------------------------------------------------------------------------------- - bool InstantRadiosity::OrderRenderOperation::operator () ( const v1::RenderOperation &_l, - const v1::RenderOperation &_r ) const + bool InstantRadiosity::OrderRenderOperation::operator()( const v1::RenderOperation &_l, + const v1::RenderOperation &_r ) const { - return _l.vertexData < _r.vertexData && - _l.operationType < _r.operationType && - _l.useIndexes < _r.useIndexes && - _l.indexData < _r.indexData; + return _l.vertexData < _r.vertexData && _l.operationType < _r.operationType && + _l.useIndexes < _r.useIndexes && _l.indexData < _r.indexData; } //----------------------------------------------------------------------------------- - InstantRadiosity::Vpl InstantRadiosity::convertToVpl( Vector3 lightColour, - Vector3 pointOnTri, + InstantRadiosity::Vpl InstantRadiosity::convertToVpl( Vector3 lightColour, Vector3 pointOnTri, const RayHit &hit ) { - //const Real NdotL = hit.triNormal.dotProduct( -hit.rayDir ); + // const Real NdotL = hit.triNormal.dotProduct( -hit.rayDir ); - //materialDiffuse is already divided by PI + // materialDiffuse is already divided by PI Vector3 diffuseTerm = /*NdotL **/ hit.material.diffuse * lightColour; if( hit.material.needsUv ) { - const Real invTriArea = Real(1.0) / ( (hit.triVerts[0] - hit.triVerts[1]). - crossProduct( hit.triVerts[0] - hit.triVerts[2] ).length() ); + const Real invTriArea = + Real( 1.0 ) / ( ( hit.triVerts[0] - hit.triVerts[1] ) + .crossProduct( hit.triVerts[0] - hit.triVerts[2] ) + .length() ); - //Calculate barycentric coordinates (only works if point is inside tri) - //Calculate vectors from point to vertices p0, p1 and p2: + // Calculate barycentric coordinates (only works if point is inside tri) + // Calculate vectors from point to vertices p0, p1 and p2: const Vector3 f0 = hit.triVerts[0] - pointOnTri; const Vector3 f1 = hit.triVerts[1] - pointOnTri; const Vector3 f2 = hit.triVerts[2] - pointOnTri; - //Calculate the areas and factors (order of parameters doesn't matter): - //a0 = p0's triangle area / tri_area + // Calculate the areas and factors (order of parameters doesn't matter): + // a0 = p0's triangle area / tri_area const Real a0 = f1.crossProduct( f2 ).length() * invTriArea; const Real a1 = f2.crossProduct( f0 ).length() * invTriArea; const Real a2 = f0.crossProduct( f1 ).length() * invTriArea; - for( int i=0; i<5 && hit.material.image[i]; ++i ) + for( int i = 0; i < 5 && hit.material.image[i]; ++i ) { const uint8 uvSet = hit.material.uvSet[i]; - const Vector2 * RESTRICT_ALIAS uv = hit.triUVs[uvSet]; + const Vector2 *RESTRICT_ALIAS uv = hit.triUVs[uvSet]; Vector2 interpUV = uv[0] * a0 + uv[1] * a1 + uv[2] * a2; - const Real texWidth = hit.material.image[i]->getWidth(); + const Real texWidth = hit.material.image[i]->getWidth(); const Real texHeight = hit.material.image[i]->getHeight(); - //The texel centers are in the middle of the pixel, so we need to subtract - //0.5; but later we need to add 0.5 to do correct rounding. So they negate - interpUV.x = interpUV.x * texWidth/* - 0.5f*/; - interpUV.y = interpUV.y * texHeight/* - 0.5f*/; + // The texel centers are in the middle of the pixel, so we need to subtract + // 0.5; but later we need to add 0.5 to do correct rounding. So they negate + interpUV.x = interpUV.x * texWidth /* - 0.5f*/; + interpUV.y = interpUV.y * texHeight /* - 0.5f*/; interpUV.x = std::fmod( interpUV.x, texWidth ); interpUV.y = std::fmod( interpUV.y, texHeight ); @@ -251,13 +222,12 @@ namespace Ogre if( interpUV.y < 0 ) interpUV.y += texHeight; - //TODO: Do blending modes + // TODO: Do blending modes ColourValue colourVal; - PixelFormatGpuUtils::unpackColour( &colourVal, hit.material.image[i]->getPixelFormat(), - hit.material.box[i].at( - static_cast(interpUV.x), - static_cast(interpUV.y), - 0u ) ); + PixelFormatGpuUtils::unpackColour( + &colourVal, hit.material.image[i]->getPixelFormat(), + hit.material.box[i].at( static_cast( interpUV.x ), + static_cast( interpUV.y ), 0u ) ); diffuseTerm.x *= colourVal.r; diffuseTerm.y *= colourVal.g; diffuseTerm.z *= colourVal.b; @@ -271,7 +241,7 @@ namespace Ogre vpl.position = pointOnTri; vpl.numMergedVpls = 1.0f; - memset( vpl.dirDiffuse, 0, sizeof(vpl.dirDiffuse) ); + memset( vpl.dirDiffuse, 0, sizeof( vpl.dirDiffuse ) ); mergeDirectionalDiffuse( diffuseTerm, hit.triNormal, vpl.dirDiffuse ); return vpl; @@ -282,7 +252,7 @@ namespace Ogre { assert( mCellSize > 0 ); - const Real cellSize = Real(1.0) / mCellSize; + const Real cellSize = Real( 1.0 ) / mCellSize; const Real bias = mBias; mTmpSparseClusters[0].clear(); @@ -302,9 +272,9 @@ namespace Ogre const Real accumDistance = hit.accumDistance + hit.distance; - Real atten = Real(1.0f) / - (attenConst + (attenLinear + attenQuad * accumDistance) * accumDistance); - atten = std::min( Real(1.0f), atten ); + Real atten = Real( 1.0f ) / + ( attenConst + ( attenLinear + attenQuad * accumDistance ) * accumDistance ); + atten = std::min( Real( 1.0f ), atten ); const Vector3 pointOnTri = hit.ray.getPoint( hit.distance * bias ); @@ -314,14 +284,14 @@ namespace Ogre Vpl vpl = convertToVpl( lightColour, pointOnTri, hit ); vpl.diffuse *= atten; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) vpl.dirDiffuse[i] *= atten; Real numCollectedVpls = 1.0f; - //Merge the lights (simple average) that lie in the same cluster. + // Merge the lights (simple average) that lie in the same cluster. RayHitVec::iterator itor = mRayHits.begin() + 1u; - RayHitVec::iterator end = mRayHits.end(); + RayHitVec::iterator end = mRayHits.end(); while( itor != end ) { @@ -330,15 +300,15 @@ namespace Ogre if( alikeHit.distance >= std::numeric_limits::max() ) { itor = efficientVectorRemove( mRayHits, itor ); - end = mRayHits.end(); + end = mRayHits.end(); continue; } const Real alikeAccumDistance = alikeHit.accumDistance + alikeHit.distance; - Real alikeAtten = Real(1.0f) / - (attenConst + (attenLinear + - attenQuad * alikeAccumDistance) * alikeAccumDistance); - alikeAtten = std::min( Real(1.0f), alikeAtten ); + Real alikeAtten = + Real( 1.0f ) / ( attenConst + ( attenLinear + attenQuad * alikeAccumDistance ) * + alikeAccumDistance ); + alikeAtten = std::min( Real( 1.0f ), alikeAtten ); const Vector3 pointOnTri02 = alikeHit.ray.getPoint( alikeHit.distance * bias ); @@ -350,16 +320,16 @@ namespace Ogre { Vpl alikeVpl = convertToVpl( lightColour, pointOnTri02, alikeHit ); vpl.diffuse += alikeVpl.diffuse * alikeAtten; - vpl.normal += alikeVpl.normal; - vpl.position+= alikeVpl.position; + vpl.normal += alikeVpl.normal; + vpl.position += alikeVpl.position; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) vpl.dirDiffuse[i] += alikeVpl.dirDiffuse[i] * alikeAtten; ++numCollectedVpls; itor = efficientVectorRemove( mRayHits, itor ); - end = mRayHits.end(); + end = mRayHits.end(); } else { @@ -367,19 +337,19 @@ namespace Ogre } } - //vpl.diffuse /= numCollectedVpls; + // vpl.diffuse /= numCollectedVpls; vpl.diffuse /= mTotalNumRays; - vpl.position/= numCollectedVpls; + vpl.position /= numCollectedVpls; vpl.normal.normalise(); vpl.numMergedVpls = numCollectedVpls; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) vpl.dirDiffuse[i] /= mTotalNumRays; mVpls.push_back( vpl ); - mTmpSparseClusters[0].insert( SparseCluster( blockX, blockY, blockZ, - vpl.diffuse, vpl.normal, vpl.dirDiffuse ) ); + mTmpSparseClusters[0].insert( + SparseCluster( blockX, blockY, blockZ, vpl.diffuse, vpl.normal, vpl.dirDiffuse ) ); RayHitVec::iterator itRay = mRayHits.begin(); efficientVectorRemove( mRayHits, itRay ); @@ -389,7 +359,7 @@ namespace Ogre { mTmpSparseClusters[1] = mTmpSparseClusters[0]; - for( int i=mNumSpreadIterations; --i; ) + for( int i = mNumSpreadIterations; --i; ) { spreadSparseClusters( mTmpSparseClusters[0], mTmpSparseClusters[1] ); mTmpSparseClusters[0] = mTmpSparseClusters[1]; @@ -405,59 +375,58 @@ namespace Ogre SparseClusterSet grid1; grid1.swap( inOutGrid1 ); - const int32 c_directions[6][3] = - { + const int32 c_directions[6][3] = { + // clang-format off { 0, 0, -1 }, { -1, 0, 0 }, { 1, 0, 0 }, { 0, -1, 0 }, { 0, 1, 0 }, { 0, 0, 1 } + // clang-format on }; Vector3 vDirs[6][9]; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) { - Vector3 clusterCorner = Vector3( c_directions[i][0], - c_directions[i][1], - c_directions[i][2] ); + Vector3 clusterCorner = + Vector3( c_directions[i][0], c_directions[i][1], c_directions[i][2] ); vDirs[i][0] = clusterCorner; vDirs[i][1] = clusterCorner + Vector3( -0.5f, -0.5f, -0.5f ); - vDirs[i][2] = clusterCorner + Vector3( 0.5f, -0.5f, -0.5f ); - vDirs[i][3] = clusterCorner + Vector3( -0.5f, 0.5f, -0.5f ); - vDirs[i][4] = clusterCorner + Vector3( 0.5f, 0.5f, -0.5f ); - vDirs[i][5] = clusterCorner + Vector3( -0.5f, -0.5f, 0.5f ); - vDirs[i][6] = clusterCorner + Vector3( 0.5f, -0.5f, 0.5f ); - vDirs[i][7] = clusterCorner + Vector3( -0.5f, 0.5f, 0.5f ); - vDirs[i][8] = clusterCorner + Vector3( 0.5f, 0.5f, 0.5f ); - - for( int j=0; j<9; ++j ) + vDirs[i][2] = clusterCorner + Vector3( 0.5f, -0.5f, -0.5f ); + vDirs[i][3] = clusterCorner + Vector3( -0.5f, 0.5f, -0.5f ); + vDirs[i][4] = clusterCorner + Vector3( 0.5f, 0.5f, -0.5f ); + vDirs[i][5] = clusterCorner + Vector3( -0.5f, -0.5f, 0.5f ); + vDirs[i][6] = clusterCorner + Vector3( 0.5f, -0.5f, 0.5f ); + vDirs[i][7] = clusterCorner + Vector3( -0.5f, 0.5f, 0.5f ); + vDirs[i][8] = clusterCorner + Vector3( 0.5f, 0.5f, 0.5f ); + + for( int j = 0; j < 9; ++j ) vDirs[i][j].normalise(); } - const Real invNumSpreadIterations = Real(1.0f) / mNumSpreadIterations; + const Real invNumSpreadIterations = Real( 1.0f ) / mNumSpreadIterations; SparseClusterSet::const_iterator itor = grid0.begin(); - SparseClusterSet::const_iterator end = grid0.end(); + SparseClusterSet::const_iterator end = grid0.end(); while( itor != end ) { const Vector3 lightDir = itor->direction.normalisedCopy(); - //Spread into all 6 directions. We don't do diagonals because it - //would be prohibitively expensive (26 directions). We hope doing - //this multiple times ends up spreading into all directions. - for( int i=0; i<6; ++i ) + // Spread into all 6 directions. We don't do diagonals because it + // would be prohibitively expensive (26 directions). We hope doing + // this multiple times ends up spreading into all directions. + for( int i = 0; i < 6; ++i ) { Real NdotL = 0; - for( int j=0; j<9; ++j ) + for( int j = 0; j < 9; ++j ) NdotL += std::max( lightDir.dotProduct( vDirs[i][j] ), Real( 0.0f ) ); NdotL /= 9.0f; const Vector3 diffuseCol = NdotL * itor->diffuse; - if( diffuseCol.x >= mSpreadThreshold || - diffuseCol.y >= mSpreadThreshold || + if( diffuseCol.x >= mSpreadThreshold || diffuseCol.y >= mSpreadThreshold || diffuseCol.z >= mSpreadThreshold ) { int32 newBlockHash[3]; @@ -465,20 +434,21 @@ namespace Ogre newBlockHash[1] = itor->blockHash[1] + c_directions[i][1]; newBlockHash[2] = itor->blockHash[2] + c_directions[i][2]; - SparseClusterSet::iterator gridCluster = grid1.find( (int32*)newBlockHash ); + SparseClusterSet::iterator gridCluster = grid1.find( (int32 *)newBlockHash ); if( gridCluster == grid1.end() ) { grid1.insert( SparseCluster( newBlockHash ) ); - gridCluster = grid1.find( (int32*)newBlockHash ); + gridCluster = grid1.find( (int32 *)newBlockHash ); } - //We guarantee we won't change the order of the iterators. - SparseCluster *gridClusterNonConst = const_cast( &(*gridCluster) ); + // We guarantee we won't change the order of the iterators. + SparseCluster *gridClusterNonConst = + const_cast( &( *gridCluster ) ); - //TODO: Consider attenuation. - gridClusterNonConst->diffuse += diffuseCol * invNumSpreadIterations; - gridClusterNonConst->direction += itor->direction; + // TODO: Consider attenuation. + gridClusterNonConst->diffuse += diffuseCol * invNumSpreadIterations; + gridClusterNonConst->direction += itor->direction; } } @@ -493,12 +463,12 @@ namespace Ogre const Real cellSize = mCellSize; SparseClusterSet::const_iterator itor = spreadCluster.begin(); - SparseClusterSet::const_iterator end = spreadCluster.end(); + SparseClusterSet::const_iterator end = spreadCluster.end(); while( itor != end ) { Vector3 vClusterCenter( itor->blockHash[0], itor->blockHash[1], itor->blockHash[2] ); - vClusterCenter = (vClusterCenter + 0.5f) * cellSize; + vClusterCenter = ( vClusterCenter + 0.5f ) * cellSize; Vpl vpl; vpl.light = 0; @@ -507,7 +477,7 @@ namespace Ogre vpl.position = vClusterCenter; vpl.numMergedVpls = 1.0f; - memcpy( vpl.dirDiffuse, itor->dirDiffuse, sizeof(vpl.dirDiffuse) ); + memcpy( vpl.dirDiffuse, itor->dirDiffuse, sizeof( vpl.dirDiffuse ) ); mVpls.push_back( vpl ); @@ -519,14 +489,14 @@ namespace Ogre { assert( mCellSize > 0 ); - const Real cellSize = Real(1.0) / mCellSize; + const Real cellSize = Real( 1.0 ) / mCellSize; VplVec::iterator itor = mVpls.begin(); - VplVec::iterator end = mVpls.end(); + VplVec::iterator end = mVpls.end(); while( itor != end ) { - Vpl vpl = *itor; //Hard copy! + Vpl vpl = *itor; // Hard copy! const size_t idx = itor - mVpls.begin(); @@ -534,12 +504,12 @@ namespace Ogre const int32 blockY = static_cast( Math::Floor( vpl.position.y * cellSize ) ); const int32 blockZ = static_cast( Math::Floor( vpl.position.z * cellSize ) ); - vpl.normal *= vpl.numMergedVpls; - vpl.position*= vpl.numMergedVpls; + vpl.normal *= vpl.numMergedVpls; + vpl.position *= vpl.numMergedVpls; Real numCollectedVpls = vpl.numMergedVpls; - //Merge the lights (simple average) that lie in the same cluster. + // Merge the lights (simple average) that lie in the same cluster. VplVec::iterator itAlike = itor + 1; while( itAlike != end ) @@ -555,18 +525,18 @@ namespace Ogre if( blockX == alikeBlockX && blockY == alikeBlockY && blockZ == alikeBlockZ ) { vpl.diffuse += alikeVpl.diffuse; - vpl.normal += alikeVpl.normal * alikeVpl.numMergedVpls; - vpl.position+= alikeVpl.position * alikeVpl.numMergedVpls; + vpl.normal += alikeVpl.normal * alikeVpl.numMergedVpls; + vpl.position += alikeVpl.position * alikeVpl.numMergedVpls; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) vpl.dirDiffuse[i] += alikeVpl.dirDiffuse[i]; numCollectedVpls += alikeVpl.numMergedVpls; - //Iterators get invalidated! + // Iterators get invalidated! itAlike = efficientVectorRemove( mVpls, itAlike ); - itor = mVpls.begin() + idx; - end = mVpls.end(); + itor = mVpls.begin() + idx; + end = mVpls.end(); } else { @@ -576,7 +546,7 @@ namespace Ogre if( numCollectedVpls > vpl.numMergedVpls ) { - vpl.position/= numCollectedVpls; + vpl.position /= numCollectedVpls; vpl.normal.normalise(); vpl.numMergedVpls = numCollectedVpls; *itor = vpl; @@ -589,25 +559,24 @@ namespace Ogre void InstantRadiosity::autogenerateAreaOfInterest() { AxisAlignedBox areaOfInterest; - for( size_t i=0; i_getEntityMemoryManager( - static_cast(i) ); + ObjectMemoryManager &memoryManager = + mSceneManager->_getEntityMemoryManager( static_cast( i ) ); const size_t numRenderQueues = memoryManager.getNumRenderQueues(); size_t firstRq = std::min( mFirstRq, numRenderQueues ); - size_t lastRq = std::min( mLastRq, numRenderQueues ); + size_t lastRq = std::min( mLastRq, numRenderQueues ); - for( size_t j=firstRq; j::max(); mRayHits[i].accumDistance = 0; @@ -646,7 +615,7 @@ namespace Ogre } else if( lightType == Light::LT_SPOTLIGHT ) { - assert( angle < Degree(180) ); + assert( angle < Degree( 180 ) ); Vector2 pointInCircle = rng.getRandomPointInCircle(); pointInCircle *= Math::Tan( angle * 0.5f ); Vector3 rayDir = Vector3( pointInCircle.x, pointInCircle.y, -1.0f ); @@ -672,37 +641,37 @@ namespace Ogre ++arrayRays; } - //Initialize all other rays (some rays may not be initialized - //at all when not all bounced rays end up hitting something) - for( size_t i=mNumRays; i::max(); size_t rayStart = 0; size_t numRays = mNumRays; - for( size_t k=0; k_getEntityMemoryManager( - static_cast(i) ); + ObjectMemoryManager &memoryManager = + mSceneManager->_getEntityMemoryManager( static_cast( i ) ); const size_t numRenderQueues = memoryManager.getNumRenderQueues(); size_t firstRq = std::min( mFirstRq, numRenderQueues ); - size_t lastRq = std::min( mLastRq, numRenderQueues ); + size_t lastRq = std::min( mLastRq, numRenderQueues ); - for( size_t j=firstRq; j( mNumRays * powf( mSurvivingRayFraction, k + 1 ) ); @@ -715,8 +684,7 @@ namespace Ogre } //----------------------------------------------------------------------------------- size_t InstantRadiosity::generateRayBounces( size_t raySrcStart, size_t raySrcCount, - size_t raysToGenerate, - RandomNumberGenerator &rng ) + size_t raysToGenerate, RandomNumberGenerator &rng ) { size_t rayIdx = raySrcStart; size_t raysRemaining = raysToGenerate; @@ -725,7 +693,7 @@ namespace Ogre const Real bias = mBias; - ArrayRay * RESTRICT_ALIAS arrayRays = mArrayRays.get(); + ArrayRay *RESTRICT_ALIAS arrayRays = mArrayRays.get(); while( rayIdx < raySrcLimit && raysRemaining > 0 ) { @@ -744,7 +712,8 @@ namespace Ogre mRayHits[i].distance = std::numeric_limits::max(); mRayHits[i].accumDistance = hit.accumDistance + hit.distance; mRayHits[i].ray.setOrigin( pointOnTri ); - mRayHits[i].ray.setDirection( rng.randomizeDirAroundCone( hit.triNormal, Degree( 90.0f ) ) ); + mRayHits[i].ray.setDirection( + rng.randomizeDirAroundCone( hit.triNormal, Degree( 90.0f ) ) ); arrayRays[i].mOrigin.setAll( mRayHits[i].ray.getOrigin() ); arrayRays[i].mDirection.setAll( mRayHits[i].ray.getDirection() ); @@ -756,7 +725,7 @@ namespace Ogre return raysToGenerate - raysRemaining; } //----------------------------------------------------------------------------------- - const InstantRadiosity::MeshData* InstantRadiosity::downloadVao( VertexArrayObject *vao ) + const InstantRadiosity::MeshData *InstantRadiosity::downloadVao( VertexArrayObject *vao ) { MeshDataMapV2::const_iterator itor = mMeshDataMapV2.find( vao ); if( itor != mMeshDataMapV2.end() ) @@ -765,17 +734,17 @@ namespace Ogre IndexBufferPacked *indexBuffer = vao->getIndexBuffer(); MeshData meshData; - memset( &meshData, 0, sizeof(meshData) ); + memset( &meshData, 0, sizeof( meshData ) ); - //Issue all async requests now. + // Issue all async requests now. VertexArrayObject::ReadRequestsArray readRequests; AsyncTicketPtr indexTicket; { - //Request to read VES_POSITION (must be present) and all of its UVs + // Request to read VES_POSITION (must be present) and all of its UVs readRequests.push_back( VES_POSITION ); - //Avoid downloading UVs if not needed + // Avoid downloading UVs if not needed if( mUseTextures ) { VertexElement2VecVec vertexDeclaration = vao->getVertexDeclaration(); @@ -806,8 +775,7 @@ namespace Ogre if( indexBuffer && !indexBuffer->getShadowCopy() ) { - indexTicket = indexBuffer->readRequest( vao->getPrimitiveStart(), - vao->getPrimitiveCount() ); + indexTicket = indexBuffer->readRequest( vao->getPrimitiveStart(), vao->getPrimitiveCount() ); } if( indexBuffer ) @@ -817,10 +785,9 @@ namespace Ogre meshData.numIndices = vao->getPrimitiveCount(); if( !indexBuffer->getShadowCopy() ) { - meshData.indexData = reinterpret_cast( - OGRE_MALLOC_SIMD( vao->getPrimitiveCount() * - indexBuffer->getBytesPerElement(), - MEMCATEGORY_GEOMETRY ) ); + meshData.indexData = reinterpret_cast( + OGRE_MALLOC_SIMD( vao->getPrimitiveCount() * indexBuffer->getBytesPerElement(), + MEMCATEGORY_GEOMETRY ) ); } } else @@ -830,57 +797,57 @@ namespace Ogre const size_t numVertexElements = readRequests.size(); - meshData.vertexData = reinterpret_cast( - OGRE_MALLOC_SIMD( meshData.numVertices * (sizeof(float) * 3u + - sizeof(float) * 2u * (numVertexElements - 1u)), - MEMCATEGORY_GEOMETRY ) ); + meshData.vertexData = reinterpret_cast( OGRE_MALLOC_SIMD( + meshData.numVertices * + ( sizeof( float ) * 3u + sizeof( float ) * 2u * ( numVertexElements - 1u ) ), + MEMCATEGORY_GEOMETRY ) ); - //Copy position + UVs + // Copy position + UVs bool isHalf[9]; - for( size_t j=0; jmapAsyncTickets( readRequests ); - for( size_t i=0; i( readRequests[0].data ); - meshData.vertexData[i*3u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); - meshData.vertexData[i*3u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); - meshData.vertexData[i*3u + 2u] = Bitwise::halfToFloat( bufferF16[2] ); + uint16 const *RESTRICT_ALIAS bufferF16 = + reinterpret_cast( readRequests[0].data ); + meshData.vertexData[i * 3u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); + meshData.vertexData[i * 3u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); + meshData.vertexData[i * 3u + 2u] = Bitwise::halfToFloat( bufferF16[2] ); } else { - float const * RESTRICT_ALIAS bufferF32 = - reinterpret_cast( readRequests[0].data ); - meshData.vertexData[i*3u + 0u] = bufferF32[0]; - meshData.vertexData[i*3u + 1u] = bufferF32[1]; - meshData.vertexData[i*3u + 2u] = bufferF32[2]; + float const *RESTRICT_ALIAS bufferF32 = + reinterpret_cast( readRequests[0].data ); + meshData.vertexData[i * 3u + 0u] = bufferF32[0]; + meshData.vertexData[i * 3u + 1u] = bufferF32[1]; + meshData.vertexData[i * 3u + 2u] = bufferF32[2]; } readRequests[0].data += readRequests[0].vertexBuffer->getBytesPerElement(); - //Copy UVs - for( size_t j=1; j( readRequests[j].data ); - uvDst[i*2u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); - uvDst[i*2u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); + uint16 const *RESTRICT_ALIAS bufferF16 = + reinterpret_cast( readRequests[j].data ); + uvDst[i * 2u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); + uvDst[i * 2u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); } else { - float const * RESTRICT_ALIAS bufferF32 = - reinterpret_cast( readRequests[j].data ); - uvDst[i*2u + 0u] = bufferF32[0]; - uvDst[i*2u + 1u] = bufferF32[1]; + float const *RESTRICT_ALIAS bufferF32 = + reinterpret_cast( readRequests[j].data ); + uvDst[i * 2u + 0u] = bufferF32[0]; + uvDst[i * 2u + 1u] = bufferF32[1]; } readRequests[j].data += readRequests[j].vertexBuffer->getBytesPerElement(); @@ -889,7 +856,7 @@ namespace Ogre vao->unmapAsyncTickets( readRequests ); - //Copy index buffer + // Copy index buffer if( indexBuffer ) { if( !indexBuffer->getShadowCopy() ) @@ -902,8 +869,8 @@ namespace Ogre else { meshData.indexDataConst = - reinterpret_cast( indexBuffer->getShadowCopy() ) + - vao->getPrimitiveStart(); + reinterpret_cast( indexBuffer->getShadowCopy() ) + + vao->getPrimitiveStart(); } } @@ -912,8 +879,8 @@ namespace Ogre return &mMeshDataMapV2[vao]; } //----------------------------------------------------------------------------------- - const InstantRadiosity::MeshData* InstantRadiosity::downloadRenderOp( - const v1::RenderOperation &renderOp ) + const InstantRadiosity::MeshData *InstantRadiosity::downloadRenderOp( + const v1::RenderOperation &renderOp ) { MeshDataMapV1::const_iterator itor = mMeshDataMapV1.find( renderOp ); if( itor != mMeshDataMapV1.end() ) @@ -922,14 +889,14 @@ namespace Ogre v1::VertexData::ReadRequestsArray readRequests; { - //Request to read VES_POSITION (must be present) and all of its UVs + // Request to read VES_POSITION (must be present) and all of its UVs readRequests.push_back( VES_POSITION ); - //Avoid downloading UVs if not needed + // Avoid downloading UVs if not needed if( mUseTextures ) { const v1::VertexDeclaration::VertexElementList &vertexElements = - renderOp.vertexData->vertexDeclaration->getElements(); + renderOp.vertexData->vertexDeclaration->getElements(); v1::VertexDeclaration::VertexElementList::const_iterator it0 = vertexElements.begin(); v1::VertexDeclaration::VertexElementList::const_iterator en0 = vertexElements.end(); @@ -946,76 +913,75 @@ namespace Ogre renderOp.vertexData->lockMultipleElements( readRequests, v1::HardwareBuffer::HBL_READ_ONLY ); MeshData meshData; - memset( &meshData, 0, sizeof(meshData) ); + memset( &meshData, 0, sizeof( meshData ) ); meshData.numVertices = renderOp.vertexData->vertexCount; - meshData.vertexData = reinterpret_cast( - OGRE_MALLOC_SIMD( meshData.numVertices * (sizeof(float) * 3u + - sizeof(float) * 2u * (numVertexElements - 1u)), - MEMCATEGORY_GEOMETRY ) ); + meshData.vertexData = reinterpret_cast( OGRE_MALLOC_SIMD( + meshData.numVertices * + ( sizeof( float ) * 3u + sizeof( float ) * 2u * ( numVertexElements - 1u ) ), + MEMCATEGORY_GEOMETRY ) ); if( renderOp.useIndexes ) { - meshData.useIndices16bit = renderOp.indexData->indexBuffer->getType() == - v1::HardwareIndexBuffer::IT_16BIT; + meshData.useIndices16bit = + renderOp.indexData->indexBuffer->getType() == v1::HardwareIndexBuffer::IT_16BIT; meshData.numIndices = renderOp.indexData->indexCount; - meshData.indexData = reinterpret_cast( - OGRE_MALLOC_SIMD( meshData.numIndices * - renderOp.indexData->indexBuffer->getIndexSize(), - MEMCATEGORY_GEOMETRY ) ); + meshData.indexData = reinterpret_cast( + OGRE_MALLOC_SIMD( meshData.numIndices * renderOp.indexData->indexBuffer->getIndexSize(), + MEMCATEGORY_GEOMETRY ) ); } - //Copy position + UVs + // Copy position + UVs bool isHalf[9]; - for( size_t j=0; jvertexStart * - readRequests[j].vertexBuffer->getVertexSize(); + readRequests[j].data += + renderOp.vertexData->vertexStart * readRequests[j].vertexBuffer->getVertexSize(); } } - for( size_t i=0; i( readRequests[0].data ); - meshData.vertexData[i*3u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); - meshData.vertexData[i*3u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); - meshData.vertexData[i*3u + 2u] = Bitwise::halfToFloat( bufferF16[2] ); + uint16 const *RESTRICT_ALIAS bufferF16 = + reinterpret_cast( readRequests[0].data ); + meshData.vertexData[i * 3u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); + meshData.vertexData[i * 3u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); + meshData.vertexData[i * 3u + 2u] = Bitwise::halfToFloat( bufferF16[2] ); } else { - float const * RESTRICT_ALIAS bufferF32 = - reinterpret_cast( readRequests[0].data ); - meshData.vertexData[i*3u + 0u] = bufferF32[0]; - meshData.vertexData[i*3u + 1u] = bufferF32[1]; - meshData.vertexData[i*3u + 2u] = bufferF32[2]; + float const *RESTRICT_ALIAS bufferF32 = + reinterpret_cast( readRequests[0].data ); + meshData.vertexData[i * 3u + 0u] = bufferF32[0]; + meshData.vertexData[i * 3u + 1u] = bufferF32[1]; + meshData.vertexData[i * 3u + 2u] = bufferF32[2]; } readRequests[0].data += readRequests[0].vertexBuffer->getVertexSize(); - //Copy UVs - for( size_t j=1; j( readRequests[j].data ); - uvDst[i*2u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); - uvDst[i*2u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); + uint16 const *RESTRICT_ALIAS bufferF16 = + reinterpret_cast( readRequests[j].data ); + uvDst[i * 2u + 0u] = Bitwise::halfToFloat( bufferF16[0] ); + uvDst[i * 2u + 1u] = Bitwise::halfToFloat( bufferF16[1] ); } else { - float const * RESTRICT_ALIAS bufferF32 = - reinterpret_cast( readRequests[j].data ); - uvDst[i*2u + 0u] = bufferF32[0]; - uvDst[i*2u + 1u] = bufferF32[1]; + float const *RESTRICT_ALIAS bufferF32 = + reinterpret_cast( readRequests[j].data ); + uvDst[i * 2u + 0u] = bufferF32[0]; + uvDst[i * 2u + 1u] = bufferF32[1]; } readRequests[j].data += readRequests[j].vertexBuffer->getVertexSize(); @@ -1024,16 +990,14 @@ namespace Ogre renderOp.vertexData->unlockMultipleElements( readRequests ); - //Copy index buffer + // Copy index buffer if( renderOp.useIndexes ) { - v1::HardwareBufferLockGuard indexLock( renderOp.indexData->indexBuffer, - renderOp.indexData->indexStart, - renderOp.indexData->indexCount, - v1::HardwareBuffer::HBL_READ_ONLY ); + v1::HardwareBufferLockGuard indexLock( + renderOp.indexData->indexBuffer, renderOp.indexData->indexStart, + renderOp.indexData->indexCount, v1::HardwareBuffer::HBL_READ_ONLY ); memcpy( meshData.indexData, indexLock.pData, - renderOp.indexData->indexCount * - renderOp.indexData->indexBuffer->getIndexSize() ); + renderOp.indexData->indexCount * renderOp.indexData->indexBuffer->getIndexSize() ); } mMeshDataMapV1[renderOp] = meshData; @@ -1054,55 +1018,55 @@ namespace Ogre return itor->second; } //----------------------------------------------------------------------------------- - void InstantRadiosity::testLightVsAllObjects( uint8 lightType, Real lightRange, - ObjectData objData, size_t numNodes, + void InstantRadiosity::testLightVsAllObjects( uint8 lightType, Real lightRange, ObjectData objData, + size_t numNodes, const AreaOfInterest &scalarAreaOfInterest, size_t rayStart, size_t numRays ) { Aabb biggestAoI = scalarAreaOfInterest.aabb; biggestAoI.merge( Aabb( biggestAoI.mCenter, Vector3( scalarAreaOfInterest.sphereRadius ) ) ); - const ArrayInt sceneFlags = Mathlib::SetAll( mVisibilityMask & - VisibilityFlags::RESERVED_VISIBILITY_FLAGS ); + const ArrayInt sceneFlags = + Mathlib::SetAll( mVisibilityMask & VisibilityFlags::RESERVED_VISIBILITY_FLAGS ); ArrayAabb areaOfInterest( ArrayVector3::ZERO, ArrayVector3::ZERO ); areaOfInterest.setAll( biggestAoI ); - for( size_t i=0; i - (objData.mVisibilityFlags); + ArrayInt *RESTRICT_ALIAS visibilityFlags = + reinterpret_cast( objData.mVisibilityFlags ); - //isObjectHitByRays = isVisble; - ArrayMaskI isObjectHitByRays = Mathlib::TestFlags4( *visibilityFlags, - Mathlib::SetAll( VisibilityFlags::LAYER_VISIBILITY ) ); - //isObjectHitByRays = isVisble & (sceneFlags & visibilityFlags); - isObjectHitByRays = Mathlib::And( isObjectHitByRays, - Mathlib::TestFlags4( sceneFlags, *visibilityFlags ) ); + // isObjectHitByRays = isVisble; + ArrayMaskI isObjectHitByRays = Mathlib::TestFlags4( + *visibilityFlags, Mathlib::SetAll( VisibilityFlags::LAYER_VISIBILITY ) ); + // isObjectHitByRays = isVisble & (sceneFlags & visibilityFlags); + isObjectHitByRays = + Mathlib::And( isObjectHitByRays, Mathlib::TestFlags4( sceneFlags, *visibilityFlags ) ); if( lightType == Light::LT_DIRECTIONAL ) { - //Check if obj is in area of interest for directional lights + // Check if obj is in area of interest for directional lights ArrayMaskI hitMask = CastRealToInt( areaOfInterest.intersects( *objData.mWorldAabb ) ); isObjectHitByRays = Mathlib::And( isObjectHitByRays, hitMask ); } if( BooleanMask4::getScalarMask( isObjectHitByRays ) == 0 ) { - //None of these objects are visible. Early out. + // None of these objects are visible. Early out. objData.advancePack(); continue; } - for( size_t k=0; kintersects( *objData.mWorldAabb ); uint32 scalarRayHits = BooleanMask4::getScalarMask( rayHits ); - for( size_t k=0; k_getParentNodeFullTransform(); RenderableArray::const_iterator itor = movableObject->mRenderables.begin(); - RenderableArray::const_iterator end = movableObject->mRenderables.end(); + RenderableArray::const_iterator end = movableObject->mRenderables.end(); while( itor != end ) { - const VertexArrayObjectArray &vaos = (*itor)->getVaos( VpNormal ); + const VertexArrayObjectArray &vaos = ( *itor )->getVaos( VpNormal ); MeshData const *meshData = 0; if( !vaos.empty() ) { - //v2 object - VertexArrayObject *vao = vaos[0]; //TODO Allow picking a LOD. + // v2 object + VertexArrayObject *vao = vaos[0]; // TODO Allow picking a LOD. meshData = downloadVao( vao ); } else { - //v1 object + // v1 object v1::RenderOperation renderOp; - (*itor)->getRenderOperation( renderOp, false ); + ( *itor )->getRenderOperation( renderOp, false ); meshData = downloadRenderOp( renderOp ); } - HlmsDatablock *datablock = (*itor)->getDatablock(); + HlmsDatablock *datablock = ( *itor )->getDatablock(); if( datablock->mType == HLMS_PBS ) { MaterialData material; - memset( &material, 0, sizeof(material) ); + memset( &material, 0, sizeof( material ) ); int imageIdx = 0; - HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); - //TODO: Should we account fresnel here? What about metalness? + HlmsPbsDatablock *pbsDatablock = + static_cast( datablock ); + // TODO: Should we account fresnel here? What about metalness? material.diffuse = pbsDatablock->getDiffuse(); TextureGpu *diffuseTex = pbsDatablock->getTexture( PBSM_DIFFUSE ); if( diffuseTex ) @@ -1168,38 +1132,36 @@ namespace Ogre else if( mUseTextures ) { material.image[imageIdx] = &downloadTexture( diffuseTex ); - material.box[imageIdx] = material.image[imageIdx]->getData(0); + material.box[imageIdx] = material.image[imageIdx]->getData( 0 ); material.uvSet[imageIdx] = - pbsDatablock->getTextureUvSource( PBSM_DIFFUSE ); + pbsDatablock->getTextureUvSource( PBSM_DIFFUSE ); material.needsUv = true; ++imageIdx; } if( mUseTextures ) { - for( int k=0; k<4; ++k ) + for( int k = 0; k < 4; ++k ) { - const PbsTextureTypes texType = static_cast( - PBSM_DETAIL0 + k ); + const PbsTextureTypes texType = + static_cast( PBSM_DETAIL0 + k ); TextureGpu *detailTex = pbsDatablock->getTexture( texType ); if( detailTex ) detailTex->waitForMetadata(); - if( detailTex && - !PixelFormatGpuUtils::isCompressed( - detailTex->getPixelFormat() ) ) + if( detailTex && !PixelFormatGpuUtils::isCompressed( + detailTex->getPixelFormat() ) ) { material.image[imageIdx] = &downloadTexture( detailTex ); - material.box[imageIdx] = material.image[imageIdx]->getData(0); + material.box[imageIdx] = material.image[imageIdx]->getData( 0 ); material.uvSet[imageIdx] = - pbsDatablock->getTextureUvSource( texType ); + pbsDatablock->getTextureUvSource( texType ); material.needsUv = true; ++imageIdx; } } } - raycastLightRayVsMesh( lightRange, *meshData, - worldMatrix, material, + raycastLightRayVsMesh( lightRange, *meshData, worldMatrix, material, mTmpRaysThatHitObject[j] ); } @@ -1218,12 +1180,12 @@ namespace Ogre { const size_t numElements = meshData.indexData ? meshData.numIndices : meshData.numVertices; - const uint16 * RESTRICT_ALIAS indexData16 = reinterpret_cast( - meshData.indexData ); - const uint32 * RESTRICT_ALIAS indexData32 = reinterpret_cast( - meshData.indexData ); + const uint16 *RESTRICT_ALIAS indexData16 = + reinterpret_cast( meshData.indexData ); + const uint32 *RESTRICT_ALIAS indexData32 = + reinterpret_cast( meshData.indexData ); - for( size_t i=0; i::const_iterator itRayIdx = raysThatHitObj.begin(); @@ -1276,13 +1238,12 @@ namespace Ogre Ray ray = mRayHits[*itRayIdx].ray; const std::pair inters = Math::intersects( - ray, triVerts[0], triVerts[1], triVerts[2], triNormal, true, false ); + ray, triVerts[0], triVerts[1], triVerts[2], triNormal, true, false ); if( inters.first ) { RayHit &rayHit = mRayHits[*itRayIdx]; - if( inters.second < rayHit.distance && - inters.second <= lightRange ) + if( inters.second < rayHit.distance && inters.second <= lightRange ) { rayHit.distance = inters.second; rayHit.material = material; @@ -1291,10 +1252,10 @@ namespace Ogre rayHit.triVerts[2] = triVerts[2]; rayHit.triNormal = triNormal; - for( int j=0; j<5 && material.image[j]; ++j ) + for( int j = 0; j < 5 && material.image[j]; ++j ) { const uint8 uvSet = material.uvSet[j]; - const float * RESTRICT_ALIAS uvPtr = meshData.getUvStart( uvSet ); + const float *RESTRICT_ALIAS uvPtr = meshData.getUvStart( uvSet ); rayHit.triUVs[j][0].x = uvPtr[vertexIdx[0] * 2u + 0]; rayHit.triUVs[j][0].y = uvPtr[vertexIdx[0] * 2u + 1]; @@ -1317,16 +1278,15 @@ namespace Ogre SceneNode *rootNode = mSceneManager->getRootSceneNode( SCENE_DYNAMIC ); VplVec::iterator itor = mVpls.begin(); - VplVec::iterator end = mVpls.end(); + VplVec::iterator end = mVpls.end(); while( itor != end ) { Vpl &vpl = *itor; Vector3 diffuseCol = vpl.diffuse * mVplPowerBoost; - if( (diffuseCol.x > mVplThreshold || - diffuseCol.y > mVplThreshold || - diffuseCol.z > mVplThreshold) && - !mUseIrradianceVolume) + if( ( diffuseCol.x > mVplThreshold || diffuseCol.y > mVplThreshold || + diffuseCol.z > mVplThreshold ) && + !mUseIrradianceVolume ) { if( !vpl.light ) { @@ -1352,7 +1312,7 @@ namespace Ogre if( mVplQuadAtten != 0 ) intensity *= 1e-6 / mVplQuadAtten; double rangeInMeters = std::sqrt( intensity ); - range = (float)(rangeInMeters * mVplIntensityRangeMultiplier); + range = (float)( rangeInMeters * mVplIntensityRangeMultiplier ); } vpl.light->setDiffuseColour( colour ); @@ -1378,7 +1338,7 @@ namespace Ogre void InstantRadiosity::clear() { VplVec::const_iterator itor = mVpls.begin(); - VplVec::const_iterator end = mVpls.end(); + VplVec::const_iterator end = mVpls.end(); while( itor != end ) { @@ -1402,32 +1362,32 @@ namespace Ogre { clear(); - if( mNumRayBounces > 0 && (mSurvivingRayFraction <= 0 || mSurvivingRayFraction > 1.0f) ) + if( mNumRayBounces > 0 && ( mSurvivingRayFraction <= 0 || mSurvivingRayFraction > 1.0f ) ) { OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "For multiple bounces, mSurvivingRayFraction must be in range (0; 1]", "InstantRadiosity::build" ); } - //Sum of the first n terms of a geometric series - //mNumRays + mNumRays * mSurvivingRayFraction + mNumRays * mSurvivingRayFraction^2 + ... + // Sum of the first n terms of a geometric series + // mNumRays + mNumRays * mSurvivingRayFraction + mNumRays * mSurvivingRayFraction^2 + ... if( mSurvivingRayFraction != 1.0f ) { - mTotalNumRays = static_cast( mNumRays * - (1.0f - powf( mSurvivingRayFraction, mNumRayBounces + 1u )) / - (1.0f - mSurvivingRayFraction) ); + mTotalNumRays = static_cast( + mNumRays * ( 1.0f - powf( mSurvivingRayFraction, mNumRayBounces + 1u ) ) / + ( 1.0f - mSurvivingRayFraction ) ); } else { - mTotalNumRays = mNumRays * (mNumRayBounces + 1u); + mTotalNumRays = mNumRays * ( mNumRayBounces + 1u ); } - //Ensure position & AABB data is up to date. + // Ensure position & AABB data is up to date. mSceneManager->updateSceneGraph(); mSceneManager->clearFrameData(); Hlms *hlms = mHlmsManager->getHlms( HLMS_PBS ); - if( !dynamic_cast( hlms ) ) + if( !dynamic_cast( hlms ) ) { OGRE_EXCEPT( Exception::ERR_INVALID_STATE, "This InstantRadiosity is designed to downcast HlmsDatablock into " @@ -1450,21 +1410,21 @@ namespace Ogre aoiAutogenerated = true; } - for( size_t i=0; i( objData.mOwner[k] ); + Light *light = static_cast( objData.mOwner[k] ); if( light->getType() != Light::LT_VPL ) { Node *lightNode = light->getParentNode(); @@ -1483,23 +1443,19 @@ namespace Ogre if( light->getType() != Light::LT_DIRECTIONAL ) numAoI = 1; - for( size_t l=0; l_getDerivedPosition(), - lightNode->_getDerivedOrientation(), - light->getType(), - light->getSpotlightOuterAngle(), - diffuseCol, - lightRange, + lightNode->_getDerivedOrientation(), light->getType(), + light->getSpotlightOuterAngle(), diffuseCol, lightRange, light->getAttenuationConstant(), light->getAttenuationLinear(), - light->getAttenuationQuadric(), - areaOfInterest ); + light->getAttenuationQuadric(), areaOfInterest ); } - //light->setPowerScale( Math::PI * 4 ); - //light->setPowerScale( 0 ); + // light->setPowerScale( Math::PI * 4 ); + // light->setPowerScale( 0 ); } } } @@ -1512,7 +1468,7 @@ namespace Ogre updateExistingVpls(); - //Free memory + // Free memory mArrayRays = RawSimdUniquePtr(); if( aoiAutogenerated ) @@ -1523,7 +1479,7 @@ namespace Ogre { { MeshDataMapV2::iterator itor = mMeshDataMapV2.begin(); - MeshDataMapV2::iterator end = mMeshDataMapV2.end(); + MeshDataMapV2::iterator end = mMeshDataMapV2.end(); while( itor != end ) { @@ -1542,7 +1498,7 @@ namespace Ogre } { MeshDataMapV1::iterator itor = mMeshDataMapV1.begin(); - MeshDataMapV1::iterator end = mMeshDataMapV1.end(); + MeshDataMapV1::iterator end = mMeshDataMapV1.end(); while( itor != end ) { @@ -1566,18 +1522,12 @@ namespace Ogre void InstantRadiosity::mergeDirectionalDiffuse( const Vector3 &diffuse, const Vector3 &lightDir, Vector3 *inOutDirDiffuse ) { - const Vector3 directions[6] = - { - Vector3( 1, 0, 0 ), - Vector3( -1, 0, 0 ), - Vector3( 0, 1, 0 ), - Vector3( 0, -1, 0 ), - Vector3( 0, 0, 1 ), - Vector3( 0, 0, -1 ) - }; + const Vector3 directions[6] = { Vector3( 1, 0, 0 ), Vector3( -1, 0, 0 ), Vector3( 0, 1, 0 ), + Vector3( 0, -1, 0 ), Vector3( 0, 0, 1 ), Vector3( 0, 0, -1 ) }; - for( int i=0; i<6; ++i ) - inOutDirDiffuse[i] += std::max( lightDir.dotProduct( directions[i] ), Real( 0.0f ) ) * diffuse; + for( int i = 0; i < 6; ++i ) + inOutDirDiffuse[i] += + std::max( lightDir.dotProduct( directions[i] ), Real( 0.0f ) ) * diffuse; } //----------------------------------------------------------------------------------- void InstantRadiosity::createDebugMarkers() @@ -1589,7 +1539,7 @@ namespace Ogre Hlms *hlms = mHlmsManager->getHlms( HLMS_UNLIT ); VplVec::const_iterator itor = mVpls.begin(); - VplVec::const_iterator end = mVpls.end(); + VplVec::const_iterator end = mVpls.end(); char tmpBuffer[128]; while( itor != end ) @@ -1602,25 +1552,24 @@ namespace Ogre sceneNode->setScale( Vector3( mCellSize * 0.05f ) ); ColourValue colour = vpl.light->getDiffuseColour(); - //Prevent very dark VPLs from being almost invisible - colour = colour * ColourValue( 0.95f, 0.95f, 0.95f ) + - ColourValue( 0.05f, 0.05f, 0.05f ); + // Prevent very dark VPLs from being almost invisible + colour = + colour * ColourValue( 0.95f, 0.95f, 0.95f ) + ColourValue( 0.05f, 0.05f, 0.05f ); - LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); texName.a( colour.r, " ", colour.g, " ", colour.b ); HlmsParamVec params; params.push_back( std::pair( "diffuse", texName.c_str() ) ); - String datablockName = "InstantRadiosity_DebugMarker_" + - StringConverter::toString( Id::generateNewId() ); - HlmsDatablock *datablock = hlms->createDatablock( datablockName, datablockName, - HlmsMacroblock(), HlmsBlendblock(), - params, false ); + String datablockName = + "InstantRadiosity_DebugMarker_" + + StringConverter::toString( Id::generateNewId() ); + HlmsDatablock *datablock = hlms->createDatablock( + datablockName, datablockName, HlmsMacroblock(), HlmsBlendblock(), params, false ); - Item *item = mSceneManager->createItem( "Sphere1000.mesh", - Ogre::ResourceGroupManager:: - AUTODETECT_RESOURCE_GROUP_NAME, - Ogre::SCENE_STATIC ); + Item *item = mSceneManager->createItem( + "Sphere1000.mesh", Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, + Ogre::SCENE_STATIC ); item->setCastShadows( false ); sceneNode->attachObject( item ); item->setDatablock( datablock ); @@ -1635,14 +1584,14 @@ namespace Ogre { Hlms *hlms = mHlmsManager->getHlms( HLMS_UNLIT ); - vector::type::const_iterator itor = mDebugMarkers.begin(); - vector::type::const_iterator end = mDebugMarkers.end(); + vector::type::const_iterator itor = mDebugMarkers.begin(); + vector::type::const_iterator end = mDebugMarkers.end(); while( itor != end ) { - SceneNode *sceneNode = (*itor)->getParentSceneNode(); + SceneNode *sceneNode = ( *itor )->getParentSceneNode(); sceneNode->getParentSceneNode()->removeAndDestroyChild( sceneNode ); - HlmsDatablock *datablock = (*itor)->getSubItem(0)->getDatablock(); + HlmsDatablock *datablock = ( *itor )->getSubItem( 0 )->getDatablock(); mSceneManager->destroyItem( *itor ); hlms->destroyDatablock( datablock->getName() ); @@ -1671,23 +1620,20 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - void InstantRadiosity::setUseIrradianceVolume(bool bUseIrradianceVolume) + void InstantRadiosity::setUseIrradianceVolume( bool bUseIrradianceVolume ) { - if (bUseIrradianceVolume != mUseIrradianceVolume) + if( bUseIrradianceVolume != mUseIrradianceVolume ) { mUseIrradianceVolume = bUseIrradianceVolume; updateExistingVpls(); } } //----------------------------------------------------------------------------------- - void InstantRadiosity::suggestIrradianceVolumeParameters( const Vector3 &cellSize, - Vector3 &outVolumeOrigin, - Real &outLightMaxPower, - uint32 &outNumBlocksX, - uint32 &outNumBlocksY, - uint32 &outNumBlocksZ) + void InstantRadiosity::suggestIrradianceVolumeParameters( + const Vector3 &cellSize, Vector3 &outVolumeOrigin, Real &outLightMaxPower, uint32 &outNumBlocksX, + uint32 &outNumBlocksY, uint32 &outNumBlocksZ ) { - const Vector3 invCellSize = Real(1.0) / cellSize; + const Vector3 invCellSize = Real( 1.0 ) / cellSize; int32 minBlockX = std::numeric_limits::max(); int32 minBlockY = std::numeric_limits::max(); @@ -1700,7 +1646,7 @@ namespace Ogre Real lightMaxPower = 0.0f; VplVec::const_iterator itor = mVpls.begin(); - VplVec::const_iterator end = mVpls.end(); + VplVec::const_iterator end = mVpls.end(); while( itor != end ) { @@ -1716,7 +1662,7 @@ namespace Ogre /*if( mVplQuadAtten != 0 ) intensity *= 1e-6 / mVplQuadAtten;*/ double rangeInMeters = std::sqrt( intensity ); - range = (float)(rangeInMeters * mVplIntensityRangeMultiplier); + range = (float)( rangeInMeters * mVplIntensityRangeMultiplier ); } range = std::min( range, mVplMaxRange ); @@ -1736,7 +1682,7 @@ namespace Ogre maxBlockY = std::max( maxBlockY, blockY + yRange ); maxBlockZ = std::max( maxBlockZ, blockZ + zRange ); - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) { lightMaxPower = std::max( lightMaxPower, vpl.dirDiffuse[i].x ); lightMaxPower = std::max( lightMaxPower, vpl.dirDiffuse[i].y ); @@ -1757,15 +1703,16 @@ namespace Ogre outLightMaxPower = lightMaxPower; } //----------------------------------------------------------------------------------- - void InstantRadiosity::fillIrradianceVolume( IrradianceVolume *volume, - Vector3 cellSize, Vector3 volumeOrigin, - Real lightMaxPower, bool fadeAttenuationOverDistance ) + void InstantRadiosity::fillIrradianceVolume( IrradianceVolume *volume, Vector3 cellSize, + Vector3 volumeOrigin, Real lightMaxPower, + bool fadeAttenuationOverDistance ) { - if (!volume) return; + if( !volume ) + return; - const Vector3 invCellSize = Real(1.0) / cellSize; + const Vector3 invCellSize = Real( 1.0 ) / cellSize; - //Quantize volumeCenter. + // Quantize volumeCenter. volumeOrigin.x = static_cast( Math::Floor( volumeOrigin.x * invCellSize.x ) ); volumeOrigin.y = static_cast( Math::Floor( volumeOrigin.y * invCellSize.y ) ); volumeOrigin.z = static_cast( Math::Floor( volumeOrigin.z * invCellSize.z ) ); @@ -1787,18 +1734,13 @@ namespace Ogre const int32 numBlocksZ = volume->getNumBlocksZ(); VplVec::const_iterator itor = mVpls.begin(); - VplVec::const_iterator end = mVpls.end(); + VplVec::const_iterator end = mVpls.end(); volume->clearVolumeData(); - const Vector3 c_directions[6] = - { - Vector3( 1, 0, 0 ), - Vector3( -1, 0, 0 ), - Vector3( 0, 1, 0 ), - Vector3( 0, -1, 0 ), - Vector3( 0, 0, 1 ), - Vector3( 0, 0, -1 ) + const Vector3 c_directions[6] = { + Vector3( 1, 0, 0 ), Vector3( -1, 0, 0 ), Vector3( 0, 1, 0 ), + Vector3( 0, -1, 0 ), Vector3( 0, 0, 1 ), Vector3( 0, 0, -1 ) }; while( itor != end ) @@ -1815,7 +1757,7 @@ namespace Ogre /*if( mVplQuadAtten != 0 ) intensity *= 1e-6 / mVplQuadAtten;*/ double rangeInMeters = std::sqrt( intensity ); - range = (float)(rangeInMeters * mVplIntensityRangeMultiplier); + range = (float)( rangeInMeters * mVplIntensityRangeMultiplier ); } range = std::min( range, mVplMaxRange ); @@ -1837,18 +1779,17 @@ namespace Ogre const int32 minBlockZ = std::max( 0, blockZ - zRange ); const int32 maxBlockX = std::min( numBlocksX - 1, blockX + xRange ); - const int32 maxBlockY = std::min( numBlocksY - 1, blockY + yRange); - const int32 maxBlockZ = std::min( numBlocksZ - 1, blockZ + zRange); + const int32 maxBlockY = std::min( numBlocksY - 1, blockY + yRange ); + const int32 maxBlockZ = std::min( numBlocksZ - 1, blockZ + zRange ); - if (maxBlockX >= 0 && minBlockX < numBlocksX && - maxBlockY >= 0 && minBlockY < numBlocksY && - maxBlockZ >= 0 && minBlockZ < numBlocksZ) + if( maxBlockX >= 0 && minBlockX < numBlocksX && maxBlockY >= 0 && minBlockY < numBlocksY && + maxBlockZ >= 0 && minBlockZ < numBlocksZ ) { - for( int32 z=minBlockZ; z<=maxBlockZ; ++z ) + for( int32 z = minBlockZ; z <= maxBlockZ; ++z ) { - for( int32 y=minBlockY; y<=maxBlockY; ++y ) + for( int32 y = minBlockY; y <= maxBlockY; ++y ) { - for( int32 x=minBlockX; x<=maxBlockX; ++x ) + for( int32 x = minBlockX; x <= maxBlockX; ++x ) { Vector3 vplToCell = Vector3( x - blockX, y - blockY, z - blockZ ); vplToCell *= cellSize; @@ -1856,26 +1797,28 @@ namespace Ogre if( vplToCell.dotProduct( vpl.normal ) < 0 ) continue; - Real atten = Real(1.0f) / - (mVplConstAtten + (mVplLinearAtten + - mVplQuadAtten * distance) * distance); - atten = std::min( Real(1.0f), atten ); + Real atten = Real( 1.0f ) / + ( mVplConstAtten + + ( mVplLinearAtten + mVplQuadAtten * distance ) * distance ); + atten = std::min( Real( 1.0f ), atten ); if( fadeAttenuationOverDistance ) - atten *= std::max( (range - distance) / range, Ogre::Real( 0.0f ) ); + atten *= std::max( ( range - distance ) / range, Ogre::Real( 0.0f ) ); const Vector3 diffuseCol = vpl.diffuse * invMaxPower * atten; - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) { if( x != blockX || y != blockY || z != blockZ ) { - Vector3 finalCol = std::max( - -vplToCell.dotProduct( c_directions[i] ), - Real( 0.0f ) ) * diffuseCol; + Vector3 finalCol = + std::max( -vplToCell.dotProduct( c_directions[i] ), + Real( 0.0f ) ) * + diffuseCol; volume->changeVolumeData( x, y, z, i, finalCol ); } else { - volume->changeVolumeData( x, y, z, i, vpl.dirDiffuse[i] * invMaxPower ); + volume->changeVolumeData( x, y, z, i, + vpl.dirDiffuse[i] * invMaxPower ); } } } @@ -1896,43 +1839,45 @@ namespace Ogre InstantRadiosity::SparseCluster::SparseCluster( int32 blockX, int32 blockY, int32 blockZ, const Vector3 &_diffuse, const Vector3 &dir, const Vector3 _dirDiffuse[6] ) : - diffuse( _diffuse ), direction( dir ) + diffuse( _diffuse ), + direction( dir ) { blockHash[0] = blockX; blockHash[1] = blockY; blockHash[2] = blockZ; - memcpy( dirDiffuse, _dirDiffuse, sizeof(dirDiffuse) ); + memcpy( dirDiffuse, _dirDiffuse, sizeof( dirDiffuse ) ); } //----------------------------------------------------------------------------------- InstantRadiosity::SparseCluster::SparseCluster( int32 _blockHash[3] ) : - diffuse( Vector3::ZERO ), direction( Vector3::ZERO ) + diffuse( Vector3::ZERO ), + direction( Vector3::ZERO ) { blockHash[0] = _blockHash[0]; blockHash[1] = _blockHash[1]; blockHash[2] = _blockHash[2]; - memset( dirDiffuse, 0, sizeof(dirDiffuse) ); + memset( dirDiffuse, 0, sizeof( dirDiffuse ) ); } //----------------------------------------------------------------------------------- - bool InstantRadiosity::SparseCluster::operator () ( const SparseCluster &_l, int32 _r[3] ) const + bool InstantRadiosity::SparseCluster::operator()( const SparseCluster &_l, int32 _r[3] ) const { return memcmp( _l.blockHash, _r, sizeof( blockHash ) ) < 0; } - bool InstantRadiosity::SparseCluster::operator () ( int32 _l[3], const SparseCluster &_r ) const + bool InstantRadiosity::SparseCluster::operator()( int32 _l[3], const SparseCluster &_r ) const { return memcmp( _l, _r.blockHash, sizeof( blockHash ) ) < 0; } - bool InstantRadiosity::SparseCluster::operator () ( const SparseCluster &_l, - const SparseCluster &_r ) const + bool InstantRadiosity::SparseCluster::operator()( const SparseCluster &_l, + const SparseCluster &_r ) const { return memcmp( _l.blockHash, _r.blockHash, sizeof( blockHash ) ) < 0; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- - float* InstantRadiosity::MeshData::getUvStart( uint8_t uvSet ) const + float *InstantRadiosity::MeshData::getUvStart( uint8_t uvSet ) const { return vertexData + numVertices * 3u + uvSet * 2u; } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp index 12b2af0c6fb..41cbfac3c33 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsJsonPbs.cpp @@ -30,37 +30,36 @@ THE SOFTWARE. #if !OGRE_NO_JSON -#include "OgreHlmsJsonPbs.h" -#include "OgreHlmsManager.h" -#include "OgreTextureGpuManager.h" -#include "OgreTextureFilters.h" +# include "OgreHlmsJsonPbs.h" -#include "OgreLwString.h" +# include "OgreHlmsManager.h" +# include "OgreTextureFilters.h" +# include "OgreTextureGpuManager.h" -#include "OgreStringConverter.h" +# include "OgreLwString.h" -#include "rapidjson/document.h" +# include "OgreStringConverter.h" + +# include "rapidjson/document.h" namespace Ogre { extern const String c_pbsBlendModes[]; - const char* c_workflows[HlmsPbsDatablock::MetallicWorkflow+1] = - { - "specular_ogre", - "specular_fresnel", + const char *c_workflows[HlmsPbsDatablock::MetallicWorkflow + 1] = { // + "specular_ogre", // + "specular_fresnel", // "metallic" }; - const char* c_transparencyModes[HlmsPbsDatablock::Refractive+1] = - { - "None", - "Transparent", - "Fade", + const char *c_transparencyModes[HlmsPbsDatablock::Refractive + 1] = { // + "None", // + "Transparent", // + "Fade", // "Refractive" }; HlmsJsonPbs::HlmsJsonPbs( HlmsManager *hlmsManager, TextureGpuManager *textureManager, - HlmsJsonListener *listener, const String &additionalExtension ) : + HlmsJsonListener *listener, const String &additionalExtension ) : mHlmsManager( hlmsManager ), mTextureManager( textureManager ), mListener( listener ), @@ -118,7 +117,7 @@ namespace Ogre //----------------------------------------------------------------------------------- PbsBlendModes HlmsJsonPbs::parseBlendMode( const char *value ) { - for( int i=0; i( i ); @@ -131,30 +130,30 @@ namespace Ogre { if( !strcmp( value, "coeff" ) ) { - outUseIOR = false; - outIsColoured = false; + outUseIOR = false; + outIsColoured = false; } else if( !strcmp( value, "ior" ) ) { - outUseIOR = true; - outIsColoured = false; + outUseIOR = true; + outIsColoured = false; } else if( !strcmp( value, "coloured" ) ) { - outUseIOR = false; - outIsColoured = true; + outUseIOR = false; + outIsColoured = true; } else if( !strcmp( value, "coloured_ior" ) ) { - outUseIOR = true; - outIsColoured = true; + outUseIOR = true; + outIsColoured = true; } } //----------------------------------------------------------------------------------- void HlmsJsonPbs::parseOffset( const rapidjson::Value &jsonArray, Vector4 &offsetScale ) { const rapidjson::SizeType arraySize = std::min( 2u, jsonArray.Size() ); - for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); @@ -164,10 +163,10 @@ namespace Ogre void HlmsJsonPbs::parseScale( const rapidjson::Value &jsonArray, Vector4 &offsetScale ) { const rapidjson::SizeType arraySize = std::min( 2u, jsonArray.Size() ); - for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); + offsetScale[i + 2u] = static_cast( jsonArray[i].GetDouble() ); } } //----------------------------------------------------------------------------------- @@ -180,8 +179,8 @@ namespace Ogre rapidjson::Value::ConstMemberIterator itor = json.FindMember( "texture" ); if( itor != json.MemberEnd() && - (itor->value.IsString() || (itor->value.IsArray() && itor->value.Size() == 2u && - itor->value[0].IsString() && itor->value[1].IsString())) ) + ( itor->value.IsString() || ( itor->value.IsArray() && itor->value.Size() == 2u && + itor->value[0].IsString() && itor->value[1].IsString() ) ) ) { char const *textureName = 0; char const *aliasName = 0; @@ -198,7 +197,7 @@ namespace Ogre if( textureType == PBSM_DIFFUSE ) { - itor = json.FindMember("grayscale"); + itor = json.FindMember( "grayscale" ); if( itor != json.MemberEnd() && itor->value.IsBool() ) { datablock->setUseDiffuseMapAsGrayscale( itor->value.GetBool() ); @@ -229,18 +228,16 @@ namespace Ogre uint32 filters = TextureFilter::TypeGenerateDefaultMipmaps; filters |= datablock->suggestFiltersForType( textureType ); - texture = mTextureManager->createOrRetrieveTexture( textureName + mAdditionalExtension, - aliasName, - GpuPageOutStrategy::Discard, - textureFlags, internalTextureType, - resourceGroup, filters ); + texture = mTextureManager->createOrRetrieveTexture( + textureName + mAdditionalExtension, aliasName, GpuPageOutStrategy::Discard, textureFlags, + internalTextureType, resourceGroup, filters ); } itor = json.FindMember( "sampler" ); if( itor != json.MemberEnd() && itor->value.IsString() ) { - map::type::const_iterator it = - blocks.samplerblocks.find( LwConstString::FromUnsafeCStr(itor->value.GetString()) ); + map::type::const_iterator it = + blocks.samplerblocks.find( LwConstString::FromUnsafeCStr( itor->value.GetString() ) ); if( it != blocks.samplerblocks.end() ) { samplerblock = it->second; @@ -248,14 +245,14 @@ namespace Ogre } } - if (texture) + if( texture ) { - if (!samplerblock) - samplerblock = mHlmsManager->getSamplerblock(HlmsSamplerblock()); - datablock->_setTexture(textureType, texture, samplerblock); + if( !samplerblock ) + samplerblock = mHlmsManager->getSamplerblock( HlmsSamplerblock() ); + datablock->_setTexture( textureType, texture, samplerblock ); } - else if (samplerblock) - datablock->_setSamplerblock(textureType, samplerblock); + else if( samplerblock ) + datablock->_setSamplerblock( textureType, samplerblock ); itor = json.FindMember( "uv" ); if( itor != json.MemberEnd() && itor->value.IsUint() ) @@ -270,7 +267,7 @@ namespace Ogre Vector3 retVal( Vector3::ZERO ); const rapidjson::SizeType arraySize = std::min( 3u, jsonArray.Size() ); - for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); @@ -284,7 +281,7 @@ namespace Ogre Vector4 retVal( Vector4::ZERO ); const rapidjson::SizeType arraySize = std::min( 4u, jsonArray.Size() ); - for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); @@ -299,7 +296,7 @@ namespace Ogre ColourValue retVal( defaultValue ); const rapidjson::SizeType arraySize = std::min( 4u, jsonArray.Size() ); - for( rapidjson::SizeType i=0; i( jsonArray[i].GetDouble() ); @@ -311,29 +308,29 @@ namespace Ogre void HlmsJsonPbs::loadMaterial( const rapidjson::Value &json, const HlmsJson::NamedBlocks &blocks, HlmsDatablock *datablock, const String &resourceGroup ) { - assert( dynamic_cast(datablock) ); - HlmsPbsDatablock *pbsDatablock = static_cast(datablock); + assert( dynamic_cast( datablock ) ); + HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); - rapidjson::Value::ConstMemberIterator itor = json.FindMember("workflow"); + rapidjson::Value::ConstMemberIterator itor = json.FindMember( "workflow" ); if( itor != json.MemberEnd() && itor->value.IsString() ) pbsDatablock->setWorkflow( parseWorkflow( itor->value.GetString() ) ); - itor = json.FindMember("brdf"); + itor = json.FindMember( "brdf" ); if( itor != json.MemberEnd() && itor->value.IsString() ) - pbsDatablock->setBrdf( parseBrdf(itor->value.GetString()) ); + pbsDatablock->setBrdf( parseBrdf( itor->value.GetString() ) ); - itor = json.FindMember("two_sided"); + itor = json.FindMember( "two_sided" ); if( itor != json.MemberEnd() && itor->value.IsBool() ) { pbsDatablock->setTwoSidedLighting( itor->value.GetBool(), true, - pbsDatablock->getMacroblock(true)->mCullMode ); + pbsDatablock->getMacroblock( true )->mCullMode ); } itor = json.FindMember( "receive_shadows" ); if( itor != json.MemberEnd() && itor->value.IsBool() ) pbsDatablock->setReceiveShadows( itor->value.GetBool() ); - itor = json.FindMember("transparency"); + itor = json.FindMember( "transparency" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -355,8 +352,8 @@ namespace Ogre useAlphaFromTextures = itor->value.GetBool(); const bool changeBlendblock = !json.HasMember( "blendblock" ); - pbsDatablock->setTransparency( transparencyValue, transpMode, - useAlphaFromTextures, changeBlendblock ); + pbsDatablock->setTransparency( transparencyValue, transpMode, useAlphaFromTextures, + changeBlendblock ); } itor = json.FindMember( "clear_coat" ); @@ -373,7 +370,7 @@ namespace Ogre pbsDatablock->setClearCoatRoughness( static_cast( itor->value.GetDouble() ) ); } - itor = json.FindMember("diffuse"); + itor = json.FindMember( "diffuse" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -388,7 +385,7 @@ namespace Ogre pbsDatablock->setBackgroundDiffuse( parseColourValueArray( itor->value ) ); } - itor = json.FindMember("specular"); + itor = json.FindMember( "specular" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -399,7 +396,7 @@ namespace Ogre pbsDatablock->setSpecular( parseVector3Array( itor->value ) ); } - itor = json.FindMember("roughness"); + itor = json.FindMember( "roughness" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -410,7 +407,7 @@ namespace Ogre pbsDatablock->setRoughness( static_cast( itor->value.GetDouble() ) ); } - itor = json.FindMember("fresnel"); + itor = json.FindMember( "fresnel" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -423,7 +420,7 @@ namespace Ogre parseFresnelMode( itor->value.GetString(), isColoured, useIOR ); itor = subobj.FindMember( "value" ); - if( itor != subobj.MemberEnd() && (itor->value.IsArray() || itor->value.IsNumber()) ) + if( itor != subobj.MemberEnd() && ( itor->value.IsArray() || itor->value.IsNumber() ) ) { Vector3 value; if( itor->value.IsArray() ) @@ -438,10 +435,10 @@ namespace Ogre } } - //There used to be a typo, so allow the wrong spelling. - itor = json.FindMember("metalness"); + // There used to be a typo, so allow the wrong spelling. + itor = json.FindMember( "metalness" ); if( itor == json.MemberEnd() ) - itor = json.FindMember("metallness"); + itor = json.FindMember( "metallness" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { @@ -453,7 +450,7 @@ namespace Ogre pbsDatablock->setMetalness( static_cast( itor->value.GetDouble() ) ); } - itor = json.FindMember("normal"); + itor = json.FindMember( "normal" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -464,23 +461,23 @@ namespace Ogre pbsDatablock->setNormalMapWeight( static_cast( itor->value.GetDouble() ) ); } - itor = json.FindMember("detail_weight"); + itor = json.FindMember( "detail_weight" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_DETAIL_WEIGHT, pbsDatablock, resourceGroup ); } - for( int i=0; i<4; ++i ) + for( int i = 0; i < 4; ++i ) { - const String iAsStr = StringConverter::toString(i); + const String iAsStr = StringConverter::toString( i ); String texTypeName = "detail_diffuse" + iAsStr; - itor = json.FindMember(texTypeName.c_str()); + itor = json.FindMember( texTypeName.c_str() ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; - loadTexture( subobj, blocks, static_cast(PBSM_DETAIL0 + i), + loadTexture( subobj, blocks, static_cast( PBSM_DETAIL0 + i ), pbsDatablock, resourceGroup ); itor = subobj.FindMember( "value" ); @@ -505,11 +502,11 @@ namespace Ogre } texTypeName = "detail_normal" + iAsStr; - itor = json.FindMember(texTypeName.c_str()); + itor = json.FindMember( texTypeName.c_str() ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; - loadTexture( subobj, blocks, static_cast(PBSM_DETAIL0_NM + i), + loadTexture( subobj, blocks, static_cast( PBSM_DETAIL0_NM + i ), pbsDatablock, resourceGroup ); itor = subobj.FindMember( "value" ); @@ -533,7 +530,7 @@ namespace Ogre } } - itor = json.FindMember("emissive"); + itor = json.FindMember( "emissive" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -544,7 +541,7 @@ namespace Ogre pbsDatablock->setEmissive( parseVector3Array( itor->value ) ); } - itor = json.FindMember("reflection"); + itor = json.FindMember( "reflection" ); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; @@ -623,46 +620,41 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsJsonPbs::saveFresnel( const HlmsPbsDatablock *datablock, String &outString ) { - saveTexture( datablock->getFresnel(), ColourValue::ZERO, "fresnel", PBSM_SPECULAR, - true, false, true, true, - datablock->getWorkflow() == HlmsPbsDatablock::SpecularAsFresnelWorkflow, + saveTexture( datablock->getFresnel(), ColourValue::ZERO, "fresnel", PBSM_SPECULAR, true, false, + true, true, datablock->getWorkflow() == HlmsPbsDatablock::SpecularAsFresnelWorkflow, datablock, outString ); } //----------------------------------------------------------------------------------- - void HlmsJsonPbs::saveTexture( const char *blockName, - PbsTextureTypes textureType, + void HlmsJsonPbs::saveTexture( const char *blockName, PbsTextureTypes textureType, const HlmsPbsDatablock *datablock, String &outString, bool writeTexture ) { - saveTexture( Vector3(0.0f), ColourValue::ZERO, blockName, textureType, - false, false, false, false, writeTexture, datablock, outString); + saveTexture( Vector3( 0.0f ), ColourValue::ZERO, blockName, textureType, false, false, false, + false, writeTexture, datablock, outString ); } //----------------------------------------------------------------------------------- - void HlmsJsonPbs::saveTexture( float value, const char *blockName, - PbsTextureTypes textureType, + void HlmsJsonPbs::saveTexture( float value, const char *blockName, PbsTextureTypes textureType, const HlmsPbsDatablock *datablock, String &outString, bool writeTexture ) { - saveTexture( Vector3(value), ColourValue::ZERO, blockName, textureType, - true, false, true, false, writeTexture, datablock, outString); + saveTexture( Vector3( value ), ColourValue::ZERO, blockName, textureType, true, false, true, + false, writeTexture, datablock, outString ); } //----------------------------------------------------------------------------------- - void HlmsJsonPbs::saveTexture(const Vector3 &value, const char *blockName, - PbsTextureTypes textureType, - const HlmsPbsDatablock *datablock, String &outString, - bool writeTexture, const ColourValue &bgColour ) + void HlmsJsonPbs::saveTexture( const Vector3 &value, const char *blockName, + PbsTextureTypes textureType, const HlmsPbsDatablock *datablock, + String &outString, bool writeTexture, const ColourValue &bgColour ) { const bool writeBgDiffuse = textureType == PBSM_DIFFUSE; - saveTexture( value, bgColour, blockName, textureType, - true, writeBgDiffuse, false, false, writeTexture, - datablock, outString ); + saveTexture( value, bgColour, blockName, textureType, true, writeBgDiffuse, false, false, + writeTexture, datablock, outString ); } //----------------------------------------------------------------------------------- void HlmsJsonPbs::saveTexture( const Vector3 &value, const ColourValue &bgDiffuse, - const char *blockName, PbsTextureTypes textureType, - bool writeValue, bool writeBgDiffuse, bool scalarValue, - bool isFresnel, bool writeTexture, - const HlmsPbsDatablock *datablock, String &outString ) + const char *blockName, PbsTextureTypes textureType, bool writeValue, + bool writeBgDiffuse, bool scalarValue, bool isFresnel, + bool writeTexture, const HlmsPbsDatablock *datablock, + String &outString ) { outString += ",\n\t\t\t\""; outString += blockName; @@ -710,7 +702,7 @@ namespace Ogre } const Vector4 &offsetScale = - datablock->getDetailMapOffsetScale( textureType - PBSM_DETAIL0 ); + datablock->getDetailMapOffsetScale( textureType - PBSM_DETAIL0 ); const Vector2 offset( offsetScale.x, offsetScale.y ); const Vector2 scale( offsetScale.z, offsetScale.w ); @@ -754,8 +746,8 @@ namespace Ogre outString += finalTexName; outString += '"'; } - - if(textureType == PBSM_DIFFUSE && datablock->getUseDiffuseMapAsGrayscale()) + + if( textureType == PBSM_DIFFUSE && datablock->getUseDiffuseMapAsGrayscale() ) { outString += ",\n\t\t\t\t\"grayscale\" : true"; } @@ -783,7 +775,7 @@ namespace Ogre if( !writeValue && outString.size() != currentOffset ) { - //Remove an extra comma and newline characters. + // Remove an extra comma and newline characters. outString.erase( currentOffset, 2 ); } @@ -792,8 +784,8 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsJsonPbs::saveMaterial( const HlmsDatablock *datablock, String &outString ) { - assert( dynamic_cast(datablock) ); - const HlmsPbsDatablock *pbsDatablock = static_cast(datablock); + assert( dynamic_cast( datablock ) ); + const HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); outString += ",\n\t\t\t\"workflow\" : "; toQuotedStr( pbsDatablock->getWorkflow(), outString ); @@ -834,10 +826,9 @@ namespace Ogre outString += "\n\t\t\t}"; } - saveTexture( pbsDatablock->getDiffuse(), "diffuse", PBSM_DIFFUSE, - pbsDatablock, outString, true, pbsDatablock->getBackgroundDiffuse() ); - saveTexture( pbsDatablock->getSpecular(), "specular", PBSM_SPECULAR, - pbsDatablock, outString, + saveTexture( pbsDatablock->getDiffuse(), "diffuse", PBSM_DIFFUSE, pbsDatablock, outString, true, + pbsDatablock->getBackgroundDiffuse() ); + saveTexture( pbsDatablock->getSpecular(), "specular", PBSM_SPECULAR, pbsDatablock, outString, pbsDatablock->getWorkflow() == HlmsPbsDatablock::SpecularWorkflow ); if( pbsDatablock->getWorkflow() != HlmsPbsDatablock::MetallicWorkflow ) { @@ -845,68 +836,66 @@ namespace Ogre } else { - saveTexture( pbsDatablock->getMetalness(), "metalness", PBSM_METALLIC, - pbsDatablock, outString ); + saveTexture( pbsDatablock->getMetalness(), "metalness", PBSM_METALLIC, pbsDatablock, + outString ); } - if( pbsDatablock->getNormalMapWeight() != 1.0f || - pbsDatablock->getTexture( PBSM_NORMAL ) ) + if( pbsDatablock->getNormalMapWeight() != 1.0f || pbsDatablock->getTexture( PBSM_NORMAL ) ) { - saveTexture( pbsDatablock->getNormalMapWeight(), "normal", PBSM_NORMAL, - pbsDatablock, outString ); + saveTexture( pbsDatablock->getNormalMapWeight(), "normal", PBSM_NORMAL, pbsDatablock, + outString ); } - saveTexture( pbsDatablock->getRoughness(), "roughness", PBSM_ROUGHNESS, - pbsDatablock, outString ); + saveTexture( pbsDatablock->getRoughness(), "roughness", PBSM_ROUGHNESS, pbsDatablock, + outString ); if( pbsDatablock->getTexture( PBSM_DETAIL_WEIGHT ) ) saveTexture( "detail_weight", PBSM_DETAIL_WEIGHT, pbsDatablock, outString ); - for( int i=0; i<4; ++i ) + for( int i = 0; i < 4; ++i ) { PbsBlendModes blendMode = pbsDatablock->getDetailMapBlendMode( i ); const Vector4 &offsetScale = pbsDatablock->getDetailMapOffsetScale( i ); const Vector2 offset( offsetScale.x, offsetScale.y ); const Vector2 scale( offsetScale.z, offsetScale.w ); - const PbsTextureTypes textureType = static_cast(PBSM_DETAIL0 + i); + const PbsTextureTypes textureType = static_cast( PBSM_DETAIL0 + i ); if( blendMode != PBSM_BLEND_NORMAL_NON_PREMUL || offset != Vector2::ZERO || scale != Vector2::UNIT_SCALE || pbsDatablock->getDetailMapWeight( i ) != 1.0f || pbsDatablock->getTexture( textureType ) ) { char tmpBuffer[64]; - LwString blockName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString blockName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); blockName.a( "detail_diffuse", i ); saveTexture( pbsDatablock->getDetailMapWeight( i ), blockName.c_str(), - static_cast(PBSM_DETAIL0 + i), pbsDatablock, - outString ); + static_cast( PBSM_DETAIL0 + i ), pbsDatablock, outString ); } } - for( int i=0; i<4; ++i ) + for( int i = 0; i < 4; ++i ) { - const PbsTextureTypes textureType = static_cast(PBSM_DETAIL0_NM + i); + const PbsTextureTypes textureType = static_cast( PBSM_DETAIL0_NM + i ); if( pbsDatablock->getDetailNormalWeight( i ) != 1.0f || pbsDatablock->getTexture( textureType ) ) { char tmpBuffer[64]; - LwString blockName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString blockName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); blockName.a( "detail_normal", i ); saveTexture( pbsDatablock->getDetailNormalWeight( i ), blockName.c_str(), - static_cast(PBSM_DETAIL0_NM + i), pbsDatablock, + static_cast( PBSM_DETAIL0_NM + i ), pbsDatablock, outString ); } } if( pbsDatablock->_hasEmissive() ) { - saveTexture( pbsDatablock->getEmissive(), "emissive", PBSM_EMISSIVE, - pbsDatablock, outString ); + saveTexture( pbsDatablock->getEmissive(), "emissive", PBSM_EMISSIVE, pbsDatablock, + outString ); } if( pbsDatablock->getTexture( PBSM_REFLECTION ) ) @@ -948,12 +937,12 @@ namespace Ogre } //----------------------------------------------------------------------------------- void HlmsJsonPbs::collectSamplerblocks( const HlmsDatablock *datablock, - set::type &outSamplerblocks ) + set::type &outSamplerblocks ) { - assert( dynamic_cast(datablock) ); - const HlmsPbsDatablock *pbsDatablock = static_cast(datablock); + assert( dynamic_cast( datablock ) ); + const HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); - for( int i=0; i( i ); const HlmsSamplerblock *samplerblock = pbsDatablock->getSamplerblock( textureType ); @@ -961,6 +950,6 @@ namespace Ogre outSamplerblocks.insert( samplerblock ); } } -} +} // namespace Ogre #endif diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp index 8ed13395c5f..1af832982d2 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp @@ -29,53 +29,49 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "OgreHlmsPbs.h" -#include "OgreHlmsPbsDatablock.h" -#include "OgreHlmsManager.h" + #include "OgreHlmsListener.h" +#include "OgreHlmsManager.h" +#include "OgreHlmsPbsDatablock.h" #include "OgreLwString.h" #if !OGRE_NO_JSON - #include "OgreHlmsJsonPbs.h" +# include "OgreHlmsJsonPbs.h" #endif -#include "OgreViewport.h" +#include "Animation/OgreSkeletonInstance.h" +#include "CommandBuffer/OgreCbShaderBuffer.h" +#include "CommandBuffer/OgreCbTexture.h" +#include "CommandBuffer/OgreCommandBuffer.h" +#include "Compositor/OgreCompositorShadowNode.h" +#include "Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h" +#include "Cubemaps/OgreParallaxCorrectedCubemap.h" +#include "IrradianceField/OgreIrradianceField.h" #include "OgreCamera.h" -#include "OgreHighLevelGpuProgramManager.h" -#include "OgreHighLevelGpuProgram.h" -#include "OgreRootLayout.h" #include "OgreForward3D.h" -#include "Cubemaps/OgreParallaxCorrectedCubemap.h" +#include "OgreHighLevelGpuProgram.h" +#include "OgreHighLevelGpuProgramManager.h" #include "OgreIrradianceVolume.h" -#include "Vct/OgreVctLighting.h" -#include "IrradianceField/OgreIrradianceField.h" - -#include "OgreSceneManager.h" +#include "OgrePixelFormatGpuUtils.h" #include "OgreRenderQueue.h" -#include "Compositor/OgreCompositorShadowNode.h" -#include "Vao/OgreVaoManager.h" +#include "OgreRootLayout.h" +#include "OgreSceneManager.h" +#include "OgreTextureGpu.h" +#include "OgreTextureGpuManager.h" +#include "OgreViewport.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreReadOnlyBufferPacked.h" +#include "Vao/OgreVaoManager.h" #include "Vao/OgreVertexArrayObject.h" - -#include "CommandBuffer/OgreCommandBuffer.h" -#include "CommandBuffer/OgreCbTexture.h" -#include "CommandBuffer/OgreCbShaderBuffer.h" - -#include "Animation/OgreSkeletonInstance.h" - -#include "Compositor/Pass/PassScene/OgreCompositorPassSceneDef.h" - -#include "OgreTextureGpu.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreTextureGpuManager.h" +#include "Vct/OgreVctLighting.h" #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS - #include "OgrePlanarReflections.h" +# include "OgrePlanarReflections.h" #endif -#include "OgreStackVector.h" #include "OgreLogManager.h" #include "OgreProfiler.h" +#include "OgreStackVector.h" #define TODO_irradianceField_samplerblock @@ -83,138 +79,140 @@ namespace Ogre { static const TextureGpuVec c_emptyTextureContainer; - const IdString PbsProperty::useLightBuffers = IdString("use_light_buffers"); + const IdString PbsProperty::useLightBuffers = IdString( "use_light_buffers" ); - const IdString PbsProperty::HwGammaRead = IdString( "hw_gamma_read" ); - const IdString PbsProperty::HwGammaWrite = IdString( "hw_gamma_write" ); - const IdString PbsProperty::MaterialsPerBuffer= IdString( "materials_per_buffer" ); - const IdString PbsProperty::LowerGpuOverhead = IdString( "lower_gpu_overhead" ); - const IdString PbsProperty::DebugPssmSplits = IdString( "debug_pssm_splits" ); - const IdString PbsProperty::PerceptualRoughness=IdString( "perceptual_roughness" ); - const IdString PbsProperty::HasPlanarReflections=IdString( "has_planar_reflections" ); + const IdString PbsProperty::HwGammaRead = IdString( "hw_gamma_read" ); + const IdString PbsProperty::HwGammaWrite = IdString( "hw_gamma_write" ); + const IdString PbsProperty::MaterialsPerBuffer = IdString( "materials_per_buffer" ); + const IdString PbsProperty::LowerGpuOverhead = IdString( "lower_gpu_overhead" ); + const IdString PbsProperty::DebugPssmSplits = IdString( "debug_pssm_splits" ); + const IdString PbsProperty::PerceptualRoughness = IdString( "perceptual_roughness" ); + const IdString PbsProperty::HasPlanarReflections = IdString( "has_planar_reflections" ); - const IdString PbsProperty::Set0TextureSlotEnd = IdString( "set0_texture_slot_end" ); - const IdString PbsProperty::Set1TextureSlotEnd = IdString( "set1_texture_slot_end" ); - const IdString PbsProperty::NumTextures = IdString( "num_textures" ); - const IdString PbsProperty::NumSamplers = IdString( "num_samplers" ); + const IdString PbsProperty::Set0TextureSlotEnd = IdString( "set0_texture_slot_end" ); + const IdString PbsProperty::Set1TextureSlotEnd = IdString( "set1_texture_slot_end" ); + const IdString PbsProperty::NumTextures = IdString( "num_textures" ); + const IdString PbsProperty::NumSamplers = IdString( "num_samplers" ); const IdString PbsProperty::DiffuseMapGrayscale = IdString( "diffuse_map_grayscale" ); - const IdString PbsProperty::EmissiveMapGrayscale= IdString( "emissive_map_grayscale" ); - const char *PbsProperty::DiffuseMap = "diffuse_map"; - const char *PbsProperty::NormalMapTex = "normal_map_tex"; - const char *PbsProperty::SpecularMap = "specular_map"; - const char *PbsProperty::RoughnessMap = "roughness_map"; - const char *PbsProperty::EmissiveMap = "emissive_map"; - const char *PbsProperty::EnvProbeMap = "envprobe_map"; - const char *PbsProperty::DetailWeightMap = "detail_weight_map"; - const char *PbsProperty::DetailMapN = "detail_map"; //detail_map0-4 - const char *PbsProperty::DetailMapNmN = "detail_map_nm"; //detail_map_nm0-4 - - const IdString PbsProperty::DetailMap0 = "detail_map0"; - const IdString PbsProperty::DetailMap1 = "detail_map1"; - const IdString PbsProperty::DetailMap2 = "detail_map2"; - const IdString PbsProperty::DetailMap3 = "detail_map3"; - - const IdString PbsProperty::NormalMap = IdString( "normal_map" ); - - const IdString PbsProperty::FresnelScalar = IdString( "fresnel_scalar" ); - const IdString PbsProperty::UseTextureAlpha = IdString( "use_texture_alpha" ); - const IdString PbsProperty::TransparentMode = IdString( "transparent_mode" ); - const IdString PbsProperty::FresnelWorkflow = IdString( "fresnel_workflow" ); - const IdString PbsProperty::MetallicWorkflow = IdString( "metallic_workflow" ); - const IdString PbsProperty::TwoSidedLighting = IdString( "two_sided_lighting" ); - const IdString PbsProperty::ReceiveShadows = IdString( "receive_shadows" ); - const IdString PbsProperty::UsePlanarReflections=IdString( "use_planar_reflections" ); - - const IdString PbsProperty::NormalSamplingFormat = IdString( "normal_sampling_format" ); - const IdString PbsProperty::NormalLa = IdString( "normal_la" ); - const IdString PbsProperty::NormalRgUnorm = IdString( "normal_rg_unorm" ); - const IdString PbsProperty::NormalRgSnorm = IdString( "normal_rg_snorm" ); - const IdString PbsProperty::NormalBc3Unorm = IdString( "normal_bc3_unorm" ); - - const IdString PbsProperty::NormalWeight = IdString( "normal_weight" ); - const IdString PbsProperty::NormalWeightTex = IdString( "normal_weight_tex" ); - const IdString PbsProperty::NormalWeightDetail0 = IdString( "normal_weight_detail0" ); - const IdString PbsProperty::NormalWeightDetail1 = IdString( "normal_weight_detail1" ); - const IdString PbsProperty::NormalWeightDetail2 = IdString( "normal_weight_detail2" ); - const IdString PbsProperty::NormalWeightDetail3 = IdString( "normal_weight_detail3" ); - - const IdString PbsProperty::DetailWeights = IdString( "detail_weights" ); - const IdString PbsProperty::DetailOffsets0 = IdString( "detail_offsets0" ); - const IdString PbsProperty::DetailOffsets1 = IdString( "detail_offsets1" ); - const IdString PbsProperty::DetailOffsets2 = IdString( "detail_offsets2" ); - const IdString PbsProperty::DetailOffsets3 = IdString( "detail_offsets3" ); - - const IdString PbsProperty::UvDiffuse = IdString( "uv_diffuse" ); - const IdString PbsProperty::UvNormal = IdString( "uv_normal" ); - const IdString PbsProperty::UvSpecular = IdString( "uv_specular" ); - const IdString PbsProperty::UvRoughness = IdString( "uv_roughness" ); - const IdString PbsProperty::UvDetailWeight = IdString( "uv_detail_weight" ); - const IdString PbsProperty::UvDetail0 = IdString( "uv_detail0" ); - const IdString PbsProperty::UvDetail1 = IdString( "uv_detail1" ); - const IdString PbsProperty::UvDetail2 = IdString( "uv_detail2" ); - const IdString PbsProperty::UvDetail3 = IdString( "uv_detail3" ); - const IdString PbsProperty::UvDetailNm0 = IdString( "uv_detail_nm0" ); - const IdString PbsProperty::UvDetailNm1 = IdString( "uv_detail_nm1" ); - const IdString PbsProperty::UvDetailNm2 = IdString( "uv_detail_nm2" ); - const IdString PbsProperty::UvDetailNm3 = IdString( "uv_detail_nm3" ); - const IdString PbsProperty::UvEmissive = IdString( "uv_emissive" ); - - const IdString PbsProperty::BlendModeIndex0 = IdString( "blend_mode_idx0" ); - const IdString PbsProperty::BlendModeIndex1 = IdString( "blend_mode_idx1" ); - const IdString PbsProperty::BlendModeIndex2 = IdString( "blend_mode_idx2" ); - const IdString PbsProperty::BlendModeIndex3 = IdString( "blend_mode_idx3" ); + const IdString PbsProperty::EmissiveMapGrayscale = IdString( "emissive_map_grayscale" ); + const char *PbsProperty::DiffuseMap = "diffuse_map"; + const char *PbsProperty::NormalMapTex = "normal_map_tex"; + const char *PbsProperty::SpecularMap = "specular_map"; + const char *PbsProperty::RoughnessMap = "roughness_map"; + const char *PbsProperty::EmissiveMap = "emissive_map"; + const char *PbsProperty::EnvProbeMap = "envprobe_map"; + const char *PbsProperty::DetailWeightMap = "detail_weight_map"; + const char *PbsProperty::DetailMapN = "detail_map"; // detail_map0-4 + const char *PbsProperty::DetailMapNmN = "detail_map_nm"; // detail_map_nm0-4 + + const IdString PbsProperty::DetailMap0 = "detail_map0"; + const IdString PbsProperty::DetailMap1 = "detail_map1"; + const IdString PbsProperty::DetailMap2 = "detail_map2"; + const IdString PbsProperty::DetailMap3 = "detail_map3"; + + const IdString PbsProperty::NormalMap = IdString( "normal_map" ); + + const IdString PbsProperty::FresnelScalar = IdString( "fresnel_scalar" ); + const IdString PbsProperty::UseTextureAlpha = IdString( "use_texture_alpha" ); + const IdString PbsProperty::TransparentMode = IdString( "transparent_mode" ); + const IdString PbsProperty::FresnelWorkflow = IdString( "fresnel_workflow" ); + const IdString PbsProperty::MetallicWorkflow = IdString( "metallic_workflow" ); + const IdString PbsProperty::TwoSidedLighting = IdString( "two_sided_lighting" ); + const IdString PbsProperty::ReceiveShadows = IdString( "receive_shadows" ); + const IdString PbsProperty::UsePlanarReflections = IdString( "use_planar_reflections" ); + + const IdString PbsProperty::NormalSamplingFormat = IdString( "normal_sampling_format" ); + const IdString PbsProperty::NormalLa = IdString( "normal_la" ); + const IdString PbsProperty::NormalRgUnorm = IdString( "normal_rg_unorm" ); + const IdString PbsProperty::NormalRgSnorm = IdString( "normal_rg_snorm" ); + const IdString PbsProperty::NormalBc3Unorm = IdString( "normal_bc3_unorm" ); + + const IdString PbsProperty::NormalWeight = IdString( "normal_weight" ); + const IdString PbsProperty::NormalWeightTex = IdString( "normal_weight_tex" ); + const IdString PbsProperty::NormalWeightDetail0 = IdString( "normal_weight_detail0" ); + const IdString PbsProperty::NormalWeightDetail1 = IdString( "normal_weight_detail1" ); + const IdString PbsProperty::NormalWeightDetail2 = IdString( "normal_weight_detail2" ); + const IdString PbsProperty::NormalWeightDetail3 = IdString( "normal_weight_detail3" ); + + const IdString PbsProperty::DetailWeights = IdString( "detail_weights" ); + const IdString PbsProperty::DetailOffsets0 = IdString( "detail_offsets0" ); + const IdString PbsProperty::DetailOffsets1 = IdString( "detail_offsets1" ); + const IdString PbsProperty::DetailOffsets2 = IdString( "detail_offsets2" ); + const IdString PbsProperty::DetailOffsets3 = IdString( "detail_offsets3" ); + + const IdString PbsProperty::UvDiffuse = IdString( "uv_diffuse" ); + const IdString PbsProperty::UvNormal = IdString( "uv_normal" ); + const IdString PbsProperty::UvSpecular = IdString( "uv_specular" ); + const IdString PbsProperty::UvRoughness = IdString( "uv_roughness" ); + const IdString PbsProperty::UvDetailWeight = IdString( "uv_detail_weight" ); + const IdString PbsProperty::UvDetail0 = IdString( "uv_detail0" ); + const IdString PbsProperty::UvDetail1 = IdString( "uv_detail1" ); + const IdString PbsProperty::UvDetail2 = IdString( "uv_detail2" ); + const IdString PbsProperty::UvDetail3 = IdString( "uv_detail3" ); + const IdString PbsProperty::UvDetailNm0 = IdString( "uv_detail_nm0" ); + const IdString PbsProperty::UvDetailNm1 = IdString( "uv_detail_nm1" ); + const IdString PbsProperty::UvDetailNm2 = IdString( "uv_detail_nm2" ); + const IdString PbsProperty::UvDetailNm3 = IdString( "uv_detail_nm3" ); + const IdString PbsProperty::UvEmissive = IdString( "uv_emissive" ); + + const IdString PbsProperty::BlendModeIndex0 = IdString( "blend_mode_idx0" ); + const IdString PbsProperty::BlendModeIndex1 = IdString( "blend_mode_idx1" ); + const IdString PbsProperty::BlendModeIndex2 = IdString( "blend_mode_idx2" ); + const IdString PbsProperty::BlendModeIndex3 = IdString( "blend_mode_idx3" ); const IdString PbsProperty::DetailMapsDiffuse = IdString( "detail_maps_diffuse" ); - const IdString PbsProperty::DetailMapsNormal = IdString( "detail_maps_normal" ); - const IdString PbsProperty::FirstValidDetailMapNm= IdString( "first_valid_detail_map_nm" ); - const IdString PbsProperty::EmissiveConstant = IdString( "emissive_constant" ); - const IdString PbsProperty::EmissiveAsLightmap= IdString( "emissive_as_lightmap" ); - - const IdString PbsProperty::Pcf = IdString( "pcf" ); - const IdString PbsProperty::PcfIterations = IdString( "pcf_iterations" ); - const IdString PbsProperty::ShadowsReceiveOnPs= IdString( "shadows_receive_on_ps" ); - const IdString PbsProperty::ExponentialShadowMaps= IdString( "exponential_shadow_maps" ); - - const IdString PbsProperty::EnvMapScale = IdString( "envmap_scale" ); - const IdString PbsProperty::LightProfilesTexture= IdString( "light_profiles_texture" ); - const IdString PbsProperty::LtcTextureAvailable= IdString( "ltc_texture_available" ); - const IdString PbsProperty::AmbientFixed = IdString( "ambient_fixed" ); + const IdString PbsProperty::DetailMapsNormal = IdString( "detail_maps_normal" ); + const IdString PbsProperty::FirstValidDetailMapNm = IdString( "first_valid_detail_map_nm" ); + const IdString PbsProperty::EmissiveConstant = IdString( "emissive_constant" ); + const IdString PbsProperty::EmissiveAsLightmap = IdString( "emissive_as_lightmap" ); + + const IdString PbsProperty::Pcf = IdString( "pcf" ); + const IdString PbsProperty::PcfIterations = IdString( "pcf_iterations" ); + const IdString PbsProperty::ShadowsReceiveOnPs = IdString( "shadows_receive_on_ps" ); + const IdString PbsProperty::ExponentialShadowMaps = IdString( "exponential_shadow_maps" ); + + const IdString PbsProperty::EnvMapScale = IdString( "envmap_scale" ); + const IdString PbsProperty::LightProfilesTexture = IdString( "light_profiles_texture" ); + const IdString PbsProperty::LtcTextureAvailable = IdString( "ltc_texture_available" ); + const IdString PbsProperty::AmbientFixed = IdString( "ambient_fixed" ); const IdString PbsProperty::AmbientHemisphere = IdString( "ambient_hemisphere" ); - const IdString PbsProperty::AmbientSh = IdString( "ambient_sh" ); - const IdString PbsProperty::AmbientShMonochrome=IdString( "ambient_sh_monochrome" ); + const IdString PbsProperty::AmbientSh = IdString( "ambient_sh" ); + const IdString PbsProperty::AmbientShMonochrome = IdString( "ambient_sh_monochrome" ); const IdString PbsProperty::TargetEnvprobeMap = IdString( "target_envprobe_map" ); const IdString PbsProperty::ParallaxCorrectCubemaps = IdString( "parallax_correct_cubemaps" ); - const IdString PbsProperty::UseParallaxCorrectCubemaps= IdString( "use_parallax_correct_cubemaps" ); - const IdString PbsProperty::EnableCubemapsAuto = IdString( "hlms_enable_cubemaps_auto" ); - const IdString PbsProperty::CubemapsUseDpm = IdString( "hlms_cubemaps_use_dpm" ); - const IdString PbsProperty::CubemapsAsDiffuseGi=IdString( "cubemaps_as_diffuse_gi" ); + const IdString PbsProperty::UseParallaxCorrectCubemaps = IdString( "use_parallax_correct_cubemaps" ); + const IdString PbsProperty::EnableCubemapsAuto = IdString( "hlms_enable_cubemaps_auto" ); + const IdString PbsProperty::CubemapsUseDpm = IdString( "hlms_cubemaps_use_dpm" ); + const IdString PbsProperty::CubemapsAsDiffuseGi = IdString( "cubemaps_as_diffuse_gi" ); const IdString PbsProperty::IrradianceVolumes = IdString( "irradiance_volumes" ); - const IdString PbsProperty::VctNumProbes = IdString( "vct_num_probes" ); - const IdString PbsProperty::VctConeDirs = IdString( "vct_cone_dirs" ); + const IdString PbsProperty::VctNumProbes = IdString( "vct_num_probes" ); + const IdString PbsProperty::VctConeDirs = IdString( "vct_cone_dirs" ); const IdString PbsProperty::VctDisableDiffuse = IdString( "vct_disable_diffuse" ); - const IdString PbsProperty::VctDisableSpecular= IdString( "vct_disable_specular" ); - const IdString PbsProperty::VctAnisotropic = IdString( "vct_anisotropic" ); - const IdString PbsProperty::VctEnableSpecularSdfQuality=IdString("vct_enable_specular_sdf_quality"); - const IdString PbsProperty::VctAmbientSphere = IdString("vct_ambient_hemisphere"); - const IdString PbsProperty::IrradianceField = IdString("irradiance_field"); - const IdString PbsProperty::ObbRestraintApprox= IdString( "obb_restraint_approx" ); - - const IdString PbsProperty::ObbRestraintLtc = IdString( "obb_restraint_ltc" ); - - const IdString PbsProperty::BrdfDefault = IdString( "BRDF_Default" ); - const IdString PbsProperty::BrdfCookTorrance = IdString( "BRDF_CookTorrance" ); - const IdString PbsProperty::BrdfBlinnPhong = IdString( "BRDF_BlinnPhong" ); - const IdString PbsProperty::FresnelSeparateDiffuse = IdString( "fresnel_separate_diffuse" ); - const IdString PbsProperty::GgxHeightCorrelated = IdString( "GGX_height_correlated" ); - const IdString PbsProperty::ClearCoat = IdString( "clear_coat" ); - const IdString PbsProperty::LegacyMathBrdf = IdString( "legacy_math_brdf" ); - const IdString PbsProperty::RoughnessIsShininess = IdString( "roughness_is_shininess" ); - - const IdString PbsProperty::UseEnvProbeMap = IdString( "use_envprobe_map" ); - const IdString PbsProperty::NeedsViewDir = IdString( "needs_view_dir" ); - const IdString PbsProperty::NeedsReflDir = IdString( "needs_refl_dir" ); - const IdString PbsProperty::NeedsEnvBrdf = IdString( "needs_env_brdf" ); - + const IdString PbsProperty::VctDisableSpecular = IdString( "vct_disable_specular" ); + const IdString PbsProperty::VctAnisotropic = IdString( "vct_anisotropic" ); + const IdString PbsProperty::VctEnableSpecularSdfQuality = + IdString( "vct_enable_specular_sdf_quality" ); + const IdString PbsProperty::VctAmbientSphere = IdString( "vct_ambient_hemisphere" ); + const IdString PbsProperty::IrradianceField = IdString( "irradiance_field" ); + const IdString PbsProperty::ObbRestraintApprox = IdString( "obb_restraint_approx" ); + + const IdString PbsProperty::ObbRestraintLtc = IdString( "obb_restraint_ltc" ); + + const IdString PbsProperty::BrdfDefault = IdString( "BRDF_Default" ); + const IdString PbsProperty::BrdfCookTorrance = IdString( "BRDF_CookTorrance" ); + const IdString PbsProperty::BrdfBlinnPhong = IdString( "BRDF_BlinnPhong" ); + const IdString PbsProperty::FresnelSeparateDiffuse = IdString( "fresnel_separate_diffuse" ); + const IdString PbsProperty::GgxHeightCorrelated = IdString( "GGX_height_correlated" ); + const IdString PbsProperty::ClearCoat = IdString( "clear_coat" ); + const IdString PbsProperty::LegacyMathBrdf = IdString( "legacy_math_brdf" ); + const IdString PbsProperty::RoughnessIsShininess = IdString( "roughness_is_shininess" ); + + const IdString PbsProperty::UseEnvProbeMap = IdString( "use_envprobe_map" ); + const IdString PbsProperty::NeedsViewDir = IdString( "needs_view_dir" ); + const IdString PbsProperty::NeedsReflDir = IdString( "needs_refl_dir" ); + const IdString PbsProperty::NeedsEnvBrdf = IdString( "needs_env_brdf" ); + + // clang-format off const IdString *PbsProperty::UvSourcePtrs[NUM_PBSM_SOURCES] = { &PbsProperty::UvDiffuse, @@ -256,6 +254,7 @@ namespace Ogre &PbsProperty::BlendModeIndex2, &PbsProperty::BlendModeIndex3 }; + // clang-format on extern const String c_pbsBlendModes[]; @@ -325,14 +324,11 @@ namespace Ogre { memset( mDecalsTextures, 0, sizeof( mDecalsTextures ) ); - //Override defaults + // Override defaults mLightGatheringMode = LightGatherForwardPlus; } //----------------------------------------------------------------------------------- - HlmsPbs::~HlmsPbs() - { - destroyAllBuffers(); - } + HlmsPbs::~HlmsPbs() { destroyAllBuffers(); } //----------------------------------------------------------------------------------- void HlmsPbs::_changeRenderSystem( RenderSystem *newRs ) { @@ -344,34 +340,34 @@ namespace Ogre if( !mSkipRequestSlotInChangeRS ) { HlmsDatablockMap::const_iterator itor = mDatablocks.begin(); - HlmsDatablockMap::const_iterator end = mDatablocks.end(); + HlmsDatablockMap::const_iterator end = mDatablocks.end(); while( itor != end ) { - assert( dynamic_cast( itor->second.datablock ) ); - HlmsPbsDatablock *datablock = static_cast(itor->second.datablock); + assert( dynamic_cast( itor->second.datablock ) ); + HlmsPbsDatablock *datablock = + static_cast( itor->second.datablock ); requestSlot( datablock->mTextureHash, datablock, false ); ++itor; } } - const ColourValue maxValBorder = ColourValue( std::numeric_limits::max(), - std::numeric_limits::max(), - std::numeric_limits::max(), - std::numeric_limits::max() ); + const ColourValue maxValBorder = + ColourValue( std::numeric_limits::max(), std::numeric_limits::max(), + std::numeric_limits::max(), std::numeric_limits::max() ); const ColourValue pitchBlackBorder = ColourValue( 0, 0, 0, 0 ); HlmsSamplerblock samplerblock; - samplerblock.mU = TAM_BORDER; - samplerblock.mV = TAM_BORDER; - samplerblock.mW = TAM_CLAMP; + samplerblock.mU = TAM_BORDER; + samplerblock.mV = TAM_BORDER; + samplerblock.mW = TAM_CLAMP; if( !mRenderSystem->isReverseDepth() ) - samplerblock.mBorderColour = maxValBorder; + samplerblock.mBorderColour = maxValBorder; else - samplerblock.mBorderColour = pitchBlackBorder; + samplerblock.mBorderColour = pitchBlackBorder; - if( mShaderProfile != "hlsl" && mShaderProfile != "hlslvk" ) + if( mShaderProfile != "hlsl" && mShaderProfile != "hlslvk" ) { samplerblock.mMinFilter = FO_POINT; samplerblock.mMagFilter = FO_POINT; @@ -383,28 +379,28 @@ namespace Ogre if( !mShadowmapEsmSamplerblock ) { - samplerblock.mMinFilter = FO_LINEAR; - samplerblock.mMagFilter = FO_LINEAR; - samplerblock.mMipFilter = FO_NONE; + samplerblock.mMinFilter = FO_LINEAR; + samplerblock.mMagFilter = FO_LINEAR; + samplerblock.mMipFilter = FO_NONE; - //ESM uses standard linear Z in range [0; 1], thus we need a different border colour + // ESM uses standard linear Z in range [0; 1], thus we need a different border colour const ColourValue oldValue = samplerblock.mBorderColour; samplerblock.mBorderColour = maxValBorder; mShadowmapEsmSamplerblock = mHlmsManager->getSamplerblock( samplerblock ); - //Restore border colour + // Restore border colour samplerblock.mBorderColour = oldValue; } - samplerblock.mMinFilter = FO_LINEAR; - samplerblock.mMagFilter = FO_LINEAR; - samplerblock.mMipFilter = FO_NONE; + samplerblock.mMinFilter = FO_LINEAR; + samplerblock.mMagFilter = FO_LINEAR; + samplerblock.mMipFilter = FO_NONE; samplerblock.mCompareFunction = CMPF_LESS_EQUAL; if( mRenderSystem->isReverseDepth() ) { samplerblock.mCompareFunction = - RenderSystem::reverseCompareFunction( samplerblock.mCompareFunction ); + RenderSystem::reverseCompareFunction( samplerblock.mCompareFunction ); } if( !mShadowmapCmpSamplerblock ) @@ -413,42 +409,42 @@ namespace Ogre #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS if( !mPlanarReflectionsSamplerblock ) { - samplerblock.mMinFilter = FO_LINEAR; - samplerblock.mMagFilter = FO_LINEAR; - samplerblock.mMipFilter = FO_LINEAR; - samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; + samplerblock.mMinFilter = FO_LINEAR; + samplerblock.mMagFilter = FO_LINEAR; + samplerblock.mMipFilter = FO_LINEAR; + samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; - samplerblock.mU = TAM_CLAMP; - samplerblock.mV = TAM_CLAMP; - samplerblock.mW = TAM_CLAMP; + samplerblock.mU = TAM_CLAMP; + samplerblock.mV = TAM_CLAMP; + samplerblock.mW = TAM_CLAMP; mPlanarReflectionsSamplerblock = mHlmsManager->getSamplerblock( samplerblock ); } #endif if( !mAreaLightMasksSamplerblock ) { - samplerblock.mMinFilter = FO_LINEAR; - samplerblock.mMagFilter = FO_LINEAR; - samplerblock.mMipFilter = FO_LINEAR; - samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; + samplerblock.mMinFilter = FO_LINEAR; + samplerblock.mMagFilter = FO_LINEAR; + samplerblock.mMipFilter = FO_LINEAR; + samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; - samplerblock.mU = TAM_CLAMP; - samplerblock.mV = TAM_CLAMP; - samplerblock.mW = TAM_CLAMP; + samplerblock.mU = TAM_CLAMP; + samplerblock.mV = TAM_CLAMP; + samplerblock.mW = TAM_CLAMP; mAreaLightMasksSamplerblock = mHlmsManager->getSamplerblock( samplerblock ); } if( !mDecalsSamplerblock ) { - samplerblock.mMinFilter = FO_LINEAR; - samplerblock.mMagFilter = FO_LINEAR; - samplerblock.mMipFilter = FO_LINEAR; - samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; + samplerblock.mMinFilter = FO_LINEAR; + samplerblock.mMagFilter = FO_LINEAR; + samplerblock.mMipFilter = FO_LINEAR; + samplerblock.mCompareFunction = NUM_COMPARE_FUNCTIONS; - samplerblock.mU = TAM_CLAMP; - samplerblock.mV = TAM_CLAMP; - samplerblock.mW = TAM_CLAMP; + samplerblock.mU = TAM_CLAMP; + samplerblock.mV = TAM_CLAMP; + samplerblock.mW = TAM_CLAMP; mDecalsSamplerblock = mHlmsManager->getSamplerblock( samplerblock ); } @@ -486,10 +482,10 @@ namespace Ogre else descBindingRanges[DescBindingTypes::ReadOnlyBuffer].start = 1u; - //if( getProperty( HlmsBaseProp::Pose ) ) - //descBindingRanges[DescBindingTypes::TexBuffer].end = 4u; + // if( getProperty( HlmsBaseProp::Pose ) ) + // descBindingRanges[DescBindingTypes::TexBuffer].end = 4u; - //else + // else { if( getProperty( HlmsBaseProp::ForwardPlus ) ) { @@ -527,8 +523,7 @@ namespace Ogre rootLayout.mBaked[1] = true; DescBindingRange *bakedRanges = rootLayout.mDescBindingRanges[1]; - bakedRanges[DescBindingTypes::Texture].start = - descBindingRanges[DescBindingTypes::Texture].end; + bakedRanges[DescBindingTypes::Texture].start = descBindingRanges[DescBindingTypes::Texture].end; bakedRanges[DescBindingTypes::Texture].end = (uint16)getProperty( PbsProperty::Set1TextureSlotEnd ); @@ -575,29 +570,28 @@ namespace Ogre mListener->setupRootLayout( rootLayout, mSetProperties ); } //----------------------------------------------------------------------------------- - const HlmsCache* HlmsPbs::createShaderCacheEntry( uint32 renderableHash, - const HlmsCache &passCache, - uint32 finalHash, - const QueuedRenderable &queuedRenderable ) + const HlmsCache *HlmsPbs::createShaderCacheEntry( uint32 renderableHash, const HlmsCache &passCache, + uint32 finalHash, + const QueuedRenderable &queuedRenderable ) { OgreProfileExhaustive( "HlmsPbs::createShaderCacheEntry" ); - const HlmsCache *retVal = Hlms::createShaderCacheEntry( renderableHash, passCache, finalHash, - queuedRenderable ); + const HlmsCache *retVal = + Hlms::createShaderCacheEntry( renderableHash, passCache, finalHash, queuedRenderable ); if( mShaderProfile != "glsl" ) { - mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, - mSetProperties, queuedRenderable ); - return retVal; //D3D embeds the texture slots in the shader. + mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, mSetProperties, + queuedRenderable ); + return retVal; // D3D embeds the texture slots in the shader. } GpuProgramParametersSharedPtr vsParams = retVal->pso.vertexShader->getDefaultParameters(); if( mSetupWorldMatBuf && mVaoManager->readOnlyIsTexBuffer() ) vsParams->setNamedConstant( "worldMatBuf", 0 ); - mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, - mSetProperties, queuedRenderable ); + mListener->shaderCacheEntryCreated( mShaderProfile, retVal, passCache, mSetProperties, + queuedRenderable ); mRenderSystem->_setPipelineStateObject( &retVal->pso ); @@ -610,7 +604,7 @@ namespace Ogre if( !mRenderSystem->getCapabilities()->hasCapability( RSC_CONST_BUFFER_SLOTS_IN_SHADER ) ) { - //Setting it to the vertex shader will set it to the PSO actually. + // Setting it to the vertex shader will set it to the PSO actually. retVal->pso.vertexShader->setUniformBlockBinding( "PassBuffer", 0 ); retVal->pso.vertexShader->setUniformBlockBinding( "MaterialBuf", 1 ); retVal->pso.vertexShader->setUniformBlockBinding( "InstanceBuffer", 2 ); @@ -626,18 +620,18 @@ namespace Ogre bool hasDiffuseMaps = false; bool hasNormalMaps = false; bool anyDetailWeight = false; - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) { uint8 blendMode = datablock->mBlendModes[i]; - setDetailTextureProperty( PbsProperty::DetailMapN, datablock, PBSM_DETAIL0, i ); + setDetailTextureProperty( PbsProperty::DetailMapN, datablock, PBSM_DETAIL0, i ); if( !bCasterPass ) setDetailTextureProperty( PbsProperty::DetailMapNmN, datablock, PBSM_DETAIL0_NM, i ); if( datablock->getTexture( PBSM_DETAIL0 + i ) ) { inOutPieces[PixelShader][*PbsProperty::BlendModes[i]] = - "@insertpiece( " + c_pbsBlendModes[blendMode] + ")"; + "@insertpiece( " + c_pbsBlendModes[blendMode] + ")"; hasDiffuseMaps = true; } @@ -677,26 +671,26 @@ namespace Ogre if( idx != NUM_PBSM_TEXTURE_TYPES ) { char tmpData[64]; - LwString propName = LwString::FromEmptyPointer( tmpData, sizeof(tmpData) ); + LwString propName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) ); - propName = propertyName; //diffuse_map + propName = propertyName; // diffuse_map - const size_t basePropSize = propName.size(); // diffuse_map + const size_t basePropSize = propName.size(); // diffuse_map - //In the template the we subtract the "+1" for the index. - //We need to increment it now otherwise @property( diffuse_map ) - //can translate to @property( 0 ) which is not what we want. + // In the template the we subtract the "+1" for the index. + // We need to increment it now otherwise @property( diffuse_map ) + // can translate to @property( 0 ) which is not what we want. setProperty( propertyName, idx + 1 ); propName.resize( basePropSize ); - propName.a( "_idx" ); //diffuse_map_idx + propName.a( "_idx" ); // diffuse_map_idx setProperty( propName.c_str(), idx ); if( mHasSeparateSamplers ) { const uint8 samplerIdx = datablock->getIndexToDescriptorSampler( texType ); propName.resize( basePropSize ); - propName.a( "_sampler" ); //diffuse_map_sampler + propName.a( "_sampler" ); // diffuse_map_sampler setProperty( propName.c_str(), samplerIdx ); } } @@ -707,19 +701,19 @@ namespace Ogre { const PbsTextureTypes texType = static_cast( baseTexType + detailIdx ); char tmpData[32]; - LwString propName = LwString::FromEmptyPointer( tmpData, sizeof(tmpData) ); - propName.a( propertyName, detailIdx ); //detail_map0 + LwString propName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) ); + propName.a( propertyName, detailIdx ); // detail_map0 setTextureProperty( propName.c_str(), datablock, texType ); } //----------------------------------------------------------------------------------- void HlmsPbs::calculateHashFor( Renderable *renderable, uint32 &outHash, uint32 &outCasterHash ) { - assert( dynamic_cast( renderable->getDatablock() ) ); - HlmsPbsDatablock *datablock = static_cast( renderable->getDatablock() ); + assert( dynamic_cast( renderable->getDatablock() ) ); + HlmsPbsDatablock *datablock = static_cast( renderable->getDatablock() ); - if( datablock->getDirtyFlags() & (DirtyTextures|DirtySamplers) ) + if( datablock->getDirtyFlags() & ( DirtyTextures | DirtySamplers ) ) { - //Delay hash generation for later, when we have the final (or temporary) descriptor sets. + // Delay hash generation for later, when we have the final (or temporary) descriptor sets. outHash = 0; outCasterHash = 0; } @@ -733,13 +727,12 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsPbs::calculateHashForPreCreate( Renderable *renderable, PiecesMap *inOutPieces ) { - assert( dynamic_cast( renderable->getDatablock() ) ); - HlmsPbsDatablock *datablock = static_cast( - renderable->getDatablock() ); + assert( dynamic_cast( renderable->getDatablock() ) ); + HlmsPbsDatablock *datablock = static_cast( renderable->getDatablock() ); const bool metallicWorkflow = datablock->getWorkflow() == HlmsPbsDatablock::MetallicWorkflow; - const bool fresnelWorkflow = datablock->getWorkflow() == - HlmsPbsDatablock::SpecularAsFresnelWorkflow; + const bool fresnelWorkflow = + datablock->getWorkflow() == HlmsPbsDatablock::SpecularAsFresnelWorkflow; setProperty( PbsProperty::FresnelScalar, datablock->hasSeparateFresnel() || metallicWorkflow ); setProperty( PbsProperty::FresnelWorkflow, fresnelWorkflow ); @@ -768,18 +761,18 @@ namespace Ogre } uint32 brdf = datablock->getBrdf(); - if( (brdf & PbsBrdf::BRDF_MASK) == PbsBrdf::Default ) + if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::Default ) { setProperty( PbsProperty::BrdfDefault, 1 ); - if( !(brdf & PbsBrdf::FLAG_UNCORRELATED) ) + if( !( brdf & PbsBrdf::FLAG_UNCORRELATED ) ) setProperty( PbsProperty::GgxHeightCorrelated, 1 ); setProperty( PbsProperty::ClearCoat, datablock->mClearCoat != 0.0f ); } - else if( (brdf & PbsBrdf::BRDF_MASK) == PbsBrdf::CookTorrance ) + else if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::CookTorrance ) setProperty( PbsProperty::BrdfCookTorrance, 1 ); - else if( (brdf & PbsBrdf::BRDF_MASK) == PbsBrdf::BlinnPhong ) + else if( ( brdf & PbsBrdf::BRDF_MASK ) == PbsBrdf::BlinnPhong ) setProperty( PbsProperty::BrdfBlinnPhong, 1 ); if( brdf & PbsBrdf::FLAG_SPERATE_DIFFUSE_FRESNEL ) @@ -790,18 +783,17 @@ namespace Ogre if( brdf & PbsBrdf::FLAG_FULL_LEGACY ) setProperty( PbsProperty::RoughnessIsShininess, 1 ); - for( size_t i=0; imUvSource[i]; setProperty( *PbsProperty::UvSourcePtrs[i], uvSource ); - if( datablock->getTexture( i ) && - getProperty( *HlmsBaseProp::UvCountPtrs[uvSource] ) < 2 ) + if( datablock->getTexture( i ) && getProperty( *HlmsBaseProp::UvCountPtrs[uvSource] ) < 2 ) { OGRE_EXCEPT( Exception::ERR_INVALID_STATE, "Renderable needs at least 2 coordinates in UV set #" + - StringConverter::toString( uvSource ) + - ". Either change the mesh, or change the UV source settings", + StringConverter::toString( uvSource ) + + ". Either change the mesh, or change the UV source settings", "HlmsPbs::calculateHashForPreCreate" ); } } @@ -813,7 +805,7 @@ namespace Ogre ++numNormalWeights; } - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) { if( datablock->getTexture( PBSM_DETAIL0_NM + i ) ) { @@ -841,13 +833,13 @@ namespace Ogre setProperty( PbsProperty::NumTextures, datablock->mTexturesDescSet->mTextures.size() - envMap ); - setTextureProperty( PbsProperty::DiffuseMap, datablock, PBSM_DIFFUSE ); - setTextureProperty( PbsProperty::NormalMapTex, datablock, PBSM_NORMAL ); - setTextureProperty( PbsProperty::SpecularMap, datablock, PBSM_SPECULAR ); - setTextureProperty( PbsProperty::RoughnessMap, datablock, PBSM_ROUGHNESS ); - setTextureProperty( PbsProperty::EmissiveMap, datablock, PBSM_EMISSIVE ); - setTextureProperty( PbsProperty::EnvProbeMap, datablock, PBSM_REFLECTION ); - setTextureProperty( PbsProperty::DetailWeightMap,datablock, PBSM_DETAIL_WEIGHT ); + setTextureProperty( PbsProperty::DiffuseMap, datablock, PBSM_DIFFUSE ); + setTextureProperty( PbsProperty::NormalMapTex, datablock, PBSM_NORMAL ); + setTextureProperty( PbsProperty::SpecularMap, datablock, PBSM_SPECULAR ); + setTextureProperty( PbsProperty::RoughnessMap, datablock, PBSM_ROUGHNESS ); + setTextureProperty( PbsProperty::EmissiveMap, datablock, PBSM_EMISSIVE ); + setTextureProperty( PbsProperty::EnvProbeMap, datablock, PBSM_REFLECTION ); + setTextureProperty( PbsProperty::DetailWeightMap, datablock, PBSM_DETAIL_WEIGHT ); if( getProperty( PbsProperty::DiffuseMap ) ) { @@ -865,12 +857,12 @@ namespace Ogre } } - //Save the name of the cubemap for hazard prevention + // Save the name of the cubemap for hazard prevention //(don't sample the cubemap and render to it at the same time). const TextureGpu *reflectionTexture = datablock->getTexture( PBSM_REFLECTION ); if( reflectionTexture ) { - //Manual reflection texture + // Manual reflection texture if( datablock->getCubemapProbe() ) setProperty( PbsProperty::UseParallaxCorrectCubemaps, 1 ); setProperty( PbsProperty::EnvProbeMap, @@ -891,14 +883,14 @@ namespace Ogre } // normal maps used in this datablock - StackVector datablockNormalMaps; + StackVector datablockNormalMaps; // normal maps that are being used and have also been loaded // NB We could just use the loadedNormalMaps for the logic below // however other parts of the code may make assumptions based on // the fact a normal map texture is registered with datablock but not loaded. - StackVector loadedNormalMaps; - TextureGpu* tempTex; + StackVector loadedNormalMaps; + TextureGpu *tempTex; if( ( tempTex = datablock->getTexture( PBSM_NORMAL ) ) != 0 ) { datablockNormalMaps.push_back( tempTex ); @@ -906,11 +898,11 @@ namespace Ogre loadedNormalMaps.push_back( tempTex ); } - for( size_t i=PBSM_DETAIL0_NM; i<=PBSM_DETAIL3_NM; ++i ) + for( size_t i = PBSM_DETAIL0_NM; i <= PBSM_DETAIL3_NM; ++i ) { if( ( tempTex = datablock->getTexture( i ) ) != 0 ) { - datablockNormalMaps.push_back(tempTex); + datablockNormalMaps.push_back( tempTex ); if( tempTex->isMetadataReady() ) loadedNormalMaps.push_back( tempTex ); } @@ -920,16 +912,17 @@ namespace Ogre /*setProperty( HlmsBaseProp::, !datablock->getTexture( PBSM_DETAIL0 ).isNull() ); setProperty( HlmsBaseProp::DiffuseMap, !datablock->getTexture( PBSM_DETAIL1 ).isNull() );*/ - bool normalMapCanBeSupported = (getProperty( HlmsBaseProp::Normal ) && - getProperty( HlmsBaseProp::Tangent )) || - getProperty( HlmsBaseProp::QTangent ); + bool normalMapCanBeSupported = + ( getProperty( HlmsBaseProp::Normal ) && getProperty( HlmsBaseProp::Tangent ) ) || + getProperty( HlmsBaseProp::QTangent ); if( !normalMapCanBeSupported && !datablockNormalMaps.empty() ) { OGRE_EXCEPT( Exception::ERR_INVALID_STATE, "Renderable can't use normal maps but datablock wants normal maps. " "Generate Tangents for this mesh to fix the problem or use a " - "datablock without normal maps.", "HlmsPbs::calculateHashForPreCreate" ); + "datablock without normal maps.", + "HlmsPbs::calculateHashForPreCreate" ); } if( !datablockNormalMaps.empty() ) @@ -939,7 +932,7 @@ namespace Ogre // has loaded, so just assume default for now. PixelFormatGpu nmPixelFormat = datablockNormalMaps[0]->getPixelFormat(); const bool isSigned = PixelFormatGpuUtils::isSigned( nmPixelFormat ); - if (isSigned) + if( isSigned ) { setProperty( PbsProperty::NormalSamplingFormat, PbsProperty::NormalRgSnorm.mHash ); setProperty( PbsProperty::NormalRgSnorm, PbsProperty::NormalRgSnorm.mHash ); @@ -957,12 +950,12 @@ namespace Ogre setProperty( PbsProperty::NormalBc3Unorm, PbsProperty::NormalBc3Unorm.mHash ); } } - //Reserved for supporting LA textures in GLES2. -// else -// { -// setProperty( PbsProperty::NormalSamplingFormat, PbsProperty::NormalLa.mHash ); -// setProperty( PbsProperty::NormalLa, PbsProperty::NormalLa.mHash ); -// } + // Reserved for supporting LA textures in GLES2. + // else + // { + // setProperty( PbsProperty::NormalSamplingFormat, PbsProperty::NormalLa.mHash + // ); setProperty( PbsProperty::NormalLa, PbsProperty::NormalLa.mHash ); + // } } // check and ensure all normal maps use the same signed convention @@ -971,16 +964,17 @@ namespace Ogre const bool isSigned = PixelFormatGpuUtils::isSigned( loadedNormalMaps[0]->getPixelFormat() ); // check normal maps all use the same one convention - for( size_t i=1u; igetPixelFormat() ); + const bool isSignedOther = + PixelFormatGpuUtils::isSigned( loadedNormalMaps[i]->getPixelFormat() ); if( isSignedOther != isSigned ) { - OGRE_EXCEPT( Exception::ERR_INVALID_STATE, + OGRE_EXCEPT( + Exception::ERR_INVALID_STATE, "Renderable can't use normal maps and detailed normal maps which have " - "different signed conventions in the same datablock. e.g. SNORM vs UNORM " - , "HlmsPbs::calculateHashForPreCreate" ); + "different signed conventions in the same datablock. e.g. SNORM vs UNORM ", + "HlmsPbs::calculateHashForPreCreate" ); } } } @@ -995,9 +989,9 @@ namespace Ogre { setProperty( PbsProperty::UseTextureAlpha, 1 ); - //When we don't use the alpha in the texture, transparency still works but - //only at material level (i.e. what datablock->mTransparency says). The - //alpha from the texture will be ignored. + // When we don't use the alpha in the texture, transparency still works but + // only at material level (i.e. what datablock->mTransparency says). The + // alpha from the texture will be ignored. if( datablock->mTransparencyMode == HlmsPbsDatablock::Transparent ) setProperty( PbsProperty::TransparentMode, 1 ); } @@ -1020,11 +1014,11 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsPbs::calculateHashForPreCaster( Renderable *renderable, PiecesMap *inOutPieces ) { - HlmsPbsDatablock *datablock = static_cast( renderable->getDatablock() ); + HlmsPbsDatablock *datablock = static_cast( renderable->getDatablock() ); const bool hasAlphaTest = datablock->getAlphaTest() != CMPF_ALWAYS_PASS; HlmsPropertyVec::iterator itor = mSetProperties.begin(); - HlmsPropertyVec::iterator end = mSetProperties.end(); + HlmsPropertyVec::iterator end = mSetProperties.end(); while( itor != end ) { @@ -1036,18 +1030,17 @@ namespace Ogre else if( itor->keyName != PbsProperty::HwGammaRead && itor->keyName != PbsProperty::UvDiffuse && itor->keyName != HlmsPsoProp::InputLayoutId && - itor->keyName != HlmsBaseProp::Skeleton && - itor->keyName != HlmsBaseProp::Pose && + itor->keyName != HlmsBaseProp::Skeleton && itor->keyName != HlmsBaseProp::Pose && itor->keyName != HlmsBaseProp::PoseHalfPrecision && itor->keyName != HlmsBaseProp::PoseNormals && itor->keyName != HlmsBaseProp::BonesPerVertex && itor->keyName != HlmsBaseProp::DualParaboloidMapping && itor->keyName != HlmsBaseProp::AlphaTest && itor->keyName != HlmsBaseProp::AlphaBlend && - (!hasAlphaTest || !requiredPropertyByAlphaTest( itor->keyName )) ) + ( !hasAlphaTest || !requiredPropertyByAlphaTest( itor->keyName ) ) ) { itor = mSetProperties.erase( itor ); - end = mSetProperties.end(); + end = mSetProperties.end(); } else { @@ -1090,18 +1083,17 @@ namespace Ogre { const int32 numVctProbes = getProperty( PbsProperty::VctNumProbes ); const bool hasVct = numVctProbes > 0; - if( getProperty( HlmsBaseProp::DecalsNormals ) || - hasVct ) + if( getProperty( HlmsBaseProp::DecalsNormals ) || hasVct ) { - //If decals normals are enabled or VCT is used, we need to generate the TBN matrix. - bool normalMapCanBeSupported = (getProperty( HlmsBaseProp::Normal ) && - getProperty( HlmsBaseProp::Tangent )) || - getProperty( HlmsBaseProp::QTangent ); + // If decals normals are enabled or VCT is used, we need to generate the TBN matrix. + bool normalMapCanBeSupported = + ( getProperty( HlmsBaseProp::Normal ) && getProperty( HlmsBaseProp::Tangent ) ) || + getProperty( HlmsBaseProp::QTangent ); setProperty( PbsProperty::NormalMap, normalMapCanBeSupported ); } - //If the pass does not have planar reflections, then the object cannot use it + // If the pass does not have planar reflections, then the object cannot use it if( !getProperty( PbsProperty::HasPlanarReflections ) ) setProperty( PbsProperty::UsePlanarReflections, 0 ); @@ -1109,10 +1101,9 @@ namespace Ogre setProperty( HlmsBaseProp::VertexId, 1 ); const int32 envProbeMapVal = getProperty( PbsProperty::EnvProbeMap ); - const bool canUseManualProbe = envProbeMapVal && - envProbeMapVal != getProperty( PbsProperty::TargetEnvprobeMap ); - if( canUseManualProbe || - getProperty( PbsProperty::ParallaxCorrectCubemaps ) ) + const bool canUseManualProbe = + envProbeMapVal && envProbeMapVal != getProperty( PbsProperty::TargetEnvprobeMap ); + if( canUseManualProbe || getProperty( PbsProperty::ParallaxCorrectCubemaps ) ) { setProperty( PbsProperty::UseEnvProbeMap, 1 ); @@ -1134,27 +1125,19 @@ namespace Ogre bool bNeedsEnvBrdf = false; - if( getProperty( HlmsBaseProp::UseSsr ) || - getProperty( PbsProperty::UseEnvProbeMap ) || + if( getProperty( HlmsBaseProp::UseSsr ) || getProperty( PbsProperty::UseEnvProbeMap ) || getProperty( PbsProperty::UsePlanarReflections ) || - getProperty( PbsProperty::AmbientHemisphere ) || - getProperty( PbsProperty::AmbientSh ) || - getProperty( PbsProperty::EnableCubemapsAuto ) || - hasIrradianceField || - hasVct ) + getProperty( PbsProperty::AmbientHemisphere ) || getProperty( PbsProperty::AmbientSh ) || + getProperty( PbsProperty::EnableCubemapsAuto ) || hasIrradianceField || hasVct ) { setProperty( PbsProperty::NeedsReflDir, 1 ); setProperty( PbsProperty::NeedsEnvBrdf, 1 ); bNeedsEnvBrdf = true; } - if( getProperty( HlmsBaseProp::LightsSpot ) || - getProperty( HlmsBaseProp::ForwardPlus ) || + if( getProperty( HlmsBaseProp::LightsSpot ) || getProperty( HlmsBaseProp::ForwardPlus ) || getProperty( HlmsBaseProp::LightsAreaApprox ) || - getProperty( HlmsBaseProp::LightsAreaLtc ) || - bNeedsEnvBrdf || - hasIrradianceField || - hasVct ) + getProperty( HlmsBaseProp::LightsAreaLtc ) || bNeedsEnvBrdf || hasIrradianceField || hasVct ) { setProperty( PbsProperty::NeedsViewDir, 1 ); } @@ -1177,7 +1160,7 @@ namespace Ogre if( getProperty( HlmsBaseProp::UsePrePass ) ) { - setTextureReg( PixelShader, "gBuf_normals", texUnit++ ); + setTextureReg( PixelShader, "gBuf_normals", texUnit++ ); setTextureReg( PixelShader, "gBuf_shadowRoughness", texUnit++ ); if( getProperty( HlmsBaseProp::UsePrePassMsaa ) ) @@ -1260,7 +1243,7 @@ namespace Ogre if( getProperty( HlmsBaseProp::EnableDecals ) ) { const int32 decalsDiffuseProp = getProperty( HlmsBaseProp::DecalsDiffuse ); - //This is a regular property! + // This is a regular property! setProperty( "decalsSampler", texUnit ); if( decalsDiffuseProp ) @@ -1278,20 +1261,20 @@ namespace Ogre if( getProperty( HlmsBaseProp::NumShadowMapLights ) != 0 ) { char tmpData[32]; - LwString texName = LwString::FromEmptyPointer( tmpData, sizeof(tmpData) ); + LwString texName = LwString::FromEmptyPointer( tmpData, sizeof( tmpData ) ); texName = "texShadowMap"; const size_t baseTexSize = texName.size(); - for( int32 i=0; igetObbRestraint(); if( obbRestraint ) { Matrix4 obbMat = obbRestraint->_getFullTransform(); obbMat = viewMatrix * obbMat; obbMat = obbMat.inverseAffine(); -#if !OGRE_DOUBLE_PRECISION +# if !OGRE_DOUBLE_PRECISION memcpy( passBufferPtr, &obbMat, sizeof( float ) * 12u ); passBufferPtr += 12u; -#else - for( size_t i=0u; i<12u; ++i ) +# else + for( size_t i = 0u; i < 12u; ++i ) *passBufferPtr++ = static_cast( obbMat[0][i] ); -#endif +# endif } else { @@ -1456,11 +1437,11 @@ namespace Ogre if( shadowNode && mShadowFilter == ExponentialShadowMaps ) setProperty( PbsProperty::ExponentialShadowMaps, mEsmK ); - //The properties need to be set before preparePassHash so that - //they are considered when building the HlmsCache's hash. + // The properties need to be set before preparePassHash so that + // they are considered when building the HlmsCache's hash. if( shadowNode && !casterPass ) { - //Shadow receiving can be improved in performance by using gather sampling. + // Shadow receiving can be improved in performance by using gather sampling. //(it's the only feature so far that uses gather) const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities(); if( capabilities->hasCapability( RSC_TEXTURE_GATHER ) ) @@ -1488,8 +1469,8 @@ namespace Ogre } else if( mShadowFilter == ExponentialShadowMaps ) { - //Already set - //setProperty( PbsProperty::ExponentialShadowMaps, 1 ); + // Already set + // setProperty( PbsProperty::ExponentialShadowMaps, 1 ); } else { @@ -1516,21 +1497,22 @@ namespace Ogre assert( mPrePassTextures->empty() || mPrePassTextures->size() == 2u ); mPrePassMsaaDepthTexture = 0; - if( !mPrePassTextures->empty() && (*mPrePassTextures)[0]->isMultisample() ) + if( !mPrePassTextures->empty() && ( *mPrePassTextures )[0]->isMultisample() ) { TextureGpu *msaaDepthTexture = sceneManager->getCurrentPrePassDepthTexture(); if( msaaDepthTexture ) mPrePassMsaaDepthTexture = msaaDepthTexture; - assert( (mPrePassMsaaDepthTexture && - mPrePassMsaaDepthTexture->getSampleDescription() == (*mPrePassTextures)[0]->getSampleDescription()) && - "Prepass + MSAA must specify an MSAA depth texture" ); + assert( + ( mPrePassMsaaDepthTexture && mPrePassMsaaDepthTexture->getSampleDescription() == + ( *mPrePassTextures )[0]->getSampleDescription() ) && + "Prepass + MSAA must specify an MSAA depth texture" ); } mDepthTexture = sceneManager->getCurrentPrePassDepthTexture(); mDepthTextureNoMsaa = sceneManager->getCurrentPassDepthTextureNoMsaa(); mSsrTexture = sceneManager->getCurrentSsrTexture(); - assert( !(mPrePassTextures->empty() && mSsrTexture) && + assert( !( mPrePassTextures->empty() && mSsrTexture ) && "Using SSR *requires* to be in prepass mode" ); mRefractionsTexture = sceneManager->getCurrentRefractionsTexture(); @@ -1538,15 +1520,15 @@ namespace Ogre OGRE_ASSERT_LOW( ( !mRefractionsTexture || ( mRefractionsTexture && mDepthTextureNoMsaa ) ) && "Refractions texture requires a depth texture!" ); - const bool vctNeedsAmbientHemi = !casterPass && mVctLighting && - mVctLighting->needsAmbientHemisphere(); + const bool vctNeedsAmbientHemi = + !casterPass && mVctLighting && mVctLighting->needsAmbientHemisphere(); AmbientLightMode ambientMode = mAmbientLightMode; ColourValue upperHemisphere = sceneManager->getAmbientLightUpperHemisphere(); ColourValue lowerHemisphere = sceneManager->getAmbientLightLowerHemisphere(); const float envMapScale = upperHemisphere.a; - //Ignore alpha channel + // Ignore alpha channel upperHemisphere.a = lowerHemisphere.a = 1.0; const CompositorPass *pass = sceneManager->getCurrentCompositorPass(); @@ -1554,8 +1536,8 @@ namespace Ogre if( pass && pass->getType() == PASS_SCENE ) { - OGRE_ASSERT_HIGH( dynamic_cast( pass->getDefinition() ) ); - passSceneDef = static_cast( pass->getDefinition() ); + OGRE_ASSERT_HIGH( dynamic_cast( pass->getDefinition() ) ); + passSceneDef = static_cast( pass->getDefinition() ); } const bool isInstancedStereo = passSceneDef && passSceneDef->mInstancedStereo; if( isInstancedStereo ) @@ -1604,7 +1586,7 @@ namespace Ogre if( envFeatures & SceneManager::EnvFeatures_DiffuseGiFromReflectionProbe ) setProperty( PbsProperty::CubemapsAsDiffuseGi, 1 ); - //Save cubemap's name so that we never try to render & sample to/from it at the same time + // Save cubemap's name so that we never try to render & sample to/from it at the same time RenderPassDescriptor *renderPassDescriptor = mRenderSystem->getCurrentPassDescriptor(); if( renderPassDescriptor->getNumColourEntries() > 0u ) { @@ -1654,7 +1636,7 @@ namespace Ogre if( mAreaLightMasks ) { const size_t numComponents = - PixelFormatGpuUtils::getNumberOfComponents( mAreaLightMasks->getPixelFormat() ); + PixelFormatGpuUtils::getNumberOfComponents( mAreaLightMasks->getPixelFormat() ); if( numComponents > 2u ) setProperty( HlmsBaseProp::LightsAreaTexColour, 1 ); } @@ -1669,8 +1651,8 @@ namespace Ogre #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS mHasPlanarReflections = false; mLastBoundPlanarReflection = 0u; - if( mPlanarReflections && - mPlanarReflections->cameraMatches( sceneManager->getCamerasInProgress().renderingCamera ) ) + if( mPlanarReflections && mPlanarReflections->cameraMatches( + sceneManager->getCamerasInProgress().renderingCamera ) ) { mHasPlanarReflections = true; setProperty( PbsProperty::HasPlanarReflections, @@ -1687,16 +1669,17 @@ namespace Ogre if( mOptimizationStrategy == LowerGpuOverhead ) setProperty( PbsProperty::LowerGpuOverhead, 1 ); - HlmsCache retVal = Hlms::preparePassHashBase( shadowNode, casterPass, - dualParaboloid, sceneManager ); + HlmsCache retVal = + Hlms::preparePassHashBase( shadowNode, casterPass, dualParaboloid, sceneManager ); if( mUseLightBuffers ) setProperty( PbsProperty::useLightBuffers, 1 ); const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities(); setProperty( PbsProperty::HwGammaRead, capabilities->hasCapability( RSC_HW_GAMMA ) ); -// setProperty( PbsProperty::HwGammaWrite, capabilities->hasCapability( RSC_HW_GAMMA ) && -// renderTarget->isHardwareGammaEnabled() ); + // setProperty( PbsProperty::HwGammaWrite, capabilities->hasCapability( RSC_HW_GAMMA ) && + // renderTarget->isHardwareGammaEnabled() + // ); setProperty( PbsProperty::HwGammaWrite, 1 ); retVal.setProperties = mSetProperties; @@ -1715,19 +1698,19 @@ namespace Ogre projectionMatrix[1][3] = -projectionMatrix[1][3]; } - int32 numLights = getProperty( HlmsBaseProp::LightsSpot ); - int32 numDirectionalLights = getProperty( HlmsBaseProp::LightsDirNonCaster ); - int32 numShadowMapLights = getProperty( HlmsBaseProp::NumShadowMapLights ); - int32 numPssmSplits = getProperty( HlmsBaseProp::PssmSplits ); - int32 numAreaApproxLights = getProperty( HlmsBaseProp::LightsAreaApprox ); - int32 numAreaLtcLights = getProperty( HlmsBaseProp::LightsAreaLtc ); + int32 numLights = getProperty( HlmsBaseProp::LightsSpot ); + int32 numDirectionalLights = getProperty( HlmsBaseProp::LightsDirNonCaster ); + int32 numShadowMapLights = getProperty( HlmsBaseProp::NumShadowMapLights ); + int32 numPssmSplits = getProperty( HlmsBaseProp::PssmSplits ); + int32 numAreaApproxLights = getProperty( HlmsBaseProp::LightsAreaApprox ); + int32 numAreaLtcLights = getProperty( HlmsBaseProp::LightsAreaLtc ); const uint32 realNumDirectionalLights = mRealNumDirectionalLights; const uint32 realNumAreaApproxLightsWithMask = mRealNumAreaApproxLightsWithMask; const uint32 realNumAreaApproxLights = mRealNumAreaApproxLights; const uint32 realNumAreaLtcLights = mRealNumAreaLtcLights; #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT - const size_t numAreaApproxFloat4Vars = 7u + (mUseObbRestraintAreaApprox ? 4u : 0u); - const size_t numAreaLtcFloat4Vars = 7u + (mUseObbRestraintAreaLtc ? 3u : 0u); + const size_t numAreaApproxFloat4Vars = 7u + ( mUseObbRestraintAreaApprox ? 4u : 0u ); + const size_t numAreaLtcFloat4Vars = 7u + ( mUseObbRestraintAreaLtc ? 3u : 0u ); #else const size_t numAreaApproxFloat4Vars = 7u; const size_t numAreaLtcFloat4Vars = 7u; @@ -1738,14 +1721,14 @@ namespace Ogre bool isShadowCastingPointLight = false; - //mat4 viewProj; + // mat4 viewProj; size_t mapSize = 16 * 4; size_t mapSizeLight0 = 0; size_t mapSizeLight1 = 0; size_t mapSizeLight2 = 0; - mGridBuffer = 0; - mGlobalLightListBuffer = 0; + mGridBuffer = 0; + mGlobalLightListBuffer = 0; mDecalsTextures[0] = 0; mDecalsTextures[1] = 0; @@ -1759,8 +1742,8 @@ namespace Ogre if( forwardPlus ) { mapSize += forwardPlus->getConstBufferSize(); - mGridBuffer = forwardPlus->getGridBuffer( cameras.cullingCamera ); - mGlobalLightListBuffer = forwardPlus->getGlobalLightListBuffer( cameras.cullingCamera ); + mGridBuffer = forwardPlus->getGridBuffer( cameras.cullingCamera ); + mGlobalLightListBuffer = forwardPlus->getGlobalLightListBuffer( cameras.cullingCamera ); if( forwardPlus->getDecalsEnabled() ) { @@ -1787,39 +1770,39 @@ namespace Ogre if( mIrradianceField ) mapSize += mIrradianceField->getConstBufferSize(); - //mat4 view + mat4 shadowRcv[numShadowMapLights].texViewProj + + // mat4 view + mat4 shadowRcv[numShadowMapLights].texViewProj + // vec2 shadowRcv[numShadowMapLights].shadowDepthRange + // float normalOffsetBias + // float padding + // vec4 shadowRcv[numShadowMapLights].invShadowMapSize + - //mat3 invViewMatCubemap (upgraded to three vec4) - mapSize += ( 16 + (16 + 2 + 2 + 4) * numShadowMapLights + 4 * 3 ) * 4; + // mat3 invViewMatCubemap (upgraded to three vec4) + mapSize += ( 16 + ( 16 + 2 + 2 + 4 ) * numShadowMapLights + 4 * 3 ) * 4; - //float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps; + // float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps; mapSize += 4u * 4u; - //float4 aspectRatio_planarReflNumMips_unused2; + // float4 aspectRatio_planarReflNumMips_unused2; mapSize += 4u * 4u; - //float2 invWindowRes + float2 windowResolution + // float2 invWindowRes + float2 windowResolution mapSize += 4u * 4u; - //vec4 shadowRcv[numShadowMapLights].texViewZRow + // vec4 shadowRcv[numShadowMapLights].texViewZRow if( mShadowFilter == ExponentialShadowMaps ) - mapSize += (4 * 4) * numShadowMapLights; + mapSize += ( 4 * 4 ) * numShadowMapLights; - //vec4 pixelOffset2x + // vec4 pixelOffset2x if( passSceneDef && passSceneDef->mUvBakingSet != 0xFF ) mapSize += 4u * 4u; - //vec3 ambientUpperHemi + float envMapScale - if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || - envMapScale != 1.0f || vctNeedsAmbientHemi ) + // vec3 ambientUpperHemi + float envMapScale + if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || envMapScale != 1.0f || + vctNeedsAmbientHemi ) { mapSize += 4 * 4; } - //vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding + // vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding if( ambientMode == AmbientHemisphere || vctNeedsAmbientHemi ) { mapSize += 8 * 4; @@ -1833,26 +1816,26 @@ namespace Ogre if( ambientMode == AmbientShMonochrome ) mapSize += 3u * 4u * 4u; - //vec3 irradianceOrigin + float maxPower + - //vec3 irradianceSize + float invHeight + mat4 invView + // vec3 irradianceOrigin + float maxPower + + // vec3 irradianceSize + float invHeight + mat4 invView if( mIrradianceVolume ) - mapSize += (4 + 4 + 4*4) * 4; + mapSize += ( 4 + 4 + 4 * 4 ) * 4; #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS if( mHasPlanarReflections ) mapSize += mPlanarReflections->getConstBufferSize(); #endif - //float pssmSplitPoints N times. + // float pssmSplitPoints N times. mapSize += numPssmSplits * 4; if( isPssmBlend ) { - //float pssmBlendPoints N-1 times. + // float pssmBlendPoints N-1 times. mapSize += ( numPssmSplits - 1 ) * 4; } if( isPssmFade ) { - //float pssmFadePoint. + // float pssmFadePoint. mapSize += 4; } @@ -1860,12 +1843,12 @@ namespace Ogre if( numShadowMapLights > 0 ) { - //Six variables * 4 (padded vec3) * 4 (bytes) * numLights + // Six variables * 4 (padded vec3) * 4 (bytes) * numLights mapSizeLight0 += ( 6 * 4 * 4 ) * numLights; } else { - //Three variables * 4 (padded vec3) * 4 (bytes) * numDirectionalLights + // Three variables * 4 (padded vec3) * 4 (bytes) * numDirectionalLights mapSizeLight0 += ( 3 * 4 * 4 ) * numDirectionalLights; } @@ -1875,39 +1858,38 @@ namespace Ogre else { isShadowCastingPointLight = getProperty( HlmsBaseProp::ShadowCasterPoint ) != 0; - //vec4 cameraPosWS + // vec4 cameraPosWS if( isShadowCastingPointLight ) mapSize += 4 * 4; - //vec4 viewZRow + // vec4 viewZRow if( mShadowFilter == ExponentialShadowMaps ) mapSize += 4 * 4; - //vec4 depthRange - mapSize += (2 + 2) * 4; + // vec4 depthRange + mapSize += ( 2 + 2 ) * 4; } const bool isCameraReflected = cameras.renderingCamera->isReflected(); - //vec4 clipPlane0 + // vec4 clipPlane0 if( isCameraReflected ) mapSize += 4 * 4; - //float4x4 viewProj[2] (second only) + float4 leftToRightView + // float4x4 viewProj[2] (second only) + float4 leftToRightView if( isInstancedStereo ) { mapSize += 16u * 4u + 4u * 4u; - //float4x4 leftEyeViewSpaceToCullCamClipSpace + // float4x4 leftEyeViewSpaceToCullCamClipSpace if( forwardPlus ) mapSize += 16u * 4u; } - mapSize += mListener->getPassBufferSize( shadowNode, casterPass, dualParaboloid, - sceneManager ); + mapSize += mListener->getPassBufferSize( shadowNode, casterPass, dualParaboloid, sceneManager ); - //Arbitrary 16kb (minimum supported by GL), should be enough. + // Arbitrary 16kb (minimum supported by GL), should be enough. const size_t maxBufferSizeRaw = 16 * 1024; - const size_t maxBufferSizeLight0 = (6 * 4 * 4) * 32; // 32 forward lights should be enough - const size_t maxBufferSizeLight1 = (numAreaApproxFloat4Vars * 4 * 4) * 8; // 8 area lights - const size_t maxBufferSizeLight2 = (numAreaLtcFloat4Vars * 4 * 4) * 8; // 8 Ltc area lights + const size_t maxBufferSizeLight0 = ( 6 * 4 * 4 ) * 32; // 32 forward lights should be enough + const size_t maxBufferSizeLight1 = ( numAreaApproxFloat4Vars * 4 * 4 ) * 8; // 8 area lights + const size_t maxBufferSizeLight2 = ( numAreaLtcFloat4Vars * 4 * 4 ) * 8; // 8 Ltc area lights assert( mapSize <= maxBufferSizeRaw ); assert( !mUseLightBuffers || mapSizeLight0 <= maxBufferSizeLight0 ); @@ -1920,11 +1902,11 @@ namespace Ogre if( mCurrentPassBuffer >= mPassBuffers.size() ) { - mPassBuffers.push_back( mVaoManager->createConstBuffer( maxBufferSize, BT_DYNAMIC_PERSISTENT, - 0, false ) ); + mPassBuffers.push_back( + mVaoManager->createConstBuffer( maxBufferSize, BT_DYNAMIC_PERSISTENT, 0, false ) ); } - if (mUseLightBuffers) + if( mUseLightBuffers ) { while( mCurrentPassBuffer >= mLight0Buffers.size() ) { @@ -1938,7 +1920,7 @@ namespace Ogre } ConstBufferPacked *passBuffer = mPassBuffers[mCurrentPassBuffer++]; - float *passBufferPtr = reinterpret_cast( passBuffer->map( 0, mapSize ) ); + float *passBufferPtr = reinterpret_cast( passBuffer->map( 0, mapSize ) ); ConstBufferPacked *light0Buffer = 0; ConstBufferPacked *light1Buffer = 0; @@ -1973,16 +1955,16 @@ namespace Ogre if( !isInstancedStereo ) { - //mat4 viewProj; + // mat4 viewProj; Matrix4 viewProjMatrix = projectionMatrix * viewMatrix; - for( size_t i=0u; i<16u; ++i ) + for( size_t i = 0u; i < 16u; ++i ) *passBufferPtr++ = (float)viewProjMatrix[0][i]; } else { - //float4x4 viewProj[2]; + // float4x4 viewProj[2]; Matrix4 vrViewMat[2]; - for( size_t eyeIdx=0u; eyeIdx<2u; ++eyeIdx ) + for( size_t eyeIdx = 0u; eyeIdx < 2u; ++eyeIdx ) { vrViewMat[eyeIdx] = cameras.renderingCamera->getVrViewMatrix( eyeIdx ); Matrix4 vrProjMat = cameras.renderingCamera->getVrProjectionMatrix( eyeIdx ); @@ -1994,11 +1976,11 @@ namespace Ogre vrProjMat[1][3] = -vrProjMat[1][3]; } Matrix4 viewProjMatrix = vrProjMat * vrViewMat[eyeIdx]; - for( size_t i=0; i<16; ++i ) + for( size_t i = 0; i < 16; ++i ) *passBufferPtr++ = (float)viewProjMatrix[0][i]; } - //float4x4 leftEyeViewSpaceToCullCamClipSpace + // float4x4 leftEyeViewSpaceToCullCamClipSpace if( forwardPlus ) { Matrix4 cullViewMat = cameras.cullingCamera->getViewMatrix( true ); @@ -2011,23 +1993,23 @@ namespace Ogre cullProjMat[1][3] = -cullProjMat[1][3]; } Matrix4 leftEyeViewSpaceToCullCamClipSpace; - leftEyeViewSpaceToCullCamClipSpace = cullProjMat * cullViewMat * - vrViewMat[0].inverseAffine(); - for( size_t i=0u; i<16u; ++i ) + leftEyeViewSpaceToCullCamClipSpace = + cullProjMat * cullViewMat * vrViewMat[0].inverseAffine(); + for( size_t i = 0u; i < 16u; ++i ) *passBufferPtr++ = (float)leftEyeViewSpaceToCullCamClipSpace[0][i]; } - //float4 leftToRightView + // float4 leftToRightView const VrData *vrData = cameras.renderingCamera->getVrData(); if( vrData ) { - for( size_t i=0u; i<3u; ++i ) + for( size_t i = 0u; i < 3u; ++i ) *passBufferPtr++ = (float)vrData->mLeftToRight[i]; *passBufferPtr++ = 0; } else { - for( size_t i=0u; i<4u; ++i ) + for( size_t i = 0u; i < 4u; ++i ) *passBufferPtr++ = 0.0f; } } @@ -2040,7 +2022,7 @@ namespace Ogre projectionMatrix[1][3] = -projectionMatrix[1][3]; } - //vec4 clipPlane0 + // vec4 clipPlane0 if( isCameraReflected ) { const Plane &reflPlane = cameras.renderingCamera->getReflectionPlane(); @@ -2050,7 +2032,7 @@ namespace Ogre *passBufferPtr++ = (float)reflPlane.d; } - //vec4 cameraPosWS; + // vec4 cameraPosWS; if( isShadowCastingPointLight ) { const Vector3 &camPos = cameras.renderingCamera->getDerivedPosition(); @@ -2060,7 +2042,7 @@ namespace Ogre *passBufferPtr++ = 1.0f; } - mPreparedPass.viewMatrix = viewMatrix; + mPreparedPass.viewMatrix = viewMatrix; mPreparedPass.shadowMaps.clear(); @@ -2069,27 +2051,27 @@ namespace Ogre if( !casterPass ) { - //mat4 view; - for( size_t i=0; i<16; ++i ) + // mat4 view; + for( size_t i = 0; i < 16; ++i ) *passBufferPtr++ = (float)viewMatrix[0][i]; size_t shadowMapTexIdx = 0; const TextureGpuVec &contiguousShadowMapTex = shadowNode ? shadowNode->getContiguousShadowMapTex() : c_emptyTextureContainer; - for( int32 i=0; iisShadowMapIdxActive( shadowMapTexIdx ) ) ++shadowMapTexIdx; - //mat4 shadowRcv[numShadowMapLights].texViewProj + // mat4 shadowRcv[numShadowMapLights].texViewProj Matrix4 viewProjTex = shadowNode->getViewProjectionMatrix( shadowMapTexIdx ); - for( size_t j=0; j<16; ++j ) + for( size_t j = 0; j < 16; ++j ) *passBufferPtr++ = (float)viewProjTex[0][j]; - //vec4 texViewZRow; + // vec4 texViewZRow; if( mShadowFilter == ExponentialShadowMaps ) { const Matrix4 &viewTex = shadowNode->getViewMatrix( shadowMapTexIdx ); @@ -2101,14 +2083,12 @@ namespace Ogre const Light *shadowLight = shadowNode->getLightAssociatedWith( shadowMapTexIdx ); - //vec2 shadowRcv[numShadowMapLights].shadowDepthRange + // vec2 shadowRcv[numShadowMapLights].shadowDepthRange Real fNear, fFar; shadowNode->getMinMaxDepthRange( shadowMapTexIdx, fNear, fFar ); const Real depthRange = fFar - fNear; - if( shadowLight && - shadowLight->getType() == Light::LT_POINT && - mShadowFilter != ExponentialShadowMaps && - mRenderSystem->isReverseDepth() ) + if( shadowLight && shadowLight->getType() == Light::LT_POINT && + mShadowFilter != ExponentialShadowMaps && mRenderSystem->isReverseDepth() ) { *passBufferPtr++ = fFar; } @@ -2118,13 +2098,12 @@ namespace Ogre } *passBufferPtr++ = 1.0f / depthRange; *passBufferPtr++ = shadowNode->getNormalOffsetBias( (size_t)shadowMapTexIdx ); - *passBufferPtr++ = 0.0f; //Padding + *passBufferPtr++ = 0.0f; // Padding - - //vec2 shadowRcv[numShadowMapLights].invShadowMapSize + // vec2 shadowRcv[numShadowMapLights].invShadowMapSize size_t shadowMapTexContigIdx = - shadowNode->getIndexToContiguousShadowMapTex( (size_t)shadowMapTexIdx ); - uint32 texWidth = contiguousShadowMapTex[shadowMapTexContigIdx]->getWidth(); + shadowNode->getIndexToContiguousShadowMapTex( (size_t)shadowMapTexIdx ); + uint32 texWidth = contiguousShadowMapTex[shadowMapTexContigIdx]->getWidth(); uint32 texHeight = contiguousShadowMapTex[shadowMapTexContigIdx]->getHeight(); *passBufferPtr++ = 1.0f / texWidth; *passBufferPtr++ = 1.0f / texHeight; @@ -2134,12 +2113,12 @@ namespace Ogre ++shadowMapTexIdx; } - //vec4 pixelOffset2x + // vec4 pixelOffset2x if( passSceneDef && passSceneDef->mUvBakingSet != 0xFF ) { - *passBufferPtr++ = static_cast( passSceneDef->mUvBakingOffset.x * Real(2.0) / + *passBufferPtr++ = static_cast( passSceneDef->mUvBakingOffset.x * Real( 2.0 ) / renderTarget->getWidth() ); - *passBufferPtr++ = static_cast( passSceneDef->mUvBakingOffset.y * Real(2.0) / + *passBufferPtr++ = static_cast( passSceneDef->mUvBakingOffset.y * Real( 2.0 ) / renderTarget->getHeight() ); *passBufferPtr++ = 0.0f; *passBufferPtr++ = 0.0f; @@ -2150,32 +2129,30 @@ namespace Ogre Matrix3 viewMatrix3, invViewMatrixCubemap; viewMatrix.extract3x3Matrix( viewMatrix3 ); - //Cubemaps are left-handed. + // Cubemaps are left-handed. invViewMatrixCubemap = viewMatrix3; invViewMatrixCubemap[0][2] = -invViewMatrixCubemap[0][2]; invViewMatrixCubemap[1][2] = -invViewMatrixCubemap[1][2]; invViewMatrixCubemap[2][2] = -invViewMatrixCubemap[2][2]; invViewMatrixCubemap = invViewMatrixCubemap.Inverse(); - //mat3 invViewMatCubemap - for( size_t i=0; i<9; ++i ) + // mat3 invViewMatCubemap + for( size_t i = 0; i < 9; ++i ) { #ifdef OGRE_GLES2_WORKAROUND_2 - Matrix3 xRot( 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, -1.0f, - 0.0f, 1.0f, 0.0f ); + Matrix3 xRot( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f ); xRot = xRot * invViewMatrixCubemap; *passBufferPtr++ = (float)xRot[0][i]; #else *passBufferPtr++ = (float)invViewMatrixCubemap[0][i]; #endif - //Alignment: each row/column is one vec4, despite being 3x3 - if( !( (i+1) % 3 ) ) + // Alignment: each row/column is one vec4, despite being 3x3 + if( !( ( i + 1 ) % 3 ) ) ++passBufferPtr; } - //float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps + // float4 pccVctMinDistance_invPccVctInvDistance_rightEyePixelStartX_envMapNumMipmaps *passBufferPtr++ = mPccVctMinDistance; *passBufferPtr++ = mInvPccVctInvDistance; *passBufferPtr++ = currViewports[1].getActualLeft(); @@ -2185,7 +2162,7 @@ namespace Ogre const float windowWidth = renderTarget->getWidth(); const float windowHeight = renderTarget->getHeight(); - //float4 aspectRatio_planarReflNumMips_unused2 + // float4 aspectRatio_planarReflNumMips_unused2 *passBufferPtr++ = windowWidth / windowHeight; #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS if( mPlanarReflections ) @@ -2203,16 +2180,16 @@ namespace Ogre *passBufferPtr++ = 0.0f; *passBufferPtr++ = 0.0f; - //float2 invWindowRes + float2 windowResolution; + // float2 invWindowRes + float2 windowResolution; *passBufferPtr++ = 1.0f / windowWidth; *passBufferPtr++ = 1.0f / windowHeight; *passBufferPtr++ = windowWidth; *passBufferPtr++ = windowHeight; } - //vec3 ambientUpperHemi + padding - if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || - envMapScale != 1.0f || vctNeedsAmbientHemi ) + // vec3 ambientUpperHemi + padding + if( ambientMode == AmbientFixed || ambientMode == AmbientHemisphere || envMapScale != 1.0f || + vctNeedsAmbientHemi ) { *passBufferPtr++ = static_cast( upperHemisphere.r ); *passBufferPtr++ = static_cast( upperHemisphere.g ); @@ -2220,7 +2197,7 @@ namespace Ogre *passBufferPtr++ = envMapScale; } - //vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding + // vec3 ambientLowerHemi + padding + vec3 ambientHemisphereDir + padding if( ambientMode == AmbientHemisphere || vctNeedsAmbientHemi ) { *passBufferPtr++ = static_cast( lowerHemisphere.r ); @@ -2246,7 +2223,7 @@ namespace Ogre *passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 1u]; *passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 2u]; } - *passBufferPtr++ = 0.0f; // Unused / padding + *passBufferPtr++ = 0.0f; // Unused / padding } // float4 sh0 - sh2; @@ -2255,60 +2232,60 @@ namespace Ogre const float *ambientSphericalHarmonics = sceneManager->getSphericalHarmonics(); for( size_t i = 0u; i < 9u; ++i ) *passBufferPtr++ = ambientSphericalHarmonics[i * 3u + 0u]; - *passBufferPtr++ = 0.0f; // Unused / padding - *passBufferPtr++ = 0.0f; // Unused / padding - *passBufferPtr++ = 0.0f; // Unused / padding + *passBufferPtr++ = 0.0f; // Unused / padding + *passBufferPtr++ = 0.0f; // Unused / padding + *passBufferPtr++ = 0.0f; // Unused / padding } if( mIrradianceVolume ) { const Vector3 irradianceCellSize = mIrradianceVolume->getIrradianceCellSize(); - const Vector3 irradianceVolumeOrigin = mIrradianceVolume->getIrradianceOrigin() / - irradianceCellSize; - const float fTexWidth = static_cast( - mIrradianceVolume->getIrradianceVolumeTexture()->getWidth() ); - const float fTexDepth = static_cast( - mIrradianceVolume->getIrradianceVolumeTexture()->getDepth() ); + const Vector3 irradianceVolumeOrigin = + mIrradianceVolume->getIrradianceOrigin() / irradianceCellSize; + const float fTexWidth = + static_cast( mIrradianceVolume->getIrradianceVolumeTexture()->getWidth() ); + const float fTexDepth = + static_cast( mIrradianceVolume->getIrradianceVolumeTexture()->getDepth() ); *passBufferPtr++ = static_cast( irradianceVolumeOrigin.x ) / fTexWidth; *passBufferPtr++ = static_cast( irradianceVolumeOrigin.y ); *passBufferPtr++ = static_cast( irradianceVolumeOrigin.z ) / fTexDepth; - *passBufferPtr++ = mIrradianceVolume->getIrradianceMaxPower() * - mIrradianceVolume->getPowerScale(); + *passBufferPtr++ = + mIrradianceVolume->getIrradianceMaxPower() * mIrradianceVolume->getPowerScale(); - const float fTexHeight = static_cast( - mIrradianceVolume->getIrradianceVolumeTexture()->getHeight() ); + const float fTexHeight = + static_cast( mIrradianceVolume->getIrradianceVolumeTexture()->getHeight() ); - *passBufferPtr++ = 1.0f / (fTexWidth * irradianceCellSize.x); + *passBufferPtr++ = 1.0f / ( fTexWidth * irradianceCellSize.x ); *passBufferPtr++ = 1.0f / irradianceCellSize.y; - *passBufferPtr++ = 1.0f / (fTexDepth * irradianceCellSize.z); + *passBufferPtr++ = 1.0f / ( fTexDepth * irradianceCellSize.z ); *passBufferPtr++ = 1.0f / fTexHeight; - //mat4 invView; + // mat4 invView; Matrix4 invViewMatrix = viewMatrix.inverse(); - for( size_t i=0; i<16; ++i ) + for( size_t i = 0; i < 16; ++i ) *passBufferPtr++ = (float)invViewMatrix[0][i]; } - //float pssmSplitPoints - for( int32 i=0; igetPssmSplits(0))[i+1]; + // float pssmSplitPoints + for( int32 i = 0; i < numPssmSplits; ++i ) + *passBufferPtr++ = ( *shadowNode->getPssmSplits( 0 ) )[i + 1]; int32 numPssmBlendsAndFade = 0; if( isPssmBlend ) { numPssmBlendsAndFade += numPssmSplits - 1; - //float pssmBlendPoints - for( int32 i=0; igetPssmBlends(0))[i]; + // float pssmBlendPoints + for( int32 i = 0; i < numPssmSplits - 1; ++i ) + *passBufferPtr++ = ( *shadowNode->getPssmBlends( 0 ) )[i]; } if( isPssmFade ) { numPssmBlendsAndFade += 1; - //float pssmFadePoint - *passBufferPtr++ = *shadowNode->getPssmFade(0); + // float pssmFadePoint + *passBufferPtr++ = *shadowNode->getPssmFade( 0 ); } passBufferPtr += alignToNextMultiple( numPssmSplits + numPssmBlendsAndFade, 4 ) - @@ -2323,19 +2300,19 @@ namespace Ogre if( mLightProfilesTexture ) invHeightLightProfileTex = 1.0f / mLightProfilesTexture->getHeight(); - //All directional lights (caster and non-caster) are sent. - //Then non-directional shadow-casting shadow lights are sent. + // All directional lights (caster and non-caster) are sent. + // Then non-directional shadow-casting shadow lights are sent. size_t shadowLightIdx = 0; size_t nonShadowLightIdx = 0; const LightListInfo &globalLightList = sceneManager->getGlobalLightList(); const LightClosestArray &lights = shadowNode->getShadowCastingLights(); const CompositorShadowNode::LightsBitSet &affectedLights = - shadowNode->getAffectedLightsBitSet(); + shadowNode->getAffectedLightsBitSet(); int32 shadowCastingDirLights = getProperty( HlmsBaseProp::LightsDirectional ); - for( int32 i=0; i_getAutoParamDataSource(); + sceneManager->_getAutoParamDataSource(); light = &autoParamDataSource->_getBlankLight(); } } else { - //Skip inactive lights (e.g. no directional lights are available - //and there's a shadow map that only accepts dir lights) + // Skip inactive lights (e.g. no directional lights are available + // and there's a shadow map that only accepts dir lights) while( !lights[shadowLightIdx].light ) ++shadowLightIdx; light = lights[shadowLightIdx++].light; @@ -2374,35 +2351,35 @@ namespace Ogre else lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z ); - //vec3 lights[numLights].position + // vec3 lights[numLights].position *light0BufferPtr++ = lightPos.x; *light0BufferPtr++ = lightPos.y; *light0BufferPtr++ = lightPos.z; #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - *reinterpret_cast(light0BufferPtr) = light->getLightMask(); + *reinterpret_cast( light0BufferPtr ) = + light->getLightMask(); #endif ++light0BufferPtr; - //vec3 lights[numLights].diffuse - ColourValue colour = light->getDiffuseColour() * - light->getPowerScale(); + // vec3 lights[numLights].diffuse + ColourValue colour = light->getDiffuseColour() * light->getPowerScale(); *light0BufferPtr++ = colour.r; *light0BufferPtr++ = colour.g; *light0BufferPtr++ = colour.b; - *reinterpret_cast(light0BufferPtr) = - realNumDirectionalLights - shadowCastingDirLights; + *reinterpret_cast( light0BufferPtr ) = + realNumDirectionalLights - shadowCastingDirLights; ++light0BufferPtr; - //vec3 lights[numLights].specular + // vec3 lights[numLights].specular colour = light->getSpecularColour() * light->getPowerScale(); *light0BufferPtr++ = colour.r; *light0BufferPtr++ = colour.g; *light0BufferPtr++ = colour.b; ++light0BufferPtr; - //vec3 lights[numLights].attenuation; - Real attenRange = light->getAttenuationRange(); - Real attenLinear = light->getAttenuationLinear(); + // vec3 lights[numLights].attenuation; + Real attenRange = light->getAttenuationRange(); + Real attenLinear = light->getAttenuationLinear(); Real attenQuadratic = light->getAttenuationQuadric(); *light0BufferPtr++ = attenRange; *light0BufferPtr++ = attenLinear; @@ -2419,13 +2396,13 @@ namespace Ogre *light0BufferPtr++ = ( static_cast( lightProfileIdx ) + 0.5f ) * invHeightLightProfileTex; - //vec4 lights[numLights].spotParams; + // vec4 lights[numLights].spotParams; if( light->getType() != Light::LT_AREA_APPROX ) { Radian innerAngle = light->getSpotlightInnerAngle(); Radian outerAngle = light->getSpotlightOuterAngle(); *light0BufferPtr++ = 1.0f / ( cosf( innerAngle.valueRadians() * 0.5f ) - - cosf( outerAngle.valueRadians() * 0.5f ) ); + cosf( outerAngle.valueRadians() * 0.5f ) ); *light0BufferPtr++ = cosf( outerAngle.valueRadians() * 0.5f ); *light0BufferPtr++ = light->getSpotlightFalloff(); } @@ -2438,12 +2415,11 @@ namespace Ogre *light0BufferPtr++ = xAxis.z; } *light0BufferPtr++ = 0.0f; - } } else { - //No shadow maps, only send directional lights + // No shadow maps, only send directional lights const LightListInfo &globalLightList = sceneManager->getGlobalLightList(); for( int32 i = 0; i < (int32)realNumDirectionalLights; ++i ) @@ -2453,37 +2429,39 @@ namespace Ogre Vector4 lightPos4 = globalLightList.lights[i]->getAs4DVector(); Vector3 lightPos = viewMatrix3 * Vector3( lightPos4.x, lightPos4.y, lightPos4.z ); - //vec3 lights[numLights].position + // vec3 lights[numLights].position *light0BufferPtr++ = lightPos.x; *light0BufferPtr++ = lightPos.y; *light0BufferPtr++ = lightPos.z; #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - *reinterpret_cast(light0BufferPtr) = - globalLightList.lights[i]->getLightMask(); + *reinterpret_cast( light0BufferPtr ) = + globalLightList.lights[i]->getLightMask(); #endif ++light0BufferPtr; - //vec3 lights[numLights].diffuse + // vec3 lights[numLights].diffuse ColourValue colour = globalLightList.lights[i]->getDiffuseColour() * globalLightList.lights[i]->getPowerScale(); *light0BufferPtr++ = colour.r; *light0BufferPtr++ = colour.g; *light0BufferPtr++ = colour.b; - *reinterpret_cast(light0BufferPtr) = - realNumDirectionalLights; + *reinterpret_cast( light0BufferPtr ) = + realNumDirectionalLights; ++light0BufferPtr; - //vec3 lights[numLights].specular - colour = globalLightList.lights[i]->getSpecularColour() * globalLightList.lights[i]->getPowerScale(); + // vec3 lights[numLights].specular + colour = globalLightList.lights[i]->getSpecularColour() * + globalLightList.lights[i]->getPowerScale(); *light0BufferPtr++ = colour.r; *light0BufferPtr++ = colour.g; *light0BufferPtr++ = colour.b; ++light0BufferPtr; } - memset(light0BufferPtr, 0, - (numDirectionalLights - realNumDirectionalLights) * sizeof(float) * 4u * 3u ); - light0BufferPtr += (numDirectionalLights - realNumDirectionalLights) * 4u * 3u; + memset( + light0BufferPtr, 0, + ( numDirectionalLights - realNumDirectionalLights ) * sizeof( float ) * 4u * 3u ); + light0BufferPtr += ( numDirectionalLights - realNumDirectionalLights ) * 4u * 3u; } if( !mUseLightBuffers ) @@ -2494,21 +2472,22 @@ namespace Ogre if( mAreaLightMasks ) { - //Roughness minimum value is 0.02, so we need to map + // Roughness minimum value is 0.02, so we need to map //[0.02; 1.0] -> [0; 1] in the pixel shader that's why we divide by 0.98. - //The 2.0 is just arbitrary (it looks good) - areaLightNumMipmaps = (mAreaLightMasks->getNumMipmaps() - 1u); + // The 2.0 is just arbitrary (it looks good) + areaLightNumMipmaps = ( mAreaLightMasks->getNumMipmaps() - 1u ); areaLightNumMipmapsSpecFactor = areaLightNumMipmaps * 2.0f / 0.98f; } - //Send area lights. We need them sorted so textured ones - //come first, as that what our shader expects + // Send area lights. We need them sorted so textured ones + // come first, as that what our shader expects mAreaLights.reserve( numAreaApproxLights ); mAreaLights.clear(); const LightListInfo &globalLightList = sceneManager->getGlobalLightList(); size_t areaLightNumber = 0; for( size_t idx = mAreaLightsGlobalLightListStart; - idxgetType() == Light::LT_AREA_APPROX ) { @@ -2522,41 +2501,40 @@ namespace Ogre if( !mUseLightBuffers ) light1BufferPtr = passBufferPtr; - for( size_t i=0; igetAs4DVector(); Vector3 lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z ); - //vec3 areaApproxLights[numLights].position + // vec3 areaApproxLights[numLights].position *light1BufferPtr++ = lightPos.x; *light1BufferPtr++ = lightPos.y; *light1BufferPtr++ = lightPos.z; #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - *reinterpret_cast(light1BufferPtr) = light->getLightMask(); + *reinterpret_cast( light1BufferPtr ) = light->getLightMask(); #endif ++light1BufferPtr; - //vec3 areaApproxLights[numLights].diffuse - ColourValue colour = light->getDiffuseColour() * - light->getPowerScale(); + // vec3 areaApproxLights[numLights].diffuse + ColourValue colour = light->getDiffuseColour() * light->getPowerScale(); *light1BufferPtr++ = colour.r; *light1BufferPtr++ = colour.g; *light1BufferPtr++ = colour.b; - *light1BufferPtr++ = areaLightNumMipmaps * - (light->mTexLightMaskDiffuseMipStart / 65535.0f); + *light1BufferPtr++ = + areaLightNumMipmaps * ( light->mTexLightMaskDiffuseMipStart / 65535.0f ); - //vec3 areaApproxLights[numLights].specular + // vec3 areaApproxLights[numLights].specular colour = light->getSpecularColour() * light->getPowerScale(); *light1BufferPtr++ = colour.r; *light1BufferPtr++ = colour.g; *light1BufferPtr++ = colour.b; *light1BufferPtr++ = areaLightNumMipmapsSpecFactor; - //vec4 areaApproxLights[numLights].attenuation; - Real attenRange = light->getAttenuationRange(); - Real attenLinear = light->getAttenuationLinear(); + // vec4 areaApproxLights[numLights].attenuation; + Real attenRange = light->getAttenuationRange(); + Real attenLinear = light->getAttenuationLinear(); Real attenQuadratic = light->getAttenuationQuadric(); *light1BufferPtr++ = attenRange; *light1BufferPtr++ = attenLinear; @@ -2565,14 +2543,14 @@ namespace Ogre const Vector2 rectSize = light->getDerivedRectSize(); - //vec4 areaApproxLights[numLights].direction; + // vec4 areaApproxLights[numLights].direction; Vector3 areaDir = viewMatrix3 * light->getDerivedDirection(); *light1BufferPtr++ = areaDir.x; *light1BufferPtr++ = areaDir.y; *light1BufferPtr++ = areaDir.z; *light1BufferPtr++ = 1.0f / rectSize.x; - //vec4 areaApproxLights[numLights].tangent; + // vec4 areaApproxLights[numLights].tangent; Quaternion qRot = light->getParentNode()->_getDerivedOrientation(); Vector3 xAxis = viewMatrix3 * qRot.xAxis(); *light1BufferPtr++ = xAxis.x; @@ -2580,36 +2558,36 @@ namespace Ogre *light1BufferPtr++ = xAxis.z; *light1BufferPtr++ = 1.0f / rectSize.y; - //vec4 doubleSided; + // vec4 doubleSided; *light1BufferPtr++ = light->getDoubleSided() ? 1.0f : 0.0f; - *reinterpret_cast(light1BufferPtr) = - realNumAreaApproxLights; + *reinterpret_cast( light1BufferPtr ) = realNumAreaApproxLights; ++light1BufferPtr; - *reinterpret_cast(light1BufferPtr) = - realNumAreaApproxLightsWithMask; + *reinterpret_cast( light1BufferPtr ) = + realNumAreaApproxLightsWithMask; ++light1BufferPtr; *light1BufferPtr++ = 0.0f; #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT if( mUseObbRestraintAreaApprox ) { - //float4 obbFadeFactorApprox + // float4 obbFadeFactorApprox const Vector3 obbRestraintFadeFactor = light->_getObbRestraintFadeFactor(); *light1BufferPtr++ = obbRestraintFadeFactor.x; *light1BufferPtr++ = obbRestraintFadeFactor.y; *light1BufferPtr++ = obbRestraintFadeFactor.z; *light1BufferPtr++ = 0.0f; - //float4x3 obbRestraint; - light1BufferPtr = fillObbRestraint( light, viewMatrix, light1BufferPtr); + // float4x3 obbRestraint; + light1BufferPtr = fillObbRestraint( light, viewMatrix, light1BufferPtr ); } #endif } - memset(light1BufferPtr, 0, (numAreaApproxLights - realNumAreaApproxLights) * - sizeof(float) * 4u * numAreaApproxFloat4Vars ); - light1BufferPtr += (numAreaApproxLights - realNumAreaApproxLights) * - 4u * numAreaApproxFloat4Vars; + memset( light1BufferPtr, 0, + ( numAreaApproxLights - realNumAreaApproxLights ) * sizeof( float ) * 4u * + numAreaApproxFloat4Vars ); + light1BufferPtr += + ( numAreaApproxLights - realNumAreaApproxLights ) * 4u * numAreaApproxFloat4Vars; if( !mUseLightBuffers ) passBufferPtr = light1BufferPtr; @@ -2618,7 +2596,7 @@ namespace Ogre mAreaLights.clear(); areaLightNumber = 0; for( size_t idx = mAreaLightsGlobalLightListStart; - idxgetType() == Light::LT_AREA_LTC ) { @@ -2627,38 +2605,37 @@ namespace Ogre } } - //std::sort( mAreaLights.begin(), mAreaLights.end(), SortByTextureLightMaskIdx ); + // std::sort( mAreaLights.begin(), mAreaLights.end(), SortByTextureLightMaskIdx ); if( !mUseLightBuffers ) light2BufferPtr = passBufferPtr; - for( size_t i=0; igetAs4DVector(); Vector3 lightPos = viewMatrix * Vector3( lightPos4.x, lightPos4.y, lightPos4.z ); - //vec3 areaLtcLights[numLights].position + // vec3 areaLtcLights[numLights].position *light2BufferPtr++ = lightPos.x; *light2BufferPtr++ = lightPos.y; *light2BufferPtr++ = lightPos.z; #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - *reinterpret_cast(light2BufferPtr) = light->getLightMask(); + *reinterpret_cast( light2BufferPtr ) = light->getLightMask(); #endif ++light2BufferPtr; - const Real attenRange = light->getAttenuationRange(); + const Real attenRange = light->getAttenuationRange(); - //vec3 areaLtcLights[numLights].diffuse - ColourValue colour = light->getDiffuseColour() * - light->getPowerScale(); + // vec3 areaLtcLights[numLights].diffuse + ColourValue colour = light->getDiffuseColour() * light->getPowerScale(); *light2BufferPtr++ = colour.r; *light2BufferPtr++ = colour.g; *light2BufferPtr++ = colour.b; *light2BufferPtr++ = attenRange; - //vec3 areaLtcLights[numLights].specular + // vec3 areaLtcLights[numLights].specular colour = light->getSpecularColour() * light->getPowerScale(); *light2BufferPtr++ = colour.r; *light2BufferPtr++ = colour.g; @@ -2667,22 +2644,22 @@ namespace Ogre const Vector2 rectSize = light->getDerivedRectSize() * 0.5f; Quaternion qRot = light->getParentNode()->_getDerivedOrientation(); - Vector3 xAxis = (viewMatrix3 * qRot.xAxis()) * rectSize.x; - Vector3 yAxis = (viewMatrix3 * qRot.yAxis()) * rectSize.y; + Vector3 xAxis = ( viewMatrix3 * qRot.xAxis() ) * rectSize.x; + Vector3 yAxis = ( viewMatrix3 * qRot.yAxis() ) * rectSize.y; Vector3 rectPoints[4]; - //vec4 areaLtcLights[numLights].points[4]; + // vec4 areaLtcLights[numLights].points[4]; rectPoints[0] = lightPos - xAxis - yAxis; rectPoints[1] = lightPos + xAxis - yAxis; rectPoints[2] = lightPos + xAxis + yAxis; rectPoints[3] = lightPos - xAxis + yAxis; #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT - //float4 obbFadeFactorApprox + // float4 obbFadeFactorApprox const Vector3 obbRestraintFadeFactor = light->_getObbRestraintFadeFactor(); #endif - for( size_t j=0; j<4u; ++j ) + for( size_t j = 0; j < 4u; ++j ) { *light2BufferPtr++ = rectPoints[j].x; *light2BufferPtr++ = rectPoints[j].y; @@ -2690,13 +2667,14 @@ namespace Ogre #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT if( j == 0u ) { - *reinterpret_cast(light2BufferPtr) = realNumAreaLtcLights; + *reinterpret_cast( light2BufferPtr ) = + realNumAreaLtcLights; ++light2BufferPtr; } else - *light2BufferPtr++ = obbRestraintFadeFactor[j-1u]; + *light2BufferPtr++ = obbRestraintFadeFactor[j - 1u]; #else - *reinterpret_cast(light2BufferPtr) = realNumAreaLtcLights; + *reinterpret_cast( light2BufferPtr ) = realNumAreaLtcLights; ++light2BufferPtr; #endif } @@ -2704,15 +2682,16 @@ namespace Ogre #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT if( mUseObbRestraintAreaLtc ) { - //float4x3 obbRestraint; - light2BufferPtr = fillObbRestraint( light, viewMatrix, light2BufferPtr); + // float4x3 obbRestraint; + light2BufferPtr = fillObbRestraint( light, viewMatrix, light2BufferPtr ); } #endif } - memset(light2BufferPtr, 0, (numAreaLtcLights - realNumAreaLtcLights) * - sizeof(float) * 4u * numAreaLtcFloat4Vars ); - light2BufferPtr += (numAreaLtcLights - realNumAreaLtcLights) * 4u * numAreaLtcFloat4Vars; + memset( light2BufferPtr, 0, + ( numAreaLtcLights - realNumAreaLtcLights ) * sizeof( float ) * 4u * + numAreaLtcFloat4Vars ); + light2BufferPtr += ( numAreaLtcLights - realNumAreaLtcLights ) * 4u * numAreaLtcFloat4Vars; if( !mUseLightBuffers ) passBufferPtr = light2BufferPtr; @@ -2767,7 +2746,7 @@ namespace Ogre } else { - //vec4 viewZRow + // vec4 viewZRow if( mShadowFilter == ExponentialShadowMaps ) { *passBufferPtr++ = viewMatrix[2][0]; @@ -2776,7 +2755,7 @@ namespace Ogre *passBufferPtr++ = viewMatrix[2][3]; } - //vec2 depthRange; + // vec2 depthRange; Real fNear, fFar; shadowNode->getMinMaxDepthRange( cameras.renderingCamera, fNear, fFar ); const Real depthRange = fFar - fNear; @@ -2788,7 +2767,7 @@ namespace Ogre passBufferPtr = mListener->preparePassBuffer( shadowNode, casterPass, dualParaboloid, sceneManager, passBufferPtr ); - assert( (size_t)(passBufferPtr - startupPtr) * 4u == mapSize ); + assert( ( size_t )( passBufferPtr - startupPtr ) * 4u == mapSize ); if( mUseLightBuffers ) { @@ -2805,7 +2784,7 @@ namespace Ogre passBuffer->unmap( UO_KEEP_PERSISTENT ); - //mTexBuffers must hold at least one buffer to prevent out of bound exceptions. + // mTexBuffers must hold at least one buffer to prevent out of bound exceptions. if( mTexBuffers.empty() ) { size_t bufferSize = @@ -2877,10 +2856,9 @@ namespace Ogre if( mLtcMatrixTexture ) ++mTexUnitSlotStart; - for( size_t i=0; i<3u; ++i ) + for( size_t i = 0; i < 3u; ++i ) { - if( mDecalsTextures[i] && - (i != 2u || !mDecalsDiffuseMergedEmissive) ) + if( mDecalsTextures[i] && ( i != 2u || !mDecalsDiffuseMergedEmissive ) ) { ++mTexUnitSlotStart; } @@ -2898,8 +2876,7 @@ namespace Ogre } //----------------------------------------------------------------------------------- uint32 HlmsPbs::fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - uint32 lastTextureHash ) + bool casterPass, uint32 lastCacheHash, uint32 lastTextureHash ) { OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, "Trying to use slow-path on a desktop implementation. " @@ -2907,44 +2884,37 @@ namespace Ogre "HlmsPbs::fillBuffersFor" ); } //----------------------------------------------------------------------------------- - uint32 HlmsPbs::fillBuffersForV1( const HlmsCache *cache, - const QueuedRenderable &queuedRenderable, + uint32 HlmsPbs::fillBuffersForV1( const HlmsCache *cache, const QueuedRenderable &queuedRenderable, bool casterPass, uint32 lastCacheHash, CommandBuffer *commandBuffer ) { - return fillBuffersFor( cache, queuedRenderable, casterPass, - lastCacheHash, commandBuffer, true ); + return fillBuffersFor( cache, queuedRenderable, casterPass, lastCacheHash, commandBuffer, true ); } //----------------------------------------------------------------------------------- - uint32 HlmsPbs::fillBuffersForV2( const HlmsCache *cache, - const QueuedRenderable &queuedRenderable, + uint32 HlmsPbs::fillBuffersForV2( const HlmsCache *cache, const QueuedRenderable &queuedRenderable, bool casterPass, uint32 lastCacheHash, CommandBuffer *commandBuffer ) { - return fillBuffersFor( cache, queuedRenderable, casterPass, - lastCacheHash, commandBuffer, false ); + return fillBuffersFor( cache, queuedRenderable, casterPass, lastCacheHash, commandBuffer, + false ); } //----------------------------------------------------------------------------------- uint32 HlmsPbs::fillBuffersFor( const HlmsCache *cache, const QueuedRenderable &queuedRenderable, - bool casterPass, uint32 lastCacheHash, - CommandBuffer *commandBuffer, bool isV1 ) + bool casterPass, uint32 lastCacheHash, CommandBuffer *commandBuffer, + bool isV1 ) { - assert( dynamic_cast( queuedRenderable.renderable->getDatablock() ) ); - const HlmsPbsDatablock *datablock = static_cast( - queuedRenderable.renderable->getDatablock() ); + assert( dynamic_cast( queuedRenderable.renderable->getDatablock() ) ); + const HlmsPbsDatablock *datablock = + static_cast( queuedRenderable.renderable->getDatablock() ); if( OGRE_EXTRACT_HLMS_TYPE_FROM_CACHE_HASH( lastCacheHash ) != mType ) { - //layout(binding = 0) uniform PassBuffer {} pass - ConstBufferPacked *passBuffer = mPassBuffers[mCurrentPassBuffer-1]; - *commandBuffer->addCommand() = CbShaderBuffer( VertexShader, - 0, passBuffer, 0, - passBuffer-> - getTotalSizeBytes() ); - *commandBuffer->addCommand() = CbShaderBuffer( PixelShader, - 0, passBuffer, 0, - passBuffer-> - getTotalSizeBytes() ); + // layout(binding = 0) uniform PassBuffer {} pass + ConstBufferPacked *passBuffer = mPassBuffers[mCurrentPassBuffer - 1]; + *commandBuffer->addCommand() = + CbShaderBuffer( VertexShader, 0, passBuffer, 0, passBuffer->getTotalSizeBytes() ); + *commandBuffer->addCommand() = + CbShaderBuffer( PixelShader, 0, passBuffer, 0, passBuffer->getTotalSizeBytes() ); if( mUseLightBuffers ) { @@ -2974,9 +2944,9 @@ namespace Ogre if( mGridBuffer ) { *commandBuffer->addCommand() = - CbShaderBuffer( PixelShader, texUnit++, mGlobalLightListBuffer, 0, 0 ); + CbShaderBuffer( PixelShader, texUnit++, mGlobalLightListBuffer, 0, 0 ); *commandBuffer->addCommand() = - CbShaderBuffer( PixelShader, texUnit++, mGridBuffer, 0, 0 ); + CbShaderBuffer( PixelShader, texUnit++, mGridBuffer, 0, 0 ); } texUnit += mReservedTexSlots; @@ -2984,9 +2954,9 @@ namespace Ogre if( !mPrePassTextures->empty() ) { *commandBuffer->addCommand() = - CbTexture( texUnit++, (*mPrePassTextures)[0], 0 ); + CbTexture( texUnit++, ( *mPrePassTextures )[0], 0 ); *commandBuffer->addCommand() = - CbTexture( texUnit++, (*mPrePassTextures)[1], 0 ); + CbTexture( texUnit++, ( *mPrePassTextures )[1], 0 ); } if( mPrePassMsaaDepthTexture ) @@ -2998,15 +2968,14 @@ namespace Ogre if( mDepthTexture ) { - *commandBuffer->addCommand() = CbTexture( - texUnit++, mDepthTexture, mDecalsSamplerblock, - PixelFormatGpuUtils::isDepth( mDepthTexture->getPixelFormat() ) ); + *commandBuffer->addCommand() = + CbTexture( texUnit++, mDepthTexture, mDecalsSamplerblock, + PixelFormatGpuUtils::isDepth( mDepthTexture->getPixelFormat() ) ); } if( mSsrTexture ) { - *commandBuffer->addCommand() = - CbTexture( texUnit++, mSsrTexture, 0 ); + *commandBuffer->addCommand() = CbTexture( texUnit++, mSsrTexture, 0 ); } if( mDepthTextureNoMsaa && mDepthTextureNoMsaa != mPrePassMsaaDepthTexture ) @@ -3019,7 +2988,7 @@ namespace Ogre if( mRefractionsTexture ) { *commandBuffer->addCommand() = - CbTexture( texUnit++, mRefractionsTexture, mDecalsSamplerblock ); + CbTexture( texUnit++, mRefractionsTexture, mDecalsSamplerblock ); } if( mIrradianceVolume ) @@ -3027,9 +2996,8 @@ namespace Ogre TextureGpu *irradianceTex = mIrradianceVolume->getIrradianceVolumeTexture(); const HlmsSamplerblock *samplerblock = mIrradianceVolume->getIrradSamplerblock(); - *commandBuffer->addCommand() = CbTexture( texUnit, - irradianceTex, - samplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, irradianceTex, samplerblock ); ++texUnit; } @@ -3037,9 +3005,8 @@ namespace Ogre { const size_t numCascades = mVctLighting->getNumCascades(); const size_t numVctTextures = mVctLighting->getNumVoxelTextures(); - const HlmsSamplerblock *samplerblock = - mVctLighting->getBindTrilinearSamplerblock(); - for( size_t i=0; igetBindTrilinearSamplerblock(); + for( size_t i = 0; i < numVctTextures; ++i ) { for( size_t cascadeIdx = 0; cascadeIdx < numCascades; ++cascadeIdx ) { @@ -3064,47 +3031,42 @@ namespace Ogre if( mUsingAreaLightMasks ) { - *commandBuffer->addCommand() = CbTexture( texUnit, - mAreaLightMasks, - mAreaLightMasksSamplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, mAreaLightMasks, mAreaLightMasksSamplerblock ); ++texUnit; } if( mLightProfilesTexture ) { - *commandBuffer->addCommand() = CbTexture( texUnit, - mLightProfilesTexture, - mAreaLightMasksSamplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, mLightProfilesTexture, mAreaLightMasksSamplerblock ); ++texUnit; } if( mLtcMatrixTexture ) { - *commandBuffer->addCommand() = CbTexture( texUnit, - mLtcMatrixTexture, - mAreaLightMasksSamplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, mLtcMatrixTexture, mAreaLightMasksSamplerblock ); ++texUnit; } - for( size_t i=0; i<3u; ++i ) + for( size_t i = 0; i < 3u; ++i ) { - if( mDecalsTextures[i] && - (i != 2u || !mDecalsDiffuseMergedEmissive) ) + if( mDecalsTextures[i] && ( i != 2u || !mDecalsDiffuseMergedEmissive ) ) { - *commandBuffer->addCommand() = CbTexture( texUnit, - mDecalsTextures[i], - mDecalsSamplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, mDecalsTextures[i], mDecalsSamplerblock ); ++texUnit; } } - //We changed HlmsType, rebind the shared textures. - FastArray::const_iterator itor = mPreparedPass.shadowMaps.begin(); - FastArray::const_iterator end = mPreparedPass.shadowMaps.end(); + // We changed HlmsType, rebind the shared textures. + FastArray::const_iterator itor = mPreparedPass.shadowMaps.begin(); + FastArray::const_iterator end = mPreparedPass.shadowMaps.end(); while( itor != end ) { - *commandBuffer->addCommand() = CbTexture( texUnit, *itor, - mCurrentShadowmapSamplerblock ); + *commandBuffer->addCommand() = + CbTexture( texUnit, *itor, mCurrentShadowmapSamplerblock ); ++texUnit; ++itor; } @@ -3113,9 +3075,9 @@ namespace Ogre { TextureGpu *pccTexture = mParallaxCorrectedCubemap->getBindTexture(); const HlmsSamplerblock *samplerblock = - mParallaxCorrectedCubemap->getBindTrilinearSamplerblock(); - *commandBuffer->addCommand() = CbTexture( texUnit, pccTexture, - samplerblock ); + mParallaxCorrectedCubemap->getBindTrilinearSamplerblock(); + *commandBuffer->addCommand() = + CbTexture( texUnit, pccTexture, samplerblock ); ++texUnit; } } @@ -3124,15 +3086,15 @@ namespace Ogre mLastDescSampler = 0; mLastBoundPool = 0; - //layout(binding = 2) uniform InstanceBuffer {} instance + // layout(binding = 2) uniform InstanceBuffer {} instance if( mCurrentConstBuffer < mConstBuffers.size() && - (size_t)((mCurrentMappedConstBuffer - mStartMappedConstBuffer) + 4) <= + ( size_t )( ( mCurrentMappedConstBuffer - mStartMappedConstBuffer ) + 4 ) <= mCurrentConstBufferSize ) { *commandBuffer->addCommand() = - CbShaderBuffer( VertexShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 ); + CbShaderBuffer( VertexShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 ); *commandBuffer->addCommand() = - CbShaderBuffer( PixelShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 ); + CbShaderBuffer( PixelShader, 2, mConstBuffers[mCurrentConstBuffer], 0, 0 ); } rebindTexBuffer( commandBuffer ); @@ -3143,17 +3105,16 @@ namespace Ogre mListener->hlmsTypeChanged( casterPass, commandBuffer, datablock, texUnit ); } - //Don't bind the material buffer on caster passes (important to keep - //MDI & auto-instancing running on shadow map passes) + // Don't bind the material buffer on caster passes (important to keep + // MDI & auto-instancing running on shadow map passes) if( mLastBoundPool != datablock->getAssignedPool() && - (!casterPass || datablock->getAlphaTest() != CMPF_ALWAYS_PASS) ) + ( !casterPass || datablock->getAlphaTest() != CMPF_ALWAYS_PASS ) ) { - //layout(binding = 1) uniform MaterialBuf {} materialArray + // layout(binding = 1) uniform MaterialBuf {} materialArray const ConstBufferPool::BufferPool *newPool = datablock->getAssignedPool(); - *commandBuffer->addCommand() = CbShaderBuffer( PixelShader, - 1, newPool->materialBuffer, 0, - newPool->materialBuffer-> - getTotalSizeBytes() ); + *commandBuffer->addCommand() = + CbShaderBuffer( PixelShader, 1, newPool->materialBuffer, 0, + newPool->materialBuffer->getTotalSizeBytes() ); CubemapProbe *manualProbe = datablock->getCubemapProbe(); if( manualProbe ) { @@ -3161,19 +3122,18 @@ namespace Ogre "Material has manual cubemap probe that does not match the " "PCC currently set" ); ConstBufferPacked *probeConstBuf = manualProbe->getConstBufferForManualProbes(); - *commandBuffer->addCommand() = CbShaderBuffer( PixelShader, - 3, probeConstBuf, - 0, 0 ); + *commandBuffer->addCommand() = + CbShaderBuffer( PixelShader, 3, probeConstBuf, 0, 0 ); } mLastBoundPool = newPool; } - uint32 * RESTRICT_ALIAS currentMappedConstBuffer = mCurrentMappedConstBuffer; - float * RESTRICT_ALIAS currentMappedTexBuffer = mCurrentMappedTexBuffer; + uint32 *RESTRICT_ALIAS currentMappedConstBuffer = mCurrentMappedConstBuffer; + float *RESTRICT_ALIAS currentMappedTexBuffer = mCurrentMappedTexBuffer; bool hasSkeletonAnimation = queuedRenderable.renderable->hasSkeletonAnimation(); uint32 numPoses = queuedRenderable.renderable->getNumPoses(); - uint32 poseWeightsNumFloats = ((numPoses >> 2u) + std::min(numPoses % 4u, 1u)) * 4u; + uint32 poseWeightsNumFloats = ( ( numPoses >> 2u ) + std::min( numPoses % 4u, 1u ) ) * 4u; const Matrix4 &worldMat = queuedRenderable.movableObject->_getParentNodeFullTransform(); @@ -3183,34 +3143,36 @@ namespace Ogre if( !hasSkeletonAnimation && numPoses == 0 ) { - //We need to correct currentMappedConstBuffer to point to the right texture buffer's - //offset, which may not be in sync if the previous draw had skeletal and/or pose animation. - const size_t currentConstOffset = (currentMappedTexBuffer - mStartMappedTexBuffer) >> - (2 + !casterPass); - currentMappedConstBuffer = currentConstOffset + mStartMappedConstBuffer; - bool exceedsConstBuffer = (size_t)((currentMappedConstBuffer - mStartMappedConstBuffer) + 4) - > mCurrentConstBufferSize; + // We need to correct currentMappedConstBuffer to point to the right texture buffer's + // offset, which may not be in sync if the previous draw had skeletal and/or pose animation. + const size_t currentConstOffset = + ( currentMappedTexBuffer - mStartMappedTexBuffer ) >> ( 2 + !casterPass ); + currentMappedConstBuffer = currentConstOffset + mStartMappedConstBuffer; + bool exceedsConstBuffer = + ( size_t )( ( currentMappedConstBuffer - mStartMappedConstBuffer ) + 4 ) > + mCurrentConstBufferSize; - const size_t minimumTexBufferSize = 16 * (1 + !casterPass); - bool exceedsTexBuffer = (currentMappedTexBuffer - mStartMappedTexBuffer) + - minimumTexBufferSize >= mCurrentTexBufferSize; + const size_t minimumTexBufferSize = 16 * ( 1 + !casterPass ); + bool exceedsTexBuffer = + ( currentMappedTexBuffer - mStartMappedTexBuffer ) + minimumTexBufferSize >= + mCurrentTexBufferSize; if( exceedsConstBuffer || exceedsTexBuffer ) { currentMappedConstBuffer = mapNextConstBuffer( commandBuffer ); if( exceedsTexBuffer ) - mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof(float) ); + mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) ); else - rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof(float) ); + rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof( float ) ); currentMappedTexBuffer = mCurrentMappedTexBuffer; } - //uint worldMaterialIdx[] + // uint worldMaterialIdx[] *currentMappedConstBuffer = datablock->getAssignedSlot() & 0x1FF; - //mat4x3 world + // mat4x3 world #if !OGRE_DOUBLE_PRECISION memcpy( currentMappedTexBuffer, &worldMat, 4 * 3 * sizeof( float ) ); currentMappedTexBuffer += 16; @@ -3219,13 +3181,13 @@ namespace Ogre { for( int x = 0; x < 4; ++x ) { - *currentMappedTexBuffer++ = worldMat[ y ][ x ]; + *currentMappedTexBuffer++ = worldMat[y][x]; } } currentMappedTexBuffer += 4; #endif - //mat4 worldView + // mat4 worldView Matrix4 tmp = mPreparedPass.viewMatrix.concatenateAffine( worldMat ); #if !OGRE_DOUBLE_PRECISION memcpy( currentMappedTexBuffer, &tmp, sizeof( Matrix4 ) * !casterPass ); @@ -3237,7 +3199,7 @@ namespace Ogre { for( int x = 0; x < 4; ++x ) { - *currentMappedTexBuffer++ = tmp[ y ][ x ]; + *currentMappedTexBuffer++ = tmp[y][x]; } } } @@ -3245,8 +3207,9 @@ namespace Ogre } else { - bool exceedsConstBuffer = (size_t)((currentMappedConstBuffer - mStartMappedConstBuffer) + 4) - > mCurrentConstBufferSize; + bool exceedsConstBuffer = + ( size_t )( ( currentMappedConstBuffer - mStartMappedConstBuffer ) + 4 ) > + mCurrentConstBufferSize; if( hasSkeletonAnimation ) { @@ -3255,84 +3218,89 @@ namespace Ogre uint16 numWorldTransforms = queuedRenderable.renderable->getNumWorldTransforms(); assert( numWorldTransforms <= 256u ); - const size_t poseDataSize = numPoses > 0u ? (4u + poseWeightsNumFloats) : 0u; + const size_t poseDataSize = numPoses > 0u ? ( 4u + poseWeightsNumFloats ) : 0u; const size_t minimumTexBufferSize = 12 * numWorldTransforms + poseDataSize; - bool exceedsTexBuffer = (currentMappedTexBuffer - mStartMappedTexBuffer) + - minimumTexBufferSize >= mCurrentTexBufferSize; + bool exceedsTexBuffer = + ( currentMappedTexBuffer - mStartMappedTexBuffer ) + minimumTexBufferSize >= + mCurrentTexBufferSize; if( exceedsConstBuffer || exceedsTexBuffer ) { currentMappedConstBuffer = mapNextConstBuffer( commandBuffer ); if( exceedsTexBuffer ) - mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof(float) ); + mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) ); else - rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof(float) ); + rebindTexBuffer( commandBuffer, true, + minimumTexBufferSize * sizeof( float ) ); currentMappedTexBuffer = mCurrentMappedTexBuffer; } - //uint worldMaterialIdx[] + // uint worldMaterialIdx[] size_t distToWorldMatStart = mCurrentMappedTexBuffer - mStartMappedTexBuffer; distToWorldMatStart >>= 2; - *currentMappedConstBuffer = (distToWorldMatStart << 9 ) | - (datablock->getAssignedSlot() & 0x1FF); + *currentMappedConstBuffer = + ( distToWorldMatStart << 9 ) | ( datablock->getAssignedSlot() & 0x1FF ); - //vec4 worldMat[][3] - //TODO: Don't rely on a virtual function + make a direct 4x3 copy + // vec4 worldMat[][3] + // TODO: Don't rely on a virtual function + make a direct 4x3 copy Matrix4 tmp[256]; queuedRenderable.renderable->getWorldTransforms( tmp ); - for( size_t i=0; igetSkeletonInstance(); - #if OGRE_DEBUG_MODE - assert( dynamic_cast( queuedRenderable.renderable ) ); - #endif +#if OGRE_DEBUG_MODE + assert( dynamic_cast( queuedRenderable.renderable ) ); +#endif - const RenderableAnimated *renderableAnimated = static_cast( - queuedRenderable.renderable ); + const RenderableAnimated *renderableAnimated = + static_cast( queuedRenderable.renderable ); - const RenderableAnimated::IndexMap *indexMap = renderableAnimated->getBlendIndexToBoneIndexMap(); + const RenderableAnimated::IndexMap *indexMap = + renderableAnimated->getBlendIndexToBoneIndexMap(); - const size_t poseDataSize = numPoses > 0u ? (4u + poseWeightsNumFloats) : 0u; + const size_t poseDataSize = numPoses > 0u ? ( 4u + poseWeightsNumFloats ) : 0u; const size_t minimumTexBufferSize = 12 * indexMap->size() + poseDataSize; - bool exceedsTexBuffer = (currentMappedTexBuffer - mStartMappedTexBuffer) + - minimumTexBufferSize >= mCurrentTexBufferSize; + bool exceedsTexBuffer = + ( currentMappedTexBuffer - mStartMappedTexBuffer ) + minimumTexBufferSize >= + mCurrentTexBufferSize; if( exceedsConstBuffer || exceedsTexBuffer ) { currentMappedConstBuffer = mapNextConstBuffer( commandBuffer ); if( exceedsTexBuffer ) - mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof(float) ); + mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) ); else - rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof(float) ); + rebindTexBuffer( commandBuffer, true, + minimumTexBufferSize * sizeof( float ) ); currentMappedTexBuffer = mCurrentMappedTexBuffer; } - //uint worldMaterialIdx[] + // uint worldMaterialIdx[] size_t distToWorldMatStart = mCurrentMappedTexBuffer - mStartMappedTexBuffer; distToWorldMatStart >>= 2; - *currentMappedConstBuffer = (distToWorldMatStart << 9 ) | - (datablock->getAssignedSlot() & 0x1FF); + *currentMappedConstBuffer = + ( distToWorldMatStart << 9 ) | ( datablock->getAssignedSlot() & 0x1FF ); RenderableAnimated::IndexMap::const_iterator itBone = indexMap->begin(); RenderableAnimated::IndexMap::const_iterator enBone = indexMap->end(); @@ -3355,83 +3323,85 @@ namespace Ogre // If not combined with skeleton animation, pose animations are gonna need 1 vec4's // for pose data (base vertex, num vertices), enough vec4's to accomodate // the weight of each pose, 3 vec4's for worldMat, and 4 vec4's for worldView. - const size_t minimumTexBufferSize = 4 + poseWeightsNumFloats + 3*4 + 4*4; - bool exceedsTexBuffer = (currentMappedTexBuffer - mStartMappedTexBuffer) + - minimumTexBufferSize >= mCurrentTexBufferSize; + const size_t minimumTexBufferSize = 4 + poseWeightsNumFloats + 3 * 4 + 4 * 4; + bool exceedsTexBuffer = + ( currentMappedTexBuffer - mStartMappedTexBuffer ) + minimumTexBufferSize >= + mCurrentTexBufferSize; if( exceedsConstBuffer || exceedsTexBuffer ) { currentMappedConstBuffer = mapNextConstBuffer( commandBuffer ); if( exceedsTexBuffer ) - mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof(float) ); + mapNextTexBuffer( commandBuffer, minimumTexBufferSize * sizeof( float ) ); else - rebindTexBuffer( commandBuffer, true, minimumTexBufferSize * sizeof(float) ); + rebindTexBuffer( commandBuffer, true, + minimumTexBufferSize * sizeof( float ) ); currentMappedTexBuffer = mCurrentMappedTexBuffer; } - //uint worldMaterialIdx[] + // uint worldMaterialIdx[] size_t distToWorldMatStart = mCurrentMappedTexBuffer - mStartMappedTexBuffer; distToWorldMatStart >>= 2; - *currentMappedConstBuffer = (distToWorldMatStart << 9 ) | - (datablock->getAssignedSlot() & 0x1FF); + *currentMappedConstBuffer = + ( distToWorldMatStart << 9 ) | ( datablock->getAssignedSlot() & 0x1FF ); } uint8 meshLod = queuedRenderable.movableObject->getCurrentMeshLod(); - const VertexArrayObjectArray &vaos = queuedRenderable.renderable->getVaos( - static_cast(casterPass) ); + const VertexArrayObjectArray &vaos = + queuedRenderable.renderable->getVaos( static_cast( casterPass ) ); VertexArrayObject *vao = vaos[meshLod]; // According to this https://forums.ogre3d.org/viewtopic.php?f=25&t=95040#p545057 // "macOS uses an old OpenGL version which doesn't use baseVertex" - #ifdef __APPLE__ +#ifdef __APPLE__ uint32 baseVertex = 0; - #else +#else uint32 baseVertex = static_cast( vao->getBaseVertexBuffer()->_getFinalBufferStart() ); - #endif +#endif memcpy( currentMappedTexBuffer, &baseVertex, sizeof( baseVertex ) ); size_t numVertices = vao->getBaseVertexBuffer()->getNumElements(); memcpy( currentMappedTexBuffer + 1, &numVertices, sizeof( numVertices ) ); currentMappedTexBuffer += 4; memcpy( currentMappedTexBuffer, queuedRenderable.renderable->getPoseWeights(), - sizeof(float) * numPoses); + sizeof( float ) * numPoses ); currentMappedTexBuffer += poseWeightsNumFloats; if( !hasSkeletonAnimation ) { - //mat4x3 world - #if !OGRE_DOUBLE_PRECISION + // mat4x3 world +#if !OGRE_DOUBLE_PRECISION memcpy( currentMappedTexBuffer, &worldMat, 4 * 3 * sizeof( float ) ); currentMappedTexBuffer += 12; - #else +#else for( int y = 0; y < 3; ++y ) { for( int x = 0; x < 4; ++x ) { - *currentMappedTexBuffer++ = worldMat[ y ][ x ]; + *currentMappedTexBuffer++ = worldMat[y][x]; } } - #endif +#endif - //mat4 worldView + // mat4 worldView Matrix4 tmp = mPreparedPass.viewMatrix.concatenateAffine( worldMat ); - #if !OGRE_DOUBLE_PRECISION +#if !OGRE_DOUBLE_PRECISION memcpy( currentMappedTexBuffer, &tmp, sizeof( Matrix4 ) * !casterPass ); currentMappedTexBuffer += 16 * !casterPass; - #else +#else if( !casterPass ) { for( int y = 0; y < 4; ++y ) { for( int x = 0; x < 4; ++x ) { - *currentMappedTexBuffer++ = tmp[ y ][ x ]; + *currentMappedTexBuffer++ = tmp[y][x]; } } } - #endif +#endif } size_t numTextures = 0u; @@ -3444,11 +3414,11 @@ namespace Ogre poseBuf->getTotalSizeBytes() ); } - //If the next entity will not be skeletally animated, we'll need - //currentMappedTexBuffer to be 16/32-byte aligned. - //Non-skeletally animated objects are far more common than skeletal ones, - //so we do this here instead of doing it before rendering the non-skeletal ones. - size_t currentConstOffset = (size_t)(currentMappedTexBuffer - mStartMappedTexBuffer); + // If the next entity will not be skeletally animated, we'll need + // currentMappedTexBuffer to be 16/32-byte aligned. + // Non-skeletally animated objects are far more common than skeletal ones, + // so we do this here instead of doing it before rendering the non-skeletal ones. + size_t currentConstOffset = ( size_t )( currentMappedTexBuffer - mStartMappedTexBuffer ); currentConstOffset = alignToNextMultiple( currentConstOffset, 16 + 16 * !casterPass ); currentConstOffset = std::min( currentConstOffset, mCurrentTexBufferSize ); currentMappedTexBuffer = mStartMappedTexBuffer + currentConstOffset; @@ -3457,10 +3427,10 @@ namespace Ogre *reinterpret_cast( currentMappedConstBuffer + 1 ) = datablock->mShadowConstantBias * mConstantBiasScale; #if !OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - *( currentMappedConstBuffer+2u ) = queuedRenderable.movableObject->getLightMask(); + *( currentMappedConstBuffer + 2u ) = queuedRenderable.movableObject->getLightMask(); #endif #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS - *( currentMappedConstBuffer+3u ) = queuedRenderable.renderable->mCustomParameter & 0x7F; + *( currentMappedConstBuffer + 3u ) = queuedRenderable.renderable->mCustomParameter & 0x7F; #endif currentMappedConstBuffer += 4; @@ -3472,14 +3442,13 @@ namespace Ogre { #ifdef OGRE_BUILD_COMPONENT_PLANAR_REFLECTIONS if( !casterPass && mHasPlanarReflections && - (queuedRenderable.renderable->mCustomParameter & 0x80 /* UseActiveActor */) && + ( queuedRenderable.renderable->mCustomParameter & 0x80 /* UseActiveActor */ ) && mLastBoundPlanarReflection != queuedRenderable.renderable->mCustomParameter ) { const uint8 activeActorIdx = queuedRenderable.renderable->mCustomParameter & 0x7F; TextureGpu *planarReflTex = mPlanarReflections->getTexture( activeActorIdx ); *commandBuffer->addCommand() = - CbTexture( mTexUnitSlotStart - 1u, planarReflTex, - mPlanarReflectionsSamplerblock ); + CbTexture( mTexUnitSlotStart - 1u, planarReflTex, mPlanarReflectionsSamplerblock ); mLastBoundPlanarReflection = queuedRenderable.renderable->mCustomParameter; } #endif @@ -3487,19 +3456,18 @@ namespace Ogre { if( datablock->mTexturesDescSet ) { - //Rebind textures + // Rebind textures size_t texUnit = mTexUnitSlotStart; - *commandBuffer->addCommand() = - CbTextures( texUnit, datablock->mCubemapIdxInDescSet, - datablock->mTexturesDescSet ); + *commandBuffer->addCommand() = CbTextures( + texUnit, datablock->mCubemapIdxInDescSet, datablock->mTexturesDescSet ); if( !mHasSeparateSamplers ) { *commandBuffer->addCommand() = - CbSamplers( texUnit, datablock->mSamplersDescSet ); + CbSamplers( texUnit, datablock->mSamplersDescSet ); } - //texUnit += datablock->mTexturesDescSet->mTextures.size(); + // texUnit += datablock->mTexturesDescSet->mTextures.size(); } mLastDescTexture = datablock->mTexturesDescSet; @@ -3509,35 +3477,35 @@ namespace Ogre { if( datablock->mSamplersDescSet ) { - //Bind samplers + // Bind samplers size_t texUnit = mTexUnitSlotStart; *commandBuffer->addCommand() = - CbSamplers( texUnit, datablock->mSamplersDescSet ); + CbSamplers( texUnit, datablock->mSamplersDescSet ); mLastDescSampler = datablock->mSamplersDescSet; } } } - mCurrentMappedConstBuffer = currentMappedConstBuffer; - mCurrentMappedTexBuffer = currentMappedTexBuffer; + mCurrentMappedConstBuffer = currentMappedConstBuffer; + mCurrentMappedTexBuffer = currentMappedTexBuffer; - return ((mCurrentMappedConstBuffer - mStartMappedConstBuffer) >> 2) - 1; + return ( ( mCurrentMappedConstBuffer - mStartMappedConstBuffer ) >> 2 ) - 1; } //----------------------------------------------------------------------------------- void HlmsPbs::destroyAllBuffers() { HlmsBufferManager::destroyAllBuffers(); - mCurrentPassBuffer = 0; + mCurrentPassBuffer = 0; { ConstBufferPackedVec::const_iterator itor = mPassBuffers.begin(); - ConstBufferPackedVec::const_iterator end = mPassBuffers.end(); + ConstBufferPackedVec::const_iterator end = mPassBuffers.end(); while( itor != end ) { - if( (*itor)->getMappingState() != MS_UNMAPPED ) - (*itor)->unmap( UO_UNMAP_ALL ); + if( ( *itor )->getMappingState() != MS_UNMAPPED ) + ( *itor )->unmap( UO_UNMAP_ALL ); mVaoManager->destroyConstBuffer( *itor ); ++itor; } @@ -3550,11 +3518,11 @@ namespace Ogre ConstBufferPackedVec::const_iterator itor = mLight0Buffers.begin(); ConstBufferPackedVec::const_iterator end = mLight0Buffers.end(); - while (itor != end) + while( itor != end ) { - if ((*itor)->getMappingState() != MS_UNMAPPED) - (*itor)->unmap(UO_UNMAP_ALL); - mVaoManager->destroyConstBuffer(*itor); + if( ( *itor )->getMappingState() != MS_UNMAPPED ) + ( *itor )->unmap( UO_UNMAP_ALL ); + mVaoManager->destroyConstBuffer( *itor ); ++itor; } @@ -3564,11 +3532,11 @@ namespace Ogre ConstBufferPackedVec::const_iterator itor = mLight1Buffers.begin(); ConstBufferPackedVec::const_iterator end = mLight1Buffers.end(); - while (itor != end) + while( itor != end ) { - if ((*itor)->getMappingState() != MS_UNMAPPED) - (*itor)->unmap(UO_UNMAP_ALL); - mVaoManager->destroyConstBuffer(*itor); + if( ( *itor )->getMappingState() != MS_UNMAPPED ) + ( *itor )->unmap( UO_UNMAP_ALL ); + mVaoManager->destroyConstBuffer( *itor ); ++itor; } @@ -3578,17 +3546,16 @@ namespace Ogre ConstBufferPackedVec::const_iterator itor = mLight2Buffers.begin(); ConstBufferPackedVec::const_iterator end = mLight2Buffers.end(); - while (itor != end) + while( itor != end ) { - if ((*itor)->getMappingState() != MS_UNMAPPED) - (*itor)->unmap(UO_UNMAP_ALL); - mVaoManager->destroyConstBuffer(*itor); + if( ( *itor )->getMappingState() != MS_UNMAPPED ) + ( *itor )->unmap( UO_UNMAP_ALL ); + mVaoManager->destroyConstBuffer( *itor ); ++itor; } mLight2Buffers.clear(); } - } //----------------------------------------------------------------------------------- void HlmsPbs::postCommandBufferExecution( CommandBuffer *commandBuffer ) @@ -3597,8 +3564,8 @@ namespace Ogre if( mPrePassMsaaDepthTexture ) { - //We need to unbind the depth texture, it may be used as a depth buffer later. - size_t texUnit = mReservedTexBufferSlots + mReservedTexSlots + (mGridBuffer ? 2u : 0u); + // We need to unbind the depth texture, it may be used as a depth buffer later. + size_t texUnit = mReservedTexBufferSlots + mReservedTexSlots + ( mGridBuffer ? 2u : 0u ); if( !mPrePassTextures->empty() ) texUnit += 2; @@ -3609,7 +3576,7 @@ namespace Ogre void HlmsPbs::frameEnded() { HlmsBufferManager::frameEnded(); - mCurrentPassBuffer = 0; + mCurrentPassBuffer = 0; } //----------------------------------------------------------------------------------- void HlmsPbs::resetIblSpecMipmap( uint8 numMipmaps ) @@ -3629,14 +3596,14 @@ namespace Ogre while( itor != endt ) { - assert( dynamic_cast( itor->second.datablock ) ); - HlmsPbsDatablock *datablock = static_cast(itor->second.datablock); + assert( dynamic_cast( itor->second.datablock ) ); + HlmsPbsDatablock *datablock = static_cast( itor->second.datablock ); TextureGpu *reflTexture = datablock->getTexture( PBSM_REFLECTION ); if( reflTexture ) { mMaxSpecIblMipmap = - std::max( reflTexture->getNumMipmaps(), mMaxSpecIblMipmap ); + std::max( reflTexture->getNumMipmaps(), mMaxSpecIblMipmap ); } ++itor; } @@ -3647,7 +3614,7 @@ namespace Ogre if( bindTexture ) { mMaxSpecIblMipmap = - std::max( bindTexture->getNumMipmaps(), mMaxSpecIblMipmap ); + std::max( bindTexture->getNumMipmaps(), mMaxSpecIblMipmap ); } } } @@ -3668,20 +3635,14 @@ namespace Ogre textureGpuManager->reservePoolId( poolId, 64u, 64u, 3u, 1u, PFG_RGBA16_FLOAT ); TextureGpu *ltcMat0 = textureGpuManager->createOrRetrieveTexture( - "ltcMatrix0.dds", GpuPageOutStrategy::Discard, - TextureFlags::AutomaticBatching, - TextureTypes::Type2D, - ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); + "ltcMatrix0.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching, + TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); TextureGpu *ltcMat1 = textureGpuManager->createOrRetrieveTexture( - "ltcMatrix1.dds", GpuPageOutStrategy::Discard, - TextureFlags::AutomaticBatching, - TextureTypes::Type2D, - ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); + "ltcMatrix1.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching, + TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); TextureGpu *brtfLut2 = textureGpuManager->createOrRetrieveTexture( - "brtfLutDfg.dds", GpuPageOutStrategy::Discard, - TextureFlags::AutomaticBatching, - TextureTypes::Type2D, - ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); + "brtfLutDfg.dds", GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching, + TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, 0, poolId ); ltcMat0->scheduleTransitionTo( GpuResidency::Resident ); ltcMat1->scheduleTransitionTo( GpuResidency::Resident ); @@ -3706,25 +3667,25 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsPbs::getDefaultPaths( String &outDataFolderPath, StringVector &outLibraryFoldersPaths ) { - //We need to know what RenderSystem is currently in use, as the - //name of the compatible shading language is part of the path + // We need to know what RenderSystem is currently in use, as the + // name of the compatible shading language is part of the path Ogre::RenderSystem *renderSystem = Ogre::Root::getSingleton().getRenderSystem(); Ogre::String shaderSyntax = "GLSL"; - if (renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem") + if( renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem" ) shaderSyntax = "GLSLES"; - else if (renderSystem->getName() == "Direct3D11 Rendering Subsystem") + else if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) shaderSyntax = "HLSL"; - else if (renderSystem->getName() == "Metal Rendering Subsystem") + else if( renderSystem->getName() == "Metal Rendering Subsystem" ) shaderSyntax = "Metal"; - //Fill the library folder paths with the relevant folders + // Fill the library folder paths with the relevant folders outLibraryFoldersPaths.clear(); outLibraryFoldersPaths.push_back( "Hlms/Common/" + shaderSyntax ); outLibraryFoldersPaths.push_back( "Hlms/Common/Any" ); outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any" ); outLibraryFoldersPaths.push_back( "Hlms/Pbs/Any/Main" ); - //Fill the data folder path + // Fill the data folder path outDataFolderPath = "Hlms/Pbs/" + shaderSyntax; } //----------------------------------------------------------------------------------- @@ -3754,10 +3715,7 @@ namespace Ogre mEsmK = K; } //----------------------------------------------------------------------------------- - void HlmsPbs::setAmbientLightMode( AmbientLightMode mode ) - { - mAmbientLightMode = mode; - } + void HlmsPbs::setAmbientLightMode( AmbientLightMode mode ) { mAmbientLightMode = mode; } //----------------------------------------------------------------------------------- void HlmsPbs::setParallaxCorrectedCubemap( ParallaxCorrectedCubemapBase *pcc, float pccVctMinDistance, float pccVctMaxDistance ) @@ -3765,13 +3723,10 @@ namespace Ogre OGRE_ASSERT_LOW( pccVctMinDistance < pccVctMaxDistance ); mParallaxCorrectedCubemap = pcc; mPccVctMinDistance = pccVctMinDistance; - mInvPccVctInvDistance = 1.0f / (pccVctMaxDistance - pccVctMinDistance); + mInvPccVctInvDistance = 1.0f / ( pccVctMaxDistance - pccVctMinDistance ); } //----------------------------------------------------------------------------------- - void HlmsPbs::setAreaLightMasks( TextureGpu *areaLightMask ) - { - mAreaLightMasks = areaLightMask; - } + void HlmsPbs::setAreaLightMasks( TextureGpu *areaLightMask ) { mAreaLightMasks = areaLightMask; } //----------------------------------------------------------------------------------- void HlmsPbs::setLightProfilesTexture( TextureGpu *lightProfilesTex ) { @@ -3786,10 +3741,7 @@ namespace Ogre mHasPlanarReflections = false; } //----------------------------------------------------------------------------------- - PlanarReflections* HlmsPbs::getPlanarReflections() const - { - return mPlanarReflections; - } + PlanarReflections *HlmsPbs::getPlanarReflections() const { return mPlanarReflections; } #endif #if OGRE_ENABLE_LIGHT_OBB_RESTRAINT //----------------------------------------------------------------------------------- @@ -3799,42 +3751,38 @@ namespace Ogre mUseObbRestraintAreaLtc = areaLtc; } #endif - void HlmsPbs::setUseLightBuffers(bool b) - { - mUseLightBuffers = b; - } + void HlmsPbs::setUseLightBuffers( bool b ) { mUseLightBuffers = b; } #if !OGRE_NO_JSON //----------------------------------------------------------------------------------- void HlmsPbs::_loadJson( const rapidjson::Value &jsonValue, const HlmsJson::NamedBlocks &blocks, HlmsDatablock *datablock, const String &resourceGroup, HlmsJsonListener *listener, const String &additionalTextureExtension ) const { - HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), - listener, additionalTextureExtension ); + HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), listener, + additionalTextureExtension ); jsonPbs.loadMaterial( jsonValue, blocks, datablock, resourceGroup ); } //----------------------------------------------------------------------------------- void HlmsPbs::_saveJson( const HlmsDatablock *datablock, String &outString, - HlmsJsonListener *listener, - const String &additionalTextureExtension ) const + HlmsJsonListener *listener, const String &additionalTextureExtension ) const { - HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), - listener, additionalTextureExtension ); + HlmsJsonPbs jsonPbs( mHlmsManager, mRenderSystem->getTextureGpuManager(), listener, + additionalTextureExtension ); jsonPbs.saveMaterial( datablock, outString ); } //----------------------------------------------------------------------------------- - void HlmsPbs::_collectSamplerblocks( set::type &outSamplerblocks, + void HlmsPbs::_collectSamplerblocks( set::type &outSamplerblocks, const HlmsDatablock *datablock ) const { HlmsJsonPbs::collectSamplerblocks( datablock, outSamplerblocks ); } #endif //----------------------------------------------------------------------------------- - HlmsDatablock* HlmsPbs::createDatablockImpl( IdString datablockName, - const HlmsMacroblock *macroblock, - const HlmsBlendblock *blendblock, - const HlmsParamVec ¶mVec ) + HlmsDatablock *HlmsPbs::createDatablockImpl( IdString datablockName, + const HlmsMacroblock *macroblock, + const HlmsBlendblock *blendblock, + const HlmsParamVec ¶mVec ) { return OGRE_NEW HlmsPbsDatablock( datablockName, this, macroblock, blendblock, paramVec ); } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbsDatablock.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbsDatablock.cpp index 0cc1269d36a..706c2f267b0 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbsDatablock.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbsDatablock.cpp @@ -29,22 +29,23 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "OgreHlmsPbsDatablock.h" -#include "OgreHlmsPbs.h" + +#include "Cubemaps/OgreCubemapProbe.h" #include "OgreHlmsManager.h" +#include "OgreHlmsPbs.h" #include "OgreLogManager.h" -#include "OgreTextureGpu.h" -#include "OgreTextureGpuManager.h" -#include "OgreRenderSystem.h" -#include "OgreTextureFilters.h" -#include "Cubemaps/OgreCubemapProbe.h" #include "OgreProfiler.h" +#include "OgreRenderSystem.h" #include "OgreString.h" +#include "OgreTextureFilters.h" +#include "OgreTextureGpu.h" +#include "OgreTextureGpuManager.h" #define _OgreHlmsTextureBaseClassExport _OgreHlmsPbsExport #define OGRE_HLMS_TEXTURE_BASE_CLASS HlmsPbsBaseTextureDatablock #define OGRE_HLMS_TEXTURE_BASE_MAX_TEX NUM_PBSM_TEXTURE_TYPES #define OGRE_HLMS_CREATOR_CLASS HlmsPbs - #include "OgreHlmsTextureBaseClass.inl" +#include "OgreHlmsTextureBaseClass.inl" #undef _OgreHlmsTextureBaseClassExport #undef OGRE_HLMS_TEXTURE_BASE_CLASS #undef OGRE_HLMS_TEXTURE_BASE_MAX_TEX @@ -55,23 +56,19 @@ THE SOFTWARE. namespace Ogre { extern const String c_pbsBlendModes[]; - const String c_pbsBlendModes[] = - { - "NormalNonPremul", "NormalPremul", "Add", "Subtract", "Multiply", - "Multiply2x", "Screen", "Overlay", "Lighten", "Darken", "GrainExtract", - "GrainMerge", "Difference" - }; + const String c_pbsBlendModes[] = { "NormalNonPremul", "NormalPremul", "Add", "Subtract", + "Multiply", "Multiply2x", "Screen", "Overlay", + "Lighten", "Darken", "GrainExtract", "GrainMerge", + "Difference" }; - const size_t HlmsPbsDatablock::MaterialSizeInGpu = 60u * 4u + NUM_PBSM_TEXTURE_TYPES * 2u; - const size_t HlmsPbsDatablock::MaterialSizeInGpuAligned = alignToNextMultiple( - HlmsPbsDatablock::MaterialSizeInGpu, - 4 * 4 ); + const size_t HlmsPbsDatablock::MaterialSizeInGpu = 60u * 4u + NUM_PBSM_TEXTURE_TYPES * 2u; + const size_t HlmsPbsDatablock::MaterialSizeInGpuAligned = + alignToNextMultiple( HlmsPbsDatablock::MaterialSizeInGpu, 4 * 4 ); //----------------------------------------------------------------------------------- HlmsPbsDatablock::HlmsPbsDatablock( IdString name, HlmsPbs *creator, const HlmsMacroblock *macroblock, - const HlmsBlendblock *blendblock, - const HlmsParamVec ¶ms ) : + const HlmsBlendblock *blendblock, const HlmsParamVec ¶ms ) : HlmsPbsBaseTextureDatablock( name, creator, macroblock, blendblock, params ), mFresnelTypeSizeBytes( 4 ), mTwoSided( false ), @@ -82,11 +79,17 @@ namespace Ogre mUseEmissiveAsLightmap( false ), mUseDiffuseMapAsGrayscale( false ), mTransparencyMode( None ), - mkDr( 0.318309886f ), mkDg( 0.318309886f ), mkDb( 0.318309886f ), //Max Diffuse = 1 / PI + mkDr( 0.318309886f ), + mkDg( 0.318309886f ), + mkDb( 0.318309886f ), // Max Diffuse = 1 / PI _padding0( 1 ), - mkSr( 1 ), mkSg( 1 ), mkSb( 1 ), + mkSr( 1 ), + mkSg( 1 ), + mkSb( 1 ), mRoughness( 1.0f ), - mFresnelR( 0.818f ), mFresnelG( 0.818f ), mFresnelB( 0.818f ), + mFresnelR( 0.818f ), + mFresnelG( 0.818f ), + mFresnelB( 0.818f ), mTransparencyValue( 1.0f ), mNormalMapWeight( 1.0f ), mRefractionStrength( 0.075f ), @@ -105,7 +108,7 @@ namespace Ogre mDetailNormalWeight[0] = mDetailNormalWeight[1] = 1.0f; mDetailNormalWeight[2] = mDetailNormalWeight[3] = 1.0f; mDetailWeight[0] = mDetailWeight[1] = mDetailWeight[2] = mDetailWeight[3] = 1.0f; - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) { mDetailsOffsetScale[i][0] = 0; mDetailsOffsetScale[i][1] = 0; @@ -144,7 +147,8 @@ namespace Ogre if( mRoughness <= 1e-6f ) { LogManager::getSingleton().logMessage( "WARNING: PBS Datablock '" + - name.getFriendlyText() + "' Very low roughness values can " + name.getFriendlyText() + + "' Very low roughness values can " "cause NaNs in the pixel shader!" ); } } @@ -220,30 +224,27 @@ namespace Ogre setTextureUvSource( PBSM_ROUGHNESS, StringConverter::parseUnsignedInt( paramVal ) ); if( Hlms::findParamInVec( params, "uv_detail_weight_map", paramVal ) ) { - setTextureUvSource( PBSM_DETAIL_WEIGHT, - StringConverter::parseUnsignedInt( paramVal ) ); + setTextureUvSource( PBSM_DETAIL_WEIGHT, StringConverter::parseUnsignedInt( paramVal ) ); } - //Detail maps default to wrap mode. + // Detail maps default to wrap mode. HlmsSamplerblock detailSamplerRef; detailSamplerRef.mU = TAM_WRAP; detailSamplerRef.mV = TAM_WRAP; detailSamplerRef.mW = TAM_WRAP; String key; - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) { key.assign( "detail_map" ).push_back( '0' + i ); if( Hlms::findParamInVec( params, key, paramVal ) ) { TextureGpu *texture; texture = textureManager->createOrRetrieveTexture( - paramVal, GpuPageOutStrategy::Discard, - TextureFlags::AutomaticBatching | - TextureFlags::PrefersLoadingFromFileAsSRGB, - TextureTypes::Type2D, - ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, - TextureFilter::TypeGenerateDefaultMipmaps ); + paramVal, GpuPageOutStrategy::Discard, + TextureFlags::AutomaticBatching | TextureFlags::PrefersLoadingFromFileAsSRGB, + TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, + TextureFilter::TypeGenerateDefaultMipmaps ); setTexture( PBSM_DETAIL0 + i, texture, &detailSamplerRef ); } @@ -252,18 +253,17 @@ namespace Ogre { TextureGpu *texture; texture = textureManager->createOrRetrieveTexture( - paramVal, GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching, - TextureTypes::Type2D, - ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, - TextureFilter::TypeGenerateDefaultMipmaps | - TextureFilter::TypePrepareForNormalMapping ); + paramVal, GpuPageOutStrategy::Discard, TextureFlags::AutomaticBatching, + TextureTypes::Type2D, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, + TextureFilter::TypeGenerateDefaultMipmaps | + TextureFilter::TypePrepareForNormalMapping ); setTexture( PBSM_DETAIL0_NM + i, texture, &detailSamplerRef ); } key.assign( "detail_blend_mode" ).push_back( '0' + i ); if( Hlms::findParamInVec( params, key, paramVal ) ) { - for( size_t j=0; j( offsetScale[0] ); mDetailsOffsetScale[i][1] = static_cast( offsetScale[1] ); mDetailsOffsetScale[i][2] = static_cast( offsetScale[2] ); @@ -328,8 +328,7 @@ namespace Ogre } else { - LogManager::getSingleton().logMessage( - "ERROR: unknown transparency_mode: " + paramVal); + LogManager::getSingleton().logMessage( "ERROR: unknown transparency_mode: " + paramVal ); } applyTransparency = true; @@ -337,22 +336,22 @@ namespace Ogre if( Hlms::findParamInVec( params, "alpha_from_textures", paramVal ) ) { - transparencyAlphaFromTextures = StringConverter::parseBool( paramVal, - transparencyAlphaFromTextures ); + transparencyAlphaFromTextures = + StringConverter::parseBool( paramVal, transparencyAlphaFromTextures ); applyTransparency = true; } if( applyTransparency ) setTransparency( transparency, transparencyMode, transparencyAlphaFromTextures ); - creator->requestSlot( /*mTextureHash*/0, this, false ); + creator->requestSlot( /*mTextureHash*/ 0, this, false ); calculateHash(); } //----------------------------------------------------------------------------------- HlmsPbsDatablock::~HlmsPbsDatablock() { if( mAssignedPool ) - static_cast(mCreator)->releaseSlot( this ); + static_cast( mCreator )->releaseSlot( this ); } //----------------------------------------------------------------------------------- void HlmsPbsDatablock::calculateHash() @@ -361,46 +360,47 @@ namespace Ogre if( mTexturesDescSet ) { - FastArray::const_iterator itor = mTexturesDescSet->mTextures.begin(); - FastArray::const_iterator end = mTexturesDescSet->mTextures.end(); + FastArray::const_iterator itor = mTexturesDescSet->mTextures.begin(); + FastArray::const_iterator end = mTexturesDescSet->mTextures.end(); while( itor != end ) { - hash += (*itor)->getName(); + hash += ( *itor )->getName(); ++itor; } } if( mSamplersDescSet ) { - FastArray::const_iterator itor= mSamplersDescSet->mSamplers.begin(); - FastArray::const_iterator end = mSamplersDescSet->mSamplers.end(); + FastArray::const_iterator itor = + mSamplersDescSet->mSamplers.begin(); + FastArray::const_iterator end = mSamplersDescSet->mSamplers.end(); while( itor != end ) { - hash += IdString( (*itor)->mId ); + hash += IdString( ( *itor )->mId ); ++itor; } } const uint32 oldTexHash = mTextureHash; - if( static_cast(mCreator)->getOptimizationStrategy() == HlmsPbs::LowerGpuOverhead ) + if( static_cast( mCreator )->getOptimizationStrategy() == HlmsPbs::LowerGpuOverhead ) { - const size_t poolIdx = static_cast(mCreator)->getPoolIndex( this ); - const uint32 finalHash = (hash.mHash & 0xFFFFFE00) | (poolIdx & 0x000001FF); + const size_t poolIdx = static_cast( mCreator )->getPoolIndex( this ); + const uint32 finalHash = ( hash.mHash & 0xFFFFFE00 ) | ( poolIdx & 0x000001FF ); mTextureHash = finalHash; } else { - const size_t poolIdx = static_cast(mCreator)->getPoolIndex( this ); - const uint32 finalHash = (hash.mHash & 0xFFFFFFF0) | (poolIdx & 0x0000000F); + const size_t poolIdx = static_cast( mCreator )->getPoolIndex( this ); + const uint32 finalHash = ( hash.mHash & 0xFFFFFFF0 ) | ( poolIdx & 0x0000000F ); mTextureHash = finalHash; } - //When ParallaxCorrectedCubemaps are used, we set a const buffer with the - //probe's information. Thus we need to keep them in different pools + // When ParallaxCorrectedCubemaps are used, we set a const buffer with the + // probe's information. Thus we need to keep them in different pools if( oldTexHash != mTextureHash && mCubemapProbe ) { IdString probeHash( mCubemapProbe->getInternalTexture()->getName() ); - static_cast(mCreator)->requestSlot( probeHash.mHash, this, false ); + static_cast( mCreator )->requestSlot( probeHash.mHash, this, false ); } } //----------------------------------------------------------------------------------- @@ -413,16 +413,16 @@ namespace Ogre //----------------------------------------------------------------------------------- void HlmsPbsDatablock::scheduleConstBufferUpdate() { - static_cast(mCreator)->scheduleForUpdate( this ); + static_cast( mCreator )->scheduleForUpdate( this ); } //----------------------------------------------------------------------------------- void HlmsPbsDatablock::uploadToConstBuffer( char *dstPtr, uint8 dirtyFlags ) { - if( dirtyFlags & (ConstBufferPool::DirtyTextures|ConstBufferPool::DirtySamplers) ) + if( dirtyFlags & ( ConstBufferPool::DirtyTextures | ConstBufferPool::DirtySamplers ) ) { - //Must be called first so mTexIndices[i] gets updated before uploading to GPU. - updateDescriptorSets( (dirtyFlags & ConstBufferPool::DirtyTextures) != 0, - (dirtyFlags & ConstBufferPool::DirtySamplers) != 0 ); + // Must be called first so mTexIndices[i] gets updated before uploading to GPU. + updateDescriptorSets( ( dirtyFlags & ConstBufferPool::DirtyTextures ) != 0, + ( dirtyFlags & ConstBufferPool::DirtySamplers ) != 0 ); } _padding0 = mAlphaTestThreshold; @@ -436,7 +436,7 @@ namespace Ogre if( mTransparencyMode == Transparent || mTransparencyMode == Refractive ) { - //Precompute the transparency CPU-side. + // Precompute the transparency CPU-side. if( mWorkflow != MetallicWorkflow ) { mFresnelR *= mTransparencyValue; @@ -449,13 +449,13 @@ namespace Ogre } uint16 texIndices[OGRE_NumTexIndices]; - for( size_t i=0; icreateOrRetrieveTexture( name, GpuPageOutStrategy::Discard, - textureFlags, textureType, - ResourceGroupManager:: - AUTODETECT_RESOURCE_GROUP_NAME, - filters ); + texture = textureManager->createOrRetrieveTexture( + name, GpuPageOutStrategy::Discard, textureFlags, textureType, + ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, filters ); } setTexture( texUnit, texture, refParams ); } @@ -711,7 +693,7 @@ namespace Ogre bool wasOne = mDetailNormalWeight[detailNormalMapIdx] == 1.0f; mDetailNormalWeight[detailNormalMapIdx] = weight; - if( wasOne != (mDetailNormalWeight[detailNormalMapIdx] == 1.0f) ) + if( wasOne != ( mDetailNormalWeight[detailNormalMapIdx] == 1.0f ) ) flushRenderables(); scheduleConstBufferUpdate(); } @@ -727,15 +709,12 @@ namespace Ogre bool wasDisabled = mNormalMapWeight == 1.0f; mNormalMapWeight = weight; - if( wasDisabled != (mNormalMapWeight == 1.0f) ) + if( wasDisabled != ( mNormalMapWeight == 1.0f ) ) flushRenderables(); scheduleConstBufferUpdate(); } //----------------------------------------------------------------------------------- - Real HlmsPbsDatablock::getNormalMapWeight() const - { - return mNormalMapWeight; - } + Real HlmsPbsDatablock::getNormalMapWeight() const { return mNormalMapWeight; } //----------------------------------------------------------------------------------- void HlmsPbsDatablock::setDetailMapWeight( uint8 detailMap, Real weight ) { @@ -744,7 +723,7 @@ namespace Ogre mDetailWeight[detailMap] = weight; - if( wasDisabled != (mDetailWeight[detailMap] == 1.0f) ) + if( wasDisabled != ( mDetailWeight[detailMap] == 1.0f ) ) flushRenderables(); scheduleConstBufferUpdate(); @@ -766,7 +745,7 @@ namespace Ogre mDetailsOffsetScale[detailMap][2] = static_cast( offsetScale[2] ); mDetailsOffsetScale[detailMap][3] = static_cast( offsetScale[3] ); - if( wasDisabled != (getDetailMapOffsetScale( detailMap ) == Vector4( 0, 0, 1, 1 )) ) + if( wasDisabled != ( getDetailMapOffsetScale( detailMap ) == Vector4( 0, 0, 1, 1 ) ) ) { flushRenderables(); } @@ -802,19 +781,15 @@ namespace Ogre flushRenderables(); } //----------------------------------------------------------------------------------- - bool HlmsPbsDatablock::getTwoSidedLighting() const - { - return mTwoSided; - } + bool HlmsPbsDatablock::getTwoSidedLighting() const { return mTwoSided; } //----------------------------------------------------------------------------------- bool HlmsPbsDatablock::hasCustomShadowMacroblock() const { if( mTwoSided && - (mMacroblock[0]->mCullMode != CULL_NONE || - mMacroblock[1]->mCullMode != CULL_NONE) ) + ( mMacroblock[0]->mCullMode != CULL_NONE || mMacroblock[1]->mCullMode != CULL_NONE ) ) { - //Since we may have ignored what HlmsManager::setShadowMappingUseBackFaces - //says, we need to treat them as custom. + // Since we may have ignored what HlmsManager::setShadowMappingUseBackFaces + // says, we need to treat them as custom. return true; } @@ -843,7 +818,7 @@ namespace Ogre { bool mustFlush = false; - mTransparencyValue = transparency; + mTransparencyValue = transparency; if( mUseAlphaFromTextures != useAlphaFromTextures || mTransparencyMode != mode ) { @@ -858,20 +833,20 @@ namespace Ogre if( mTransparencyMode == None || mTransparencyMode == Refractive ) { - newBlendblock.mSourceBlendFactor = SBF_ONE; - newBlendblock.mDestBlendFactor = SBF_ZERO; + newBlendblock.mSourceBlendFactor = SBF_ONE; + newBlendblock.mDestBlendFactor = SBF_ZERO; if( mTransparencyMode == Refractive ) newBlendblock.setForceTransparentRenderOrder( true ); } else if( mTransparencyMode == Transparent ) { - newBlendblock.mSourceBlendFactor = SBF_ONE; - newBlendblock.mDestBlendFactor = SBF_ONE_MINUS_SOURCE_ALPHA; + newBlendblock.mSourceBlendFactor = SBF_ONE; + newBlendblock.mDestBlendFactor = SBF_ONE_MINUS_SOURCE_ALPHA; } else if( mTransparencyMode == Fade ) { - newBlendblock.mSourceBlendFactor = SBF_SOURCE_ALPHA; - newBlendblock.mDestBlendFactor = SBF_ONE_MINUS_SOURCE_ALPHA; + newBlendblock.mSourceBlendFactor = SBF_SOURCE_ALPHA; + newBlendblock.mDestBlendFactor = SBF_ONE_MINUS_SOURCE_ALPHA; } if( newBlendblock != *mBlendblock[0] ) @@ -890,16 +865,16 @@ namespace Ogre if( mTransparencyMode == None && mBlendblock[0]->mIsTransparent ) { LogManager::getSingleton().logMessage( - "WARNING: PBS Datablock '" + *getNameStr() + - "' disabling transparency but forcing a blendblock to" - " keep using alpha blending. Performance will be affected." ); + "WARNING: PBS Datablock '" + *getNameStr() + + "' disabling transparency but forcing a blendblock to" + " keep using alpha blending. Performance will be affected." ); } else if( mTransparencyMode != None && !mBlendblock[0]->mIsTransparent ) { LogManager::getSingleton().logMessage( - "WARNING: PBS Datablock '" + *getNameStr() + - "' enabling transparency but forcing a blendblock to avoid" - " alpha blending. Results may not look as expected." ); + "WARNING: PBS Datablock '" + *getNameStr() + + "' enabling transparency but forcing a blendblock to avoid" + " alpha blending. Results may not look as expected." ); } } @@ -961,10 +936,7 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - bool HlmsPbsDatablock::getUseEmissiveAsLightmap() const - { - return mUseEmissiveAsLightmap; - } + bool HlmsPbsDatablock::getUseEmissiveAsLightmap() const { return mUseEmissiveAsLightmap; } //----------------------------------------------------------------------------------- void HlmsPbsDatablock::setUseDiffuseMapAsGrayscale( bool bUseDiffuseMapAsGrayscale ) { @@ -975,28 +947,22 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - bool HlmsPbsDatablock::getUseDiffuseMapAsGrayscale() const - { - return mUseDiffuseMapAsGrayscale; - } + bool HlmsPbsDatablock::getUseDiffuseMapAsGrayscale() const { return mUseDiffuseMapAsGrayscale; } //----------------------------------------------------------------------------------- - bool HlmsPbsDatablock::getReceiveShadows() const - { - return mReceiveShadows; - } + bool HlmsPbsDatablock::getReceiveShadows() const { return mReceiveShadows; } //----------------------------------------------------------------------------------- - void HlmsPbsDatablock::setUserValue(uint8 userValueIdx, const Vector4 &value) + void HlmsPbsDatablock::setUserValue( uint8 userValueIdx, const Vector4 &value ) { - assert(userValueIdx < 3); + assert( userValueIdx < 3 ); mUserValue[userValueIdx][0] = value.x; mUserValue[userValueIdx][1] = value.y; mUserValue[userValueIdx][2] = value.z; mUserValue[userValueIdx][3] = value.w; } //----------------------------------------------------------------------------------- - Vector4 HlmsPbsDatablock::getUserValue(uint8 userValueIdx) const + Vector4 HlmsPbsDatablock::getUserValue( uint8 userValueIdx ) const { - assert(userValueIdx < 3); + assert( userValueIdx < 3 ); return Vector4( mUserValue[userValueIdx][0], mUserValue[userValueIdx][1], mUserValue[userValueIdx][2], mUserValue[userValueIdx][3] ); } @@ -1016,15 +982,12 @@ namespace Ogre } else { - setTexture( PBSM_REFLECTION, (TextureGpu*)0, 0 ); + setTexture( PBSM_REFLECTION, (TextureGpu *)0, 0 ); } } } //----------------------------------------------------------------------------------- - CubemapProbe* HlmsPbsDatablock::getCubemapProbe() const - { - return mCubemapProbe; - } + CubemapProbe *HlmsPbsDatablock::getCubemapProbe() const { return mCubemapProbe; } //----------------------------------------------------------------------------------- void HlmsPbsDatablock::setBrdf( PbsBrdf::PbsBrdf brdf ) { @@ -1034,13 +997,14 @@ namespace Ogre const PbsBrdf::PbsBrdf newBrdf = brdf; mBrdf = brdf; - //BlinnPhongFullLegacy expects diffuse in range [0; 1]; we have it in range [0; 1 / PI] + // BlinnPhongFullLegacy expects diffuse in range [0; 1]; we have it in range [0; 1 / PI] if( oldBrdf == PbsBrdf::BlinnPhongFullLegacy && newBrdf != PbsBrdf::BlinnPhongFullLegacy ) - setDiffuse( Vector3( mkDr, mkDg, mkDb ) ); //Will be divided by PI. + setDiffuse( Vector3( mkDr, mkDg, mkDb ) ); // Will be divided by PI. if( oldBrdf != PbsBrdf::BlinnPhongFullLegacy && newBrdf == PbsBrdf::BlinnPhongFullLegacy ) - setDiffuse( Vector3( mkDr, mkDg, mkDb ) * Math::PI ); //Increase by PI, won't be divided. + setDiffuse( Vector3( mkDr, mkDg, mkDb ) * + Math::PI ); // Increase by PI, won't be divided. - //BlinnPhongLegacyMath expects specular in range [0; 1 / PI]; we have it in range [0; 1] + // BlinnPhongLegacyMath expects specular in range [0; 1 / PI]; we have it in range [0; 1] if( oldBrdf == PbsBrdf::BlinnPhongLegacyMath && newBrdf != PbsBrdf::BlinnPhongLegacyMath ) setSpecular( Vector3( mkSr, mkSg, mkSb ) * Math::PI ); if( oldBrdf != PbsBrdf::BlinnPhongLegacyMath && newBrdf == PbsBrdf::BlinnPhongLegacyMath ) @@ -1050,17 +1014,14 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - uint32 HlmsPbsDatablock::getBrdf() const - { - return mBrdf; - } + uint32 HlmsPbsDatablock::getBrdf() const { return mBrdf; } //----------------------------------------------------------------------------------- - void HlmsPbsDatablock::importUnity( const Vector3 &diffuse, const Vector3 &specular, - Real roughness, bool changeBrdf ) + void HlmsPbsDatablock::importUnity( const Vector3 &diffuse, const Vector3 &specular, Real roughness, + bool changeBrdf ) { if( changeBrdf ) { - //Set the BRDF that matches Unity the closest. + // Set the BRDF that matches Unity the closest. setBrdf( PbsBrdf::DefaultUncorrelated ); } @@ -1068,8 +1029,8 @@ namespace Ogre setDiffuse( diffuse ); - //Unity uses coloured fresnel as if it were specular. So we need to - //set our kS to white and use the fresnel for colouring instead. + // Unity uses coloured fresnel as if it were specular. So we need to + // set our kS to white and use the fresnel for colouring instead. setSpecular( Vector3::UNIT_SCALE ); bool separateFresnel = false; if( Math::Abs( specular.x - specular.y ) <= 1e-5f && @@ -1082,12 +1043,12 @@ namespace Ogre setRoughness( roughness ); } //----------------------------------------------------------------------------------- - void HlmsPbsDatablock::importUnity( const Vector3 &colour, Real metallic, - Real roughness, bool changeBrdf ) + void HlmsPbsDatablock::importUnity( const Vector3 &colour, Real metallic, Real roughness, + bool changeBrdf ) { if( changeBrdf ) { - //Set the BRDF that matches Unity the closest. + // Set the BRDF that matches Unity the closest. setBrdf( PbsBrdf::DefaultUncorrelated ); } @@ -1104,7 +1065,7 @@ namespace Ogre bool HlmsPbsDatablock::suggestUsingSRGB( PbsTextureTypes type ) const { if( type == PBSM_NORMAL || type == PBSM_ROUGHNESS || type == PBSM_DETAIL_WEIGHT || - (type >= PBSM_DETAIL0_NM && type <= PBSM_DETAIL3_NM) ) + ( type >= PBSM_DETAIL0_NM && type <= PBSM_DETAIL3_NM ) ) { return false; } @@ -1153,19 +1114,12 @@ namespace Ogre return retVal; } //----------------------------------------------------------------------------------- - TextureGpu* HlmsPbsDatablock::getDiffuseTexture() const - { - return getTexture( PBSM_DIFFUSE ); - } + TextureGpu *HlmsPbsDatablock::getDiffuseTexture() const { return getTexture( PBSM_DIFFUSE ); } //----------------------------------------------------------------------------------- - TextureGpu* HlmsPbsDatablock::getEmissiveTexture() const - { - return getTexture( PBSM_EMISSIVE ); - } + TextureGpu *HlmsPbsDatablock::getEmissiveTexture() const { return getTexture( PBSM_EMISSIVE ); } //----------------------------------------------------------------------------------- - void HlmsPbsDatablock::notifyTextureChanged( TextureGpu *texture, - TextureGpuListener::Reason reason, - void *extraData ) + void HlmsPbsDatablock::notifyTextureChanged( TextureGpu *texture, TextureGpuListener::Reason reason, + void *extraData ) { HlmsPbsBaseTextureDatablock::notifyTextureChanged( texture, reason, extraData ); if( texture == mTextures[PBSM_REFLECTION] ) @@ -1177,4 +1131,4 @@ namespace Ogre } } } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/OgreIrradianceVolume.cpp b/Components/Hlms/Pbs/src/OgreIrradianceVolume.cpp index 88667d9d930..bab01779533 100644 --- a/Components/Hlms/Pbs/src/OgreIrradianceVolume.cpp +++ b/Components/Hlms/Pbs/src/OgreIrradianceVolume.cpp @@ -29,14 +29,13 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "OgreIrradianceVolume.h" -#include "OgreHlmsPbsDatablock.h" -#include "OgreHlmsPbs.h" -#include "OgreHlmsManager.h" - -#include "OgreTextureGpuManager.h" -#include "OgreStagingTexture.h" +#include "OgreHlmsManager.h" +#include "OgreHlmsPbs.h" +#include "OgreHlmsPbsDatablock.h" #include "OgreLwString.h" +#include "OgreStagingTexture.h" +#include "OgreTextureGpuManager.h" namespace Ogre { @@ -65,7 +64,7 @@ namespace Ogre freeMemory(); } //----------------------------------------------------------------------------------- - void IrradianceVolume::gaussFilter( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + void IrradianceVolume::gaussFilter( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth ) { /*const float c_kernel[17] = @@ -77,43 +76,45 @@ namespace Ogre const int kernelStart = -8; const int kernelEnd = 8;*/ + // clang-format off const float c_kernel[9] = { 0.028532f, 0.067234f, 0.124009f, 0.179044f, 0.20236f, 0.179044f, 0.124009f, 0.067234f, 0.028532f }; + // clang-format on const int kernelStart = -4; - const int kernelEnd = 4; - - gaussFilterX( dstData, srcData, texWidth, texHeight, texDepth, - c_kernel, kernelStart, kernelEnd ); - gaussFilterY( srcData, dstData, texWidth, texHeight, texDepth, - c_kernel, kernelStart, kernelEnd ); - gaussFilterZ( dstData, srcData, texWidth, texHeight, texDepth, - c_kernel, kernelStart, kernelEnd ); + const int kernelEnd = 4; + + gaussFilterX( dstData, srcData, texWidth, texHeight, texDepth, c_kernel, kernelStart, + kernelEnd ); + gaussFilterY( srcData, dstData, texWidth, texHeight, texDepth, c_kernel, kernelStart, + kernelEnd ); + gaussFilterZ( dstData, srcData, texWidth, texHeight, texDepth, c_kernel, kernelStart, + kernelEnd ); } //----------------------------------------------------------------------------------- - void IrradianceVolume::gaussFilterX( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + void IrradianceVolume::gaussFilterX( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth, - const float * RESTRICT_ALIAS kernel, - int kernelStart, int kernelEnd ) + const float *RESTRICT_ALIAS kernel, int kernelStart, + int kernelEnd ) { const size_t rowPitch = texWidth * 3u; const size_t slicePitch = rowPitch * texHeight; - //X filter - for( size_t z=0; z( -(int)x, kernelStart ); - const int kEnd = std::min( texWidth - 1 - x, kernelEnd ); + const int kStart = std::max( -(int)x, kernelStart ); + const int kEnd = std::min( texWidth - 1 - x, kernelEnd ); - for( int i=0; i<6; ++i ) + for( int i = 0; i < 6; ++i ) { float accumR = 0; float accumG = 0; @@ -121,51 +122,51 @@ namespace Ogre float divisor = 0; - size_t srcIdx = z * slicePitch + (y + i) * rowPitch + (x + kStart) * 3u; + size_t srcIdx = z * slicePitch + ( y + i ) * rowPitch + ( x + kStart ) * 3u; - for( int k=kStart; k<=kEnd; ++k ) + for( int k = kStart; k <= kEnd; ++k ) { - const float kernelVal = kernel[k+kernelEnd]; + const float kernelVal = kernel[k + kernelEnd]; - accumR += srcData[srcIdx+0] * kernelVal; - accumG += srcData[srcIdx+1] * kernelVal; - accumB += srcData[srcIdx+2] * kernelVal; + accumR += srcData[srcIdx + 0] * kernelVal; + accumG += srcData[srcIdx + 1] * kernelVal; + accumB += srcData[srcIdx + 2] * kernelVal; divisor += kernelVal; srcIdx += 3; } float invDivisor = 1.0f / divisor; - const size_t dstIdx = z * slicePitch + (y + i) * rowPitch + x * 3u; + const size_t dstIdx = z * slicePitch + ( y + i ) * rowPitch + x * 3u; - dstData[dstIdx+0] = accumR * invDivisor; - dstData[dstIdx+1] = accumG * invDivisor; - dstData[dstIdx+2] = accumB * invDivisor; + dstData[dstIdx + 0] = accumR * invDivisor; + dstData[dstIdx + 1] = accumG * invDivisor; + dstData[dstIdx + 2] = accumB * invDivisor; } } } } } //----------------------------------------------------------------------------------- - void IrradianceVolume::gaussFilterY( float * RESTRICT_ALIAS dstData, float * RESTRICT_ALIAS srcData, + void IrradianceVolume::gaussFilterY( float *RESTRICT_ALIAS dstData, float *RESTRICT_ALIAS srcData, size_t texWidth, size_t texHeight, size_t texDepth, - const float * RESTRICT_ALIAS kernel, - int kernelStart, int kernelEnd ) + const float *RESTRICT_ALIAS kernel, int kernelStart, + int kernelEnd ) { const size_t rowPitch = texWidth * 3u; const size_t slicePitch = rowPitch * texHeight; - //Y filter - for( size_t z=0; z( -(int)(y / 6u), kernelStart ); - const int kEnd = std::min( (texHeight - 6u - y) / 6u, kernelEnd ); + const int kStart = std::max( -(int)( y / 6u ), kernelStart ); + const int kEnd = std::min( ( texHeight - 6u - y ) / 6u, kernelEnd ); - for( size_t x=0; x( -(int)z, kernelStart ); - const int kEnd = std::min( texDepth - 1u - z, kernelEnd ); + const int kStart = std::max( -(int)z, kernelStart ); + const int kEnd = std::min( texDepth - 1u - z, kernelEnd ); - for( size_t y=0; y() ); TextureGpuManager *textureManager = mHlmsManager->getRenderSystem()->getTextureGpuManager(); @@ -278,8 +280,8 @@ namespace Ogre 0, TextureTypes::Type3D ); mIrradianceVolume->setResolution( width, height, depth ); mIrradianceVolume->setPixelFormat( PFG_R10G10B10A2_UNORM ); - //mIrradianceVolume->setNumMipmaps( maxMipCount ); - mIrradianceVolume->_transitionTo( GpuResidency::Resident, (uint8*)0 ); + // mIrradianceVolume->setNumMipmaps( maxMipCount ); + mIrradianceVolume->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); mIrradianceVolume->_setNextResidencyStatus( GpuResidency::Resident ); HlmsSamplerblock samplerblock; @@ -318,12 +320,13 @@ namespace Ogre } } - void IrradianceVolume::changeVolumeData(uint32 x, uint32 y, uint32 z, uint32 direction_id, const Vector3& delta) + void IrradianceVolume::changeVolumeData( uint32 x, uint32 y, uint32 z, uint32 direction_id, + const Vector3 &delta ) { assert( mVolumeData ); assert( direction_id < 6 ); - const size_t idx = z * mSlicePitch + (y * 6 + direction_id) * mRowPitch + x * 3u; + const size_t idx = z * mSlicePitch + ( y * 6 + direction_id ) * mRowPitch + x * 3u; mVolumeData[idx + 0] += delta.x; mVolumeData[idx + 1] += delta.y; mVolumeData[idx + 2] += delta.z; @@ -337,62 +340,61 @@ namespace Ogre { const int32 texWidth = static_cast( mIrradianceVolume->getWidth() ); const int32 texHeight = static_cast( mIrradianceVolume->getHeight() ); - const int32 texDepth = static_cast( mIrradianceVolume->getDepth() ); + const int32 texDepth = static_cast( mIrradianceVolume->getDepth() ); - mVolumeData = reinterpret_cast( OGRE_MALLOC( texWidth * texHeight * - texDepth * 3u * sizeof(float), - MEMCATEGORY_GENERAL ) ); - mBlurredVolumeData = reinterpret_cast( OGRE_MALLOC( texWidth * texHeight * - texDepth * 3u * sizeof(float), - MEMCATEGORY_GENERAL ) ); + mVolumeData = reinterpret_cast( OGRE_MALLOC( + texWidth * texHeight * texDepth * 3u * sizeof( float ), MEMCATEGORY_GENERAL ) ); + mBlurredVolumeData = reinterpret_cast( OGRE_MALLOC( + texWidth * texHeight * texDepth * 3u * sizeof( float ), MEMCATEGORY_GENERAL ) ); - memset( mVolumeData, 0, texWidth * texHeight * texDepth * 3u * sizeof(float) ); + memset( mVolumeData, 0, texWidth * texHeight * texDepth * 3u * sizeof( float ) ); } } void IrradianceVolume::updateIrradianceVolumeTexture() { - const int32 texWidth = static_cast( mIrradianceVolume->getWidth() ); + const int32 texWidth = static_cast( mIrradianceVolume->getWidth() ); const int32 texHeight = static_cast( mIrradianceVolume->getHeight() ); - const int32 texDepth = static_cast( mIrradianceVolume->getDepth() ); + const int32 texDepth = static_cast( mIrradianceVolume->getDepth() ); gaussFilter( mBlurredVolumeData, mVolumeData, texWidth, texHeight, texDepth ); TextureGpuManager *textureManager = mHlmsManager->getRenderSystem()->getTextureGpuManager(); StagingTexture *stagingTexture = - textureManager->getStagingTexture( mIrradianceVolume->getWidth(), - mIrradianceVolume->getHeight(), - mIrradianceVolume->getDepth(), - mIrradianceVolume->getNumSlices(), - mIrradianceVolume->getPixelFormat(), 100u ); + textureManager->getStagingTexture( mIrradianceVolume->getWidth(), // + mIrradianceVolume->getHeight(), // + mIrradianceVolume->getDepth(), // + mIrradianceVolume->getNumSlices(), // + mIrradianceVolume->getPixelFormat(), // + 100u ); stagingTexture->startMapRegion(); - TextureBox dstBox = stagingTexture->mapRegion( mIrradianceVolume->getWidth(), - mIrradianceVolume->getHeight(), - mIrradianceVolume->getDepth(), - mIrradianceVolume->getNumSlices(), + TextureBox dstBox = stagingTexture->mapRegion( mIrradianceVolume->getWidth(), // + mIrradianceVolume->getHeight(), // + mIrradianceVolume->getDepth(), // + mIrradianceVolume->getNumSlices(), // mIrradianceVolume->getPixelFormat() ); const size_t bytesPerPixel = dstBox.bytesPerPixel; - const size_t rowPitch = texWidth * 3u; + const size_t rowPitch = texWidth * 3u; const size_t slicePitch = rowPitch * texHeight; - for (size_t z = 0; z<(size_t)texDepth; ++z) + for( size_t z = 0; z < (size_t)texDepth; ++z ) { - for( size_t y=0; y<(size_t)texHeight; ++y ) + for( size_t y = 0; y < (size_t)texHeight; ++y ) { - uint8 * RESTRICT_ALIAS dstData = - reinterpret_cast( dstBox.at( 0, y, z ) ); - for( size_t x=0; x<(size_t)texWidth; ++x ) + uint8 *RESTRICT_ALIAS dstData = + reinterpret_cast( dstBox.at( 0, y, z ) ); + for( size_t x = 0; x < (size_t)texWidth; ++x ) { const size_t srcIdx = z * slicePitch + y * rowPitch + x * 3u; const size_t dstIdx = x * bytesPerPixel; float rgba[4]; - rgba[0] = mBlurredVolumeData[srcIdx+0]; - rgba[1] = mBlurredVolumeData[srcIdx+1]; - rgba[2] = mBlurredVolumeData[srcIdx+2]; + rgba[0] = mBlurredVolumeData[srcIdx + 0]; + rgba[1] = mBlurredVolumeData[srcIdx + 1]; + rgba[2] = mBlurredVolumeData[srcIdx + 2]; rgba[3] = 1.0f; PixelFormatGpuUtils::packColour( rgba, PFG_R10G10B10A2_UNORM, &dstData[dstIdx] ); } @@ -405,4 +407,4 @@ namespace Ogre if( !mIrradianceVolume->isDataReady() ) mIrradianceVolume->notifyDataIsReady(); } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Vct/OgreVctLighting.cpp b/Components/Hlms/Pbs/src/Vct/OgreVctLighting.cpp index 11acd05ab8e..fd254013a4f 100644 --- a/Components/Hlms/Pbs/src/Vct/OgreVctLighting.cpp +++ b/Components/Hlms/Pbs/src/Vct/OgreVctLighting.cpp @@ -36,37 +36,32 @@ THE SOFTWARE. #include "OgreHlmsCompute.h" #include "OgreHlmsComputeJob.h" #include "OgreHlmsManager.h" -#include "OgreShaderPrimitives.h" - -#include "OgreTextureGpuManager.h" -#include "OgreStringConverter.h" - +#include "OgreLight.h" +#include "OgreLwString.h" #include "OgrePixelFormatGpuUtils.h" #include "OgreRenderSystem.h" #include "OgreSceneManager.h" - -#include "OgreLight.h" +#include "OgreShaderPrimitives.h" +#include "OgreStringConverter.h" +#include "OgreTextureGpuManager.h" #include "Vao/OgreConstBufferPacked.h" #include "Vao/OgreVaoManager.h" -#include "OgreLwString.h" - - namespace Ogre { struct ShaderVctLight { - //Pre-mul by PI? -No because we lose a ton of precision + // Pre-mul by PI? -No because we lose a ton of precision //.w contains lightDistThreshold float diffuse[4]; - //For directional lights, pos.xyz contains -dir.xyz and pos.w = 0; - //For the rest of lights, pos.xyz contains pos.xyz and pos.w = 1; + // For directional lights, pos.xyz contains -dir.xyz and pos.w = 0; + // For the rest of lights, pos.xyz contains pos.xyz and pos.w = 1; float pos[4]; - //uvwPos.w contains the light type + // uvwPos.w contains the light type float uvwPos[4]; - //Used by area lights - //points[0].w contains double sided info + // Used by area lights + // points[0].w contains double sided info float points[4][4]; }; @@ -107,9 +102,9 @@ namespace Ogre mMultiplier( 1.0f ), mDebugVoxelVisualizer( 0 ) { - memset( mLightVoxel, 0, sizeof(mLightVoxel) ); - memset( mUpperHemisphere, 0, sizeof(mUpperHemisphere) ); - memset( mLowerHemisphere, 0, sizeof(mLowerHemisphere) ); + memset( mLightVoxel, 0, sizeof( mLightVoxel ) ); + memset( mUpperHemisphere, 0, sizeof( mUpperHemisphere ) ); + memset( mLowerHemisphere, 0, sizeof( mLowerHemisphere ) ); OGRE_ASSERT_LOW( mVoxelizer->getAlbedoVox() && "VctVoxelizer::build must've been called before creating VctLighting!" ); @@ -118,8 +113,8 @@ namespace Ogre mVoxelizer->getNormalVox()->addListener( this ); mVoxelizerListenersRemoved = false; - //VctVoxelizer should've already been initialized, thus no need - //to check if JSON has been built or if the assets were added + // VctVoxelizer should've already been initialized, thus no need + // to check if JSON has been built or if the assets were added HlmsCompute *hlmsCompute = mVoxelizer->getHlmsManager()->getComputeHlms(); mLightInjectionJob = hlmsCompute->findComputeJob( "VCT/LightInjection" ); @@ -128,12 +123,12 @@ namespace Ogre mRayMarchStepSize = mShaderParams->findParameter( "rayMarchStepSize_bakingMultiplier" ); mVoxelCellSize = mShaderParams->findParameter( "voxelCellSize" ); mDirCorrectionRatioThinWallCounter = - mShaderParams->findParameter( "dirCorrectionRatio_thinWallCounter" ); + mShaderParams->findParameter( "dirCorrectionRatio_thinWallCounter" ); mInvVoxelResolution = mShaderParams->findParameter( "invVoxelResolution" ); RenderSystem *renderSystem = mVoxelizer->getRenderSystem(); VaoManager *vaoManager = renderSystem->getVaoManager(); - mLightsConstBuffer = vaoManager->createConstBuffer( sizeof(ShaderVctLight) * 16u, + mLightsConstBuffer = vaoManager->createConstBuffer( sizeof( ShaderVctLight ) * 16u, BT_DYNAMIC_PERSISTENT, 0, false ); HlmsManager *hlmsManager = mVoxelizer->getHlmsManager(); @@ -220,18 +215,18 @@ namespace Ogre } } //------------------------------------------------------------------------- - float VctLighting::addLight( ShaderVctLight * RESTRICT_ALIAS vctLight, Light *light, + float VctLighting::addLight( ShaderVctLight *RESTRICT_ALIAS vctLight, Light *light, const Vector3 &voxelOrigin, const Vector3 &invVoxelSize ) { const ColourValue diffuseColour = light->getDiffuseColour() * light->getPowerScale(); - for( size_t i=0; i<3u; ++i ) + for( size_t i = 0; i < 3u; ++i ) vctLight->diffuse[i] = static_cast( diffuseColour[i] ); const Vector4 *lightDistThreshold = - light->getCustomParameterNoThrow( msDistanceThresholdCustomParam ); - vctLight->diffuse[3] = lightDistThreshold ? - (lightDistThreshold->x * lightDistThreshold->x) : - (mDefaultLightDistThreshold * mDefaultLightDistThreshold); + light->getCustomParameterNoThrow( msDistanceThresholdCustomParam ); + vctLight->diffuse[3] = lightDistThreshold + ? ( lightDistThreshold->x * lightDistThreshold->x ) + : ( mDefaultLightDistThreshold * mDefaultLightDistThreshold ); Light::LightTypes lightType = light->getType(); if( lightType == Light::LT_AREA_APPROX ) @@ -241,12 +236,12 @@ namespace Ogre if( lightType != Light::LT_DIRECTIONAL ) light4dVec -= Vector4( voxelOrigin, 0.0f ); - for( size_t i=0; i<4u; ++i ) + for( size_t i = 0; i < 4u; ++i ) vctLight->pos[i] = static_cast( light4dVec[i] ); Vector3 uvwPos = light->getParentNode()->_getDerivedPosition(); - uvwPos = (uvwPos - voxelOrigin) * invVoxelSize; - for( size_t i=0; i<3u; ++i ) + uvwPos = ( uvwPos - voxelOrigin ) * invVoxelSize; + for( size_t i = 0; i < 3u; ++i ) vctLight->uvwPos[i] = static_cast( uvwPos[i] ); vctLight->uvwPos[3] = static_cast( lightType ); @@ -269,16 +264,16 @@ namespace Ogre } else { - memset( rectPoints, 0, sizeof(rectPoints) ); + memset( rectPoints, 0, sizeof( rectPoints ) ); if( lightType == Light::LT_SPOTLIGHT ) { - //float3 spotDirection + // float3 spotDirection rectPoints[0].x = -lightDir.x; rectPoints[0].y = -lightDir.y; rectPoints[0].z = -lightDir.z; - //float3 spotParams + // float3 spotParams const Radian innerAngle = light->getSpotlightInnerAngle(); const Radian outerAngle = light->getSpotlightOuterAngle(); rectPoints[1].x = 1.0f / ( cosf( innerAngle.valueRadians() * 0.5f ) - @@ -289,9 +284,9 @@ namespace Ogre } const float isDoubleSided = light->getDoubleSided() ? 1.0f : 0.0f; - for( size_t i=0; i<4u; ++i ) + for( size_t i = 0; i < 4u; ++i ) { - for( size_t j=0; j<3u; ++j ) + for( size_t j = 0; j < 3u; ++j ) vctLight->points[i][j] = rectPoints[i][j]; vctLight->points[i][3u] = isDoubleSided; } @@ -321,39 +316,37 @@ namespace Ogre const TextureGpu *albedoVox = mVoxelizer->getAlbedoVox(); - const uint32 width = albedoVox->getWidth(); + const uint32 width = albedoVox->getWidth(); const uint32 height = albedoVox->getHeight(); - const uint32 depth = albedoVox->getDepth(); + const uint32 depth = albedoVox->getDepth(); - const uint32 widthAniso = std::max( 1u, width ); - const uint32 heightAniso = std::max( 1u, height >> 1u ); - const uint32 depthAniso = std::max( 1u, depth >> 1u ); + const uint32 widthAniso = std::max( 1u, width ); + const uint32 heightAniso = std::max( 1u, height >> 1u ); + const uint32 depthAniso = std::max( 1u, depth >> 1u ); - const uint8 numMipsMain = (mAnisotropic && !bSdfQuality) ? - 1u : - PixelFormatGpuUtils::getMaxMipmapCount( width, height, depth ); - //numMipsAniso needs one less mip; because the last mip must be 2x1x1, not 1x1x1 + const uint8 numMipsMain = ( mAnisotropic && !bSdfQuality ) + ? 1u + : PixelFormatGpuUtils::getMaxMipmapCount( width, height, depth ); + // numMipsAniso needs one less mip; because the last mip must be 2x1x1, not 1x1x1 const uint8 numMipsAniso = - PixelFormatGpuUtils::getMaxMipmapCount( widthAniso, heightAniso, depthAniso ) - 1u; + PixelFormatGpuUtils::getMaxMipmapCount( widthAniso, heightAniso, depthAniso ) - 1u; const size_t numTextures = mAnisotropic ? 4u : 1u; - const char *names[] = - { - "Main", - "X_axis", - "Y_axis", - "Z_axis" + const char *names[] = { + "Main", // + "X_axis", // + "Y_axis", // + "Z_axis" // }; - for( size_t i=0; icreateTexture( texName.c_str(), - GpuPageOutStrategy::Discard, - texFlags, TextureTypes::Type3D ); + TextureGpu *texture = textureManager->createTexture( + texName.c_str(), GpuPageOutStrategy::Discard, texFlags, TextureTypes::Type3D ); if( i == 0u ) { texture->setResolution( width, height, depth ); @@ -368,86 +361,85 @@ namespace Ogre texture->scheduleTransitionTo( GpuResidency::Resident ); mLightVoxel[i] = texture; - texFlags &= (uint32)~(TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps); + texFlags &= ( uint32 ) ~( TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps ); } if( mAnisotropic ) { - //Setup the compute shaders for VctLighting::generateAnisotropicMips() + // Setup the compute shaders for VctLighting::generateAnisotropicMips() HlmsCompute *hlmsCompute = mVoxelizer->getHlmsManager()->getComputeHlms(); mAnisoGeneratorStep0 = hlmsCompute->findComputeJob( "VCT/AnisotropicMipStep0" ); char tmpBuffer[128]; - LwString jobName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString jobName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); - //Step 0 + // Step 0 jobName.clear(); jobName.a( "VCT/AnisotropicMipStep0/Id", getId() ); mAnisoGeneratorStep0 = mAnisoGeneratorStep0->clone( jobName.c_str() ); - for( uint8 i=0; i<3u; ++i ) + for( uint8 i = 0; i < 3u; ++i ) { DescriptorSetUav::TextureSlot uavSlot( DescriptorSetUav::TextureSlot::makeEmpty() ); uavSlot.access = ResourceAccess::Write; - uavSlot.texture = mLightVoxel[i+1u]; + uavSlot.texture = mLightVoxel[i + 1u]; uavSlot.pixelFormat = PFG_RGBA8_UNORM; mAnisoGeneratorStep0->_setUavTexture( i, uavSlot ); } - DescriptorSetTexture2::TextureSlot texSlot( DescriptorSetTexture2:: - TextureSlot::makeEmpty() ); + DescriptorSetTexture2::TextureSlot texSlot( + DescriptorSetTexture2::TextureSlot::makeEmpty() ); texSlot.texture = mLightVoxel[0]; mAnisoGeneratorStep0->setTexture( 0, texSlot ); texSlot.texture = mVoxelizer->getNormalVox(); mAnisoGeneratorStep0->setTexture( 1, texSlot ); ShaderParams *shaderParams = &mAnisoGeneratorStep0->getShaderParams( "default" ); - //higherMipHalfWidth + // higherMipHalfWidth ShaderParams::Param *lowerMipResolutionParam = &shaderParams->mParams.back(); - //int32 resolution[4] = { static_cast( mLightVoxel[1]->getWidth() >> 1u ) }; - lowerMipResolutionParam->setManualValue( static_cast( - mLightVoxel[1]->getWidth() >> 1u ) ); + // int32 resolution[4] = { static_cast( mLightVoxel[1]->getWidth() >> 1u ) }; + lowerMipResolutionParam->setManualValue( + static_cast( mLightVoxel[1]->getWidth() >> 1u ) ); shaderParams->setDirty(); - //Now setup step 1 - //numMipsOnStep1 is subtracted one because mip 0 got processed by step 0 + // Now setup step 1 + // numMipsOnStep1 is subtracted one because mip 0 got processed by step 0 const uint8 numMipsOnStep1 = mLightVoxel[1]->getNumMipmaps() - 1u; mAnisoGeneratorStep1.resize( numMipsOnStep1 ); HlmsComputeJob *baseJob = hlmsCompute->findComputeJob( "VCT/AnisotropicMipStep1" ); - for( uint8 i=0; iclone( jobName.c_str() ); - for( uint8 axis=0; axis<3u; ++axis ) + for( uint8 axis = 0; axis < 3u; ++axis ) { - texSlot.texture = mLightVoxel[axis+1u]; + texSlot.texture = mLightVoxel[axis + 1u]; texSlot.mipmapLevel = i; texSlot.numMipmaps = 1u; mipJob->setTexture( axis, texSlot ); DescriptorSetUav::TextureSlot uavSlot( DescriptorSetUav::TextureSlot::makeEmpty() ); uavSlot.access = ResourceAccess::Write; - uavSlot.texture = mLightVoxel[axis+1u]; + uavSlot.texture = mLightVoxel[axis + 1u]; uavSlot.mipmapLevel = i + 1u; uavSlot.pixelFormat = PFG_RGBA8_UNORM; mipJob->_setUavTexture( axis, uavSlot ); } shaderParams = &mipJob->getShaderParams( "default" ); - //higherMipHalfRes_lowerMipHalfWidth + // higherMipHalfRes_lowerMipHalfWidth lowerMipResolutionParam = &shaderParams->mParams.back(); - int32 resolutions[4] = - { - static_cast( mLightVoxel[1]->getWidth() >> (i + 2u) ), - static_cast( mLightVoxel[1]->getHeight()>> (i + 1u) ), - static_cast( mLightVoxel[1]->getDepth() >> (i + 1u) ), - static_cast( mLightVoxel[1]->getWidth() >> (i + 1u) ) + int32 resolutions[4] = { // + static_cast( mLightVoxel[1]->getWidth() >> ( i + 2u ) ), + static_cast( mLightVoxel[1]->getHeight() >> ( i + 1u ) ), + static_cast( mLightVoxel[1]->getDepth() >> ( i + 1u ) ), + static_cast( mLightVoxel[1]->getWidth() >> ( i + 1u ) ) }; - for( size_t j=0; j<4u; ++j ) + for( size_t j = 0; j < 4u; ++j ) resolutions[j] = std::max( 1, resolutions[j] ); lowerMipResolutionParam->setManualValue( resolutions, 4u ); shaderParams->setDirty(); @@ -473,7 +465,7 @@ namespace Ogre restoreSwappedTextures(); TextureGpuManager *textureManager = mVoxelizer->getTextureGpuManager(); - for( size_t i=0; i::const_iterator itor = mAnisoGeneratorStep1.begin(); - FastArray::const_iterator end = mAnisoGeneratorStep1.end(); + FastArray::const_iterator itor = mAnisoGeneratorStep1.begin(); + FastArray::const_iterator end = mAnisoGeneratorStep1.end(); while( itor != end ) { - hlmsCompute->destroyComputeJob( (*itor)->getName() ); + hlmsCompute->destroyComputeJob( ( *itor )->getName() ); ++itor; } @@ -550,7 +542,6 @@ namespace Ogre texSlot.texture = mLightVoxel[0]; mLightVctBounceInject->setTexture( 2, texSlot, mSamplerblockTrilinear ); - uint8 texSlotIdx = 3u; for( size_t cascadeIdx = 0u; cascadeIdx < numExtraCascades; ++cascadeIdx ) @@ -567,7 +558,7 @@ namespace Ogre if( mAnisotropic ) { - for( uint8 i=0u; i<3u; ++i ) + for( uint8 i = 0u; i < 3u; ++i ) { texSlot.texture = mLightVoxel[i + 1u]; mLightVctBounceInject->setTexture( texSlotIdx++, texSlot, 0, false ); @@ -717,7 +708,7 @@ namespace Ogre if( i == numCascades - 1u ) { - startBias_invStartBias_cascadeMaxLod[i].z = 256.0f; // cascadeMaxLod + startBias_invStartBias_cascadeMaxLod[i].z = 256.0f; // cascadeMaxLod } else { @@ -835,11 +826,10 @@ namespace Ogre texFlags |= TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps; char tmpBuffer[128]; - LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString texName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); texName.a( "VctLightingBounce/Id", getId() ); - TextureGpu *texture = textureManager->createTexture( texName.c_str(), - GpuPageOutStrategy::Discard, - texFlags, TextureTypes::Type3D ); + TextureGpu *texture = textureManager->createTexture( + texName.c_str(), GpuPageOutStrategy::Discard, texFlags, TextureTypes::Type3D ); texture->setResolution( mLightVoxel[0]->getWidth(), mLightVoxel[0]->getHeight(), mLightVoxel[0]->getDepth() ); @@ -875,15 +865,9 @@ namespace Ogre setupGlslTextureUnits(); } //------------------------------------------------------------------------- - bool VctLighting::getAllowMultipleBounces() const - { - return mLightBounce != 0; - } + bool VctLighting::getAllowMultipleBounces() const { return mLightBounce != 0; } //------------------------------------------------------------------------- - void VctLighting::setBakingMultiplier( float bakingMult ) - { - mBakingMultiplier = bakingMult; - } + void VctLighting::setBakingMultiplier( float bakingMult ) { mBakingMultiplier = bakingMult; } //------------------------------------------------------------------------- void VctLighting::update( SceneManager *sceneManager, uint32 numBounces, float thinWallCounter, bool autoMultiplier, float rayMarchStepScale, uint32 _lightMask ) @@ -914,37 +898,37 @@ namespace Ogre float autoMultiplierValue = 0.0f; - const Vector3 voxelOrigin = mVoxelizer->getVoxelOrigin(); - const Vector3 invVoxelRes = 1.0f / mVoxelizer->getVoxelResolution(); - const Vector3 invVoxelSize = 1.0f / mVoxelizer->getVoxelSize(); + const Vector3 voxelOrigin = mVoxelizer->getVoxelOrigin(); + const Vector3 invVoxelRes = 1.0f / mVoxelizer->getVoxelResolution(); + const Vector3 invVoxelSize = 1.0f / mVoxelizer->getVoxelSize(); - ShaderVctLight * RESTRICT_ALIAS vctLight = - reinterpret_cast( - mLightsConstBuffer->map( 0, mLightsConstBuffer->getNumElements() ) ); + ShaderVctLight *RESTRICT_ALIAS vctLight = reinterpret_cast( + mLightsConstBuffer->map( 0, mLightsConstBuffer->getNumElements() ) ); uint32 numCollectedLights = 0; - const uint32 maxNumLights = static_cast( mLightsConstBuffer->getNumElements() / - sizeof(ShaderVctLight) ); + const uint32 maxNumLights = + static_cast( mLightsConstBuffer->getNumElements() / sizeof( ShaderVctLight ) ); const uint32 lightMask = _lightMask & VisibilityFlags::RESERVED_VISIBILITY_FLAGS; ObjectMemoryManager &memoryManager = sceneManager->_getLightMemoryManager(); const size_t numRenderQueues = memoryManager.getNumRenderQueues(); - for( size_t i=0; i( objData.mOwner[k] ); + Light *light = static_cast( objData.mOwner[k] ); if( light->getType() == Light::LT_DIRECTIONAL || light->getType() == Light::LT_POINT || light->getType() == Light::LT_SPOTLIGHT || @@ -976,13 +960,12 @@ namespace Ogre const Vector3 voxelCellSize( mVoxelizer->getVoxelCellSize() ); Vector3 dirCorrection( 1.0f / voxelCellSize ); - dirCorrection /= std::max( std::max( fabsf( dirCorrection.x ), - fabsf( dirCorrection.y ) ), - fabsf( dirCorrection.z ) ); + dirCorrection /= std::max( std::max( fabsf( dirCorrection.x ), fabsf( dirCorrection.y ) ), + fabsf( dirCorrection.z ) ); mNumLights->setManualValue( numCollectedLights ); - mRayMarchStepSize->setManualValue( Vector4( rayMarchStepScale / voxelRes, - autoMultiplierValue ) ); + mRayMarchStepSize->setManualValue( + Vector4( rayMarchStepScale / voxelRes, autoMultiplierValue ) ); mVoxelCellSize->setManualValue( voxelCellSize ); mDirCorrectionRatioThinWallCounter->setManualValue( Vector4( dirCorrection, thinWallCounter ) ); mInvVoxelResolution->setManualValue( invVoxelRes ); @@ -1014,7 +997,7 @@ namespace Ogre "numBounces must be 0, else call setAllowMultipleBounces first!", "VctLighting::update" ); } - for( uint32 i=0u; igetWidth(); + const uint32 width = mLightVoxel[0]->getWidth(); const uint32 height = mLightVoxel[0]->getHeight(); - const uint32 depth = mLightVoxel[0]->getDepth(); + const uint32 depth = mLightVoxel[0]->getDepth(); const float smallestRes = static_cast( std::min( std::min( width, height ), depth ) ); - const float maxMipmapCount = - static_cast( PixelFormatGpuUtils::getMaxMipmapCount( - static_cast( smallestRes ) ) ); + const float maxMipmapCount = static_cast( + PixelFormatGpuUtils::getMaxMipmapCount( static_cast( smallestRes ) ) ); - const float mipDiff = (maxMipmapCount - 8.0f) * 0.5f; + const float mipDiff = ( maxMipmapCount - 8.0f ) * 0.5f; - const float finalMultiplier = mInvBakingMultiplier * mMultiplier; - const float invFinalMultiplier = 1.0f / finalMultiplier; + const float finalMultiplier = mInvBakingMultiplier * mMultiplier; + const float invFinalMultiplier = 1.0f / finalMultiplier; const size_t numCascades = mExtraCascades.size() + 1u; @@ -1184,27 +1166,27 @@ namespace Ogre *passBufferPtr++ = 1.0f / ( cascadeNumMipmaps * cascadeNumMipmaps * cascadeNumMipmaps ); } - //float specSdfMaxMip; - //float specularSdfFactor; - //float blendFade; - //float multiplier; + // float specSdfMaxMip; + // float specularSdfFactor; + // float blendFade; + // float multiplier; *passBufferPtr++ = 7.0f + mipDiff; - //Where did 0.1875f & 0.3125f come from? Empirically obtained. - //At 128x128x128, values in range [24; 40] gave good results. - //Below 24, quality became unnacceptable. - //Past 40, performance only went down without visible changes. - //Thus 24 / 128 and 40 / 128 = 0.1875f and 0.3125f + // Where did 0.1875f & 0.3125f come from? Empirically obtained. + // At 128x128x128, values in range [24; 40] gave good results. + // Below 24, quality became unnacceptable. + // Past 40, performance only went down without visible changes. + // Thus 24 / 128 and 40 / 128 = 0.1875f and 0.3125f *passBufferPtr++ = Math::lerp( 0.1875f, 0.3125f, mSpecularSdfQuality ) * smallestRes; *passBufferPtr++ = 1.0f; *passBufferPtr++ = finalMultiplier; - //float4 ambientUpperHemi + // float4 ambientUpperHemi *passBufferPtr++ = mUpperHemisphere[0] * invFinalMultiplier; *passBufferPtr++ = mUpperHemisphere[1] * invFinalMultiplier; *passBufferPtr++ = mUpperHemisphere[2] * invFinalMultiplier; *passBufferPtr++ = 0.0f; - //float4 ambientLowerHemi + // float4 ambientLowerHemi *passBufferPtr++ = mLowerHemisphere[0] * invFinalMultiplier; *passBufferPtr++ = mLowerHemisphere[1] * invFinalMultiplier; *passBufferPtr++ = mLowerHemisphere[2] * invFinalMultiplier; @@ -1212,30 +1194,29 @@ namespace Ogre Matrix4 xform, invXForm; xform.makeTransform( -mVoxelizer->getVoxelOrigin() / mVoxelizer->getVoxelSize(), - 1.0f / mVoxelizer->getVoxelSize(), - Quaternion::IDENTITY ); - //xform = xform * viewMatrix.inverse(); + 1.0f / mVoxelizer->getVoxelSize(), Quaternion::IDENTITY ); + // xform = xform * viewMatrix.inverse(); xform = xform.concatenateAffine( viewMatrix.inverseAffine() ); invXForm = xform.inverseAffine(); - //float4 xform_row0; - //float4 xform_row1; - //float4 xform_row2; - for( size_t i=0; i<12u; ++i ) + // float4 xform_row0; + // float4 xform_row1; + // float4 xform_row2; + for( size_t i = 0; i < 12u; ++i ) *passBufferPtr++ = static_cast( xform[0][i] ); - //float4 invXform_row0; - //float4 invXform_row1; - //float4 invXform_row2; - for( size_t i=0; i<12u; ++i ) + // float4 invXform_row0; + // float4 invXform_row1; + // float4 invXform_row2; + for( size_t i = 0; i < 12u; ++i ) *passBufferPtr++ = static_cast( invXForm[0][i] ); } //------------------------------------------------------------------------- bool VctLighting::shouldEnableSpecularSdfQuality() const { return mVoxelizer->getAlbedoVox()->getWidth() > 32u && - mVoxelizer->getAlbedoVox()->getHeight() > 32u && - mVoxelizer->getAlbedoVox()->getDepth() > 32u; + mVoxelizer->getAlbedoVox()->getHeight() > 32u && + mVoxelizer->getAlbedoVox()->getDepth() > 32u; } //------------------------------------------------------------------------- void VctLighting::setDebugVisualization( bool bShow, SceneManager *sceneManager ) @@ -1255,10 +1236,9 @@ namespace Ogre SceneNode *rootNode = sceneManager->getRootSceneNode( SCENE_STATIC ); SceneNode *visNode = rootNode->createChildSceneNode( SCENE_STATIC ); - mDebugVoxelVisualizer = - OGRE_NEW VoxelVisualizer( Ogre::Id::generateNewId(), - &sceneManager->_getEntityMemoryManager( SCENE_STATIC ), - sceneManager, 0u ); + mDebugVoxelVisualizer = OGRE_NEW VoxelVisualizer( + Ogre::Id::generateNewId(), + &sceneManager->_getEntityMemoryManager( SCENE_STATIC ), sceneManager, 0u ); mDebugVoxelVisualizer->setTrackingVoxel( mLightVoxel[0], mLightVoxel[0], true ); @@ -1268,10 +1248,7 @@ namespace Ogre } } //------------------------------------------------------------------------- - bool VctLighting::getDebugVisualizationMode() const - { - return mDebugVoxelVisualizer != 0; - } + bool VctLighting::getDebugVisualizationMode() const { return mDebugVoxelVisualizer != 0; } //------------------------------------------------------------------------- void VctLighting::setAnisotropic( bool bAnisotropic ) { @@ -1282,10 +1259,10 @@ namespace Ogre } } //------------------------------------------------------------------------- - void VctLighting::setAmbient( const ColourValue& upperHemisphere, - const ColourValue& lowerHemisphere ) + void VctLighting::setAmbient( const ColourValue &upperHemisphere, + const ColourValue &lowerHemisphere ) { - for( size_t i=0; i<3u; ++i ) + for( size_t i = 0; i < 3u; ++i ) { mUpperHemisphere[i] = static_cast( upperHemisphere[i] ); mLowerHemisphere[i] = static_cast( lowerHemisphere[i] ); @@ -1312,4 +1289,4 @@ namespace Ogre mVoxelizerListenersRemoved = true; } } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Vct/OgreVctMaterial.cpp b/Components/Hlms/Pbs/src/Vct/OgreVctMaterial.cpp index c2db9571271..064e032176e 100644 --- a/Components/Hlms/Pbs/src/Vct/OgreVctMaterial.cpp +++ b/Components/Hlms/Pbs/src/Vct/OgreVctMaterial.cpp @@ -30,25 +30,21 @@ THE SOFTWARE. #include "Vct/OgreVctMaterial.h" -#include "Vao/OgreVaoManager.h" -#include "Vao/OgreConstBufferPacked.h" - +#include "Compositor/OgreCompositorManager2.h" +#include "Compositor/OgreCompositorWorkspace.h" +#include "OgreDepthBuffer.h" #include "OgreHlms.h" #include "OgreHlmsPbsDatablock.h" - -#include "OgreTextureGpuManager.h" -#include "OgreTextureBox.h" -#include "OgreSceneManager.h" - +#include "OgreLogManager.h" #include "OgreMaterialManager.h" -#include "OgreTechnique.h" #include "OgrePass.h" +#include "OgreSceneManager.h" +#include "OgreTechnique.h" +#include "OgreTextureBox.h" +#include "OgreTextureGpuManager.h" #include "OgreTextureUnitState.h" -#include "OgreDepthBuffer.h" -#include "Compositor/OgreCompositorManager2.h" -#include "Compositor/OgreCompositorWorkspace.h" - -#include "OgreLogManager.h" +#include "Vao/OgreConstBufferPacked.h" +#include "Vao/OgreVaoManager.h" namespace Ogre { @@ -79,21 +75,21 @@ namespace Ogre mDownsampleWorkspace2D( 0 ) { MaterialPtr mat; - mat = MaterialManager::getSingleton().load( - "Ogre/Copy/4xFP32_2DArray", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ).staticCast(); + mat = MaterialManager::getSingleton() + .load( "Ogre/Copy/4xFP32_2DArray", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ) + .staticCast(); mDownsampleMatPass2DArray = mat->getTechnique( 0 )->getPass( 0 ); - mat = MaterialManager::getSingleton().load( - "Ogre/Copy/4xFP32", - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ).staticCast(); + mat = MaterialManager::getSingleton() + .load( "Ogre/Copy/4xFP32", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ) + .staticCast(); mDownsampleMatPass2D = mat->getTechnique( 0 )->getPass( 0 ); } //------------------------------------------------------------------------- VctMaterial::~VctMaterial() { BucketVec::const_iterator itor = mBuckets.begin(); - BucketVec::const_iterator end = mBuckets.end(); + BucketVec::const_iterator end = mBuckets.end(); while( itor != end ) { @@ -119,12 +115,12 @@ namespace Ogre OGRE_ASSERT_MEDIUM( usedSlots < c_numDatablocksPerConstBuffer ); ShaderVctMaterial shaderMaterial; - memset( &shaderMaterial, 0, sizeof(shaderMaterial) ); + memset( &shaderMaterial, 0, sizeof( shaderMaterial ) ); { ColourValue diffuseCol = datablock->getDiffuseColour(); ColourValue emissiveCol = datablock->getEmissiveColour(); - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) { shaderMaterial.bgDiffuse[i] = 1.0f; shaderMaterial.diffuse[i] = diffuseCol[i]; @@ -136,13 +132,13 @@ namespace Ogre if( datablock->getCreator()->getType() == HLMS_PBS ) { - OGRE_ASSERT_HIGH( dynamic_cast( datablock ) ); - HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); + OGRE_ASSERT_HIGH( dynamic_cast( datablock ) ); + HlmsPbsDatablock *pbsDatablock = static_cast( datablock ); ColourValue bgDiffuse = pbsDatablock->getBackgroundDiffuse(); float transparency = pbsDatablock->getTransparency(); - for( size_t i=0; i<4; ++i ) + for( size_t i = 0; i < 4; ++i ) shaderMaterial.bgDiffuse[i] = bgDiffuse[i]; shaderMaterial.diffuse[3] = transparency; shaderMaterial.emissive[3] = 1.0f; @@ -152,8 +148,8 @@ namespace Ogre TextureGpu *emissiveTex = datablock->getEmissiveTexture(); DatablockConversionResult conversionResult; - conversionResult.slotIdx = static_cast( usedSlots ); - conversionResult.constBuffer = bucket.buffer; + conversionResult.slotIdx = static_cast( usedSlots ); + conversionResult.constBuffer = bucket.buffer; if( diffuseTex ) { conversionResult.diffuseTexIdx = getPoolSliceIdxForTexture( diffuseTex ); @@ -178,7 +174,7 @@ namespace Ogre { TextureToPoolEntryMap::const_iterator itor = mTextureToPoolEntry.find( texture ); if( itor != mTextureToPoolEntry.end() ) - return itor->second; //We already copied that texture. We're done + return itor->second; // We already copied that texture. We're done if( !mTexturePool || mNumUsedPoolSlices >= mTexturePool->getNumSlices() ) resizeTexturePool(); @@ -188,7 +184,7 @@ namespace Ogre if( texture->getInternalTextureType() == TextureTypes::Type2DArray ) { GpuProgramParametersSharedPtr psParams = - mDownsampleMatPass2DArray->getFragmentProgramParameters(); + mDownsampleMatPass2DArray->getFragmentProgramParameters(); psParams->setNamedConstant( "sliceIdx", static_cast( texture->getInternalSliceStart() ) ); mDownsampleMatPass2DArray->getTextureUnitState( 0 )->setTexture( texture ); @@ -216,15 +212,14 @@ namespace Ogre { String texName = "VctMaterial" + StringConverter::toString( getId() ) + "/" + StringConverter::toString( mNumUsedPoolSlices ); - TextureGpu *newPool = mTextureGpuManager->createTexture( texName, texName, - GpuPageOutStrategy::Discard, - TextureFlags::ManualTexture, - TextureTypes::Type2DArray ); + TextureGpu *newPool = + mTextureGpuManager->createTexture( texName, texName, GpuPageOutStrategy::Discard, + TextureFlags::ManualTexture, TextureTypes::Type2DArray ); newPool->setResolution( 64u, 64u, 64u ); newPool->setPixelFormat( PFG_RGBA8_UNORM_SRGB ); if( mTexturePool ) { - //We use quadratic growth because AMD GCN cards already round up to the next power of 2. + // We use quadratic growth because AMD GCN cards already round up to the next power of 2. newPool->setResolution( 64u, 64u, mTexturePool->getDepthOrSlices() << 1u ); } newPool->scheduleTransitionTo( GpuResidency::Resident ); @@ -239,25 +234,24 @@ namespace Ogre mTexturePool = newPool; } //------------------------------------------------------------------------- - VctMaterial::MaterialBucket* VctMaterial::findFreeBucketFor( HlmsDatablock *datablock ) + VctMaterial::MaterialBucket *VctMaterial::findFreeBucketFor( HlmsDatablock *datablock ) { const bool needsDiffuse = datablock->getDiffuseTexture() != 0; const bool needsEmissive = datablock->getEmissiveTexture() != 0; BucketVec::iterator itor = mBuckets.begin(); - BucketVec::iterator end = mBuckets.end(); + BucketVec::iterator end = mBuckets.end(); while( itor != end && - (itor->datablocks.size() >= c_numDatablocksPerConstBuffer || - itor->hasDiffuse != needsDiffuse || - itor->hasEmissive != needsEmissive) ) + ( itor->datablocks.size() >= c_numDatablocksPerConstBuffer || + itor->hasDiffuse != needsDiffuse || itor->hasEmissive != needsEmissive ) ) { ++itor; } MaterialBucket *retVal = 0; if( itor != end ) - retVal = &(*itor); + retVal = &( *itor ); return retVal; } @@ -268,20 +262,18 @@ namespace Ogre "VctMaterialDownsampleTex", "VctMaterialDownsampleTex", GpuPageOutStrategy::Discard, TextureFlags::RenderToTexture | TextureFlags::DiscardableContent, TextureTypes::Type2D ); mDownsampleTex->setResolution( 64u, 64u ); - mDownsampleTex->setPixelFormat( PFG_RGBA8_UNORM_SRGB ); - mDownsampleTex->_setDepthBufferDefaults( DepthBuffer::POOL_NO_DEPTH, false, PFG_UNKNOWN ); + mDownsampleTex->setPixelFormat( PFG_RGBA8_UNORM_SRGB ); + mDownsampleTex->_setDepthBufferDefaults( DepthBuffer::POOL_NO_DEPTH, false, PFG_UNKNOWN ); mDownsampleTex->scheduleTransitionTo( GpuResidency::Resident ); Camera *dummyCamera = sceneManager->createCamera( "VctMaterialCam" ); - mDownsampleWorkspace2DArray = - mCompositorManager->addWorkspace( - sceneManager, mDownsampleTex, dummyCamera, "VctTexDownsampleWorkspace", false, - -1, 0, 0, Vector4::ZERO, 0x00, 0x01 ); - mDownsampleWorkspace2D = - mCompositorManager->addWorkspace( - sceneManager, mDownsampleTex, dummyCamera, "VctTexDownsampleWorkspace", false, - -1, 0, 0, Vector4::ZERO, 0x00, 0x02 ); + mDownsampleWorkspace2DArray = mCompositorManager->addWorkspace( + sceneManager, mDownsampleTex, dummyCamera, "VctTexDownsampleWorkspace", false, -1, 0, 0, + Vector4::ZERO, 0x00, 0x01 ); + mDownsampleWorkspace2D = mCompositorManager->addWorkspace( + sceneManager, mDownsampleTex, dummyCamera, "VctTexDownsampleWorkspace", false, -1, 0, 0, + Vector4::ZERO, 0x00, 0x02 ); } //------------------------------------------------------------------------- void VctMaterial::destroyTempResources() @@ -306,7 +298,7 @@ namespace Ogre DatablockConversionResult retVal; DatablockConversionResultMap::const_iterator itResult = - mDatablockConversionResults.find( datablock ); + mDatablockConversionResults.find( datablock ); if( itResult != mDatablockConversionResults.end() ) retVal = itResult->second; else @@ -314,11 +306,10 @@ namespace Ogre MaterialBucket *bucket = findFreeBucketFor( datablock ); if( !bucket ) { - //Create a new bucket + // Create a new bucket MaterialBucket newBucket; - newBucket.buffer = mVaoManager->createConstBuffer( c_numDatablocksPerConstBuffer * - sizeof(ShaderVctMaterial), - BT_DEFAULT, 0, false ); + newBucket.buffer = mVaoManager->createConstBuffer( + c_numDatablocksPerConstBuffer * sizeof( ShaderVctMaterial ), BT_DEFAULT, 0, false ); newBucket.hasDiffuse = datablock->getDiffuseTexture() != 0; newBucket.hasEmissive = datablock->getEmissiveTexture() != 0; mBuckets.push_back( newBucket ); @@ -330,4 +321,4 @@ namespace Ogre return retVal; } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizer.cpp b/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizer.cpp index 57d20233206..3973a3cd9ba 100644 --- a/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizer.cpp +++ b/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizer.cpp @@ -29,41 +29,32 @@ THE SOFTWARE. #include "OgreStableHeaders.h" #include "Vct/OgreVctVoxelizer.h" + #include "Vct/OgreVctMaterial.h" #include "Vct/OgreVoxelVisualizer.h" +#include "Compute/OgreComputeTools.h" +#include "OgreHlmsCompute.h" +#include "OgreHlmsComputeJob.h" +#include "OgreItem.h" +#include "OgreLwString.h" +#include "OgreMaterial.h" +#include "OgreMaterialManager.h" +#include "OgreMesh2.h" +#include "OgrePixelFormatGpuUtils.h" +#include "OgreProfiler.h" #include "OgreRenderSystem.h" #include "OgreRoot.h" #include "OgreSceneManager.h" - -#include "OgreItem.h" -#include "OgreMesh2.h" +#include "OgreStringConverter.h" #include "OgreSubMesh2.h" - -#include "OgreMaterialManager.h" -#include "OgreMaterial.h" - -#include "Vao/OgreVertexArrayObject.h" - +#include "OgreTextureGpuManager.h" #include "Vao/OgreIndexBufferPacked.h" #include "Vao/OgreReadOnlyBufferPacked.h" +#include "Vao/OgreStagingBuffer.h" #include "Vao/OgreUavBufferPacked.h" - #include "Vao/OgreVaoManager.h" - -#include "Vao/OgreStagingBuffer.h" - -#include "Compute/OgreComputeTools.h" - -#include "OgreHlmsCompute.h" -#include "OgreHlmsComputeJob.h" -#include "OgreLwString.h" - -#include "OgreTextureGpuManager.h" -#include "OgrePixelFormatGpuUtils.h" -#include "OgreStringConverter.h" - -#include "OgreProfiler.h" +#include "Vao/OgreVertexArrayObject.h" #define TODO_deal_no_index_buffer @@ -79,16 +70,15 @@ namespace Ogre static const IdString Index32bit; static const IdString CompressedVertexFormat; - static const IdString* AllProps[c_numVctProperties]; + static const IdString *AllProps[c_numVctProperties]; }; - const IdString VctVoxelizerProp::HasDiffuseTex = IdString( "has_diffuse_tex" ); - const IdString VctVoxelizerProp::HasEmissiveTex = IdString( "has_emissive_tex" ); - const IdString VctVoxelizerProp::Index32bit = IdString( "index_32bit" ); + const IdString VctVoxelizerProp::HasDiffuseTex = IdString( "has_diffuse_tex" ); + const IdString VctVoxelizerProp::HasEmissiveTex = IdString( "has_emissive_tex" ); + const IdString VctVoxelizerProp::Index32bit = IdString( "index_32bit" ); const IdString VctVoxelizerProp::CompressedVertexFormat = IdString( "compressed_vertex_format" ); - const IdString* VctVoxelizerProp::AllProps[c_numVctProperties] = - { + const IdString *VctVoxelizerProp::AllProps[c_numVctProperties] = { &VctVoxelizerProp::Index32bit, &VctVoxelizerProp::CompressedVertexFormat, &VctVoxelizerProp::HasDiffuseTex, @@ -128,8 +118,8 @@ namespace Ogre mAutoRegion( true ), mMaxRegion( Aabb::BOX_INFINITE ) { - memset( mComputeJobs, 0, sizeof(mComputeJobs) ); - memset( mAabbCalculator, 0, sizeof(mAabbCalculator) ); + memset( mComputeJobs, 0, sizeof( mComputeJobs ) ); + memset( mAabbCalculator, 0, sizeof( mAabbCalculator ) ); createComputeJobs(); } //------------------------------------------------------------------------- @@ -185,9 +175,9 @@ namespace Ogre size_t numVariants = 1u << c_numVctProperties; char tmpBuffer[128]; - LwString jobName( LwString::FromEmptyPointer( tmpBuffer, sizeof(tmpBuffer) ) ); + LwString jobName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); - for( size_t variant=0u; variant( variant ) ); @@ -201,7 +191,8 @@ namespace Ogre ShaderParams &glslShaderParams = mComputeJobs[variant]->getShaderParams( "glsl" ); uint8 numTexUnits = 1u; - if( variant & (VoxelizerJobSetting::HasDiffuseTex|VoxelizerJobSetting::HasEmissiveTex) ) + if( variant & + ( VoxelizerJobSetting::HasDiffuseTex | VoxelizerJobSetting::HasEmissiveTex ) ) { ShaderParams::Param param; param.name = "texturePool"; @@ -213,9 +204,9 @@ namespace Ogre } mComputeJobs[variant]->setNumTexUnits( numTexUnits ); - for( size_t property=0; propertysetProperty( *VctVoxelizerProp::AllProps[property], propValue ); } @@ -228,7 +219,7 @@ namespace Ogre aabbCalc->setThreadsPerGroup( caps->getMaxThreadsPerThreadgroupAxis()[0], 1u, 1u ); numVariants = 1u << c_numAabCalcProperties; - for( size_t variant=0u; variant( variant ) ); @@ -239,9 +230,9 @@ namespace Ogre { mAabbCalculator[variant] = aabbCalc->clone( jobName.c_str() ); - for( size_t property=0; propertysetProperty( *VctVoxelizerProp::AllProps[property], propValue ); } @@ -253,11 +244,11 @@ namespace Ogre //------------------------------------------------------------------------- void VctVoxelizer::clearComputeJobResources( bool calculatorDataOnly ) { - //Do not leave dangling pointers when destroying buffers, even if we later set them - //with a new pointer (if malloc reuses an address and the jobs weren't cleared, we're screwed) + // Do not leave dangling pointers when destroying buffers, even if we later set them + // with a new pointer (if malloc reuses an address and the jobs weren't cleared, we're screwed) if( !calculatorDataOnly ) { - for( size_t i=0; iclearUavBuffers(); mComputeJobs[i]->clearTexBuffers(); @@ -267,7 +258,7 @@ namespace Ogre { const size_t numVariants = 1u << c_numAabCalcProperties; - for( size_t i=0; iclearUavBuffers(); mAabbCalculator[i]->clearTexBuffers(); @@ -286,17 +277,17 @@ namespace Ogre uint32 totalNumIndices16 = 0u; uint32 totalNumIndices32 = 0u; - for( unsigned subMeshIdx=0; subMeshIdxgetSubMesh( subMeshIdx ); VertexArrayObject *vao = subMesh->mVao[VpNormal].front(); - //Count the total number of indices and vertices + // Count the total number of indices and vertices size_t vertexStart = 0u; size_t numVertices = vao->getBaseVertexBuffer()->getNumElements(); - uint32 vbOffset = totalNumVertices + (queuedMesh.bCompressed ? mNumVerticesCompressed : - mNumVerticesUncompressed); + uint32 vbOffset = totalNumVertices + ( queuedMesh.bCompressed ? mNumVerticesCompressed + : mNumVerticesUncompressed ); uint32 ibOffset = 0; uint32 numIndices = 0; @@ -314,13 +305,13 @@ namespace Ogre ibOffset = mNumIndices16 + totalNumIndices16; totalNumIndices16 += alignToNextMultiple( numIndices, 4u ); - partSubMeshIdx = queuedMesh.bCompressed ? &mNumCompressedPartSubMeshes16 : - &mNumUncompressedPartSubMeshes16; + partSubMeshIdx = queuedMesh.bCompressed ? &mNumCompressedPartSubMeshes16 + : &mNumUncompressedPartSubMeshes16; } else { - partSubMeshIdx = queuedMesh.bCompressed ? &mNumCompressedPartSubMeshes32 : - &mNumUncompressedPartSubMeshes32; + partSubMeshIdx = queuedMesh.bCompressed ? &mNumCompressedPartSubMeshes32 + : &mNumUncompressedPartSubMeshes32; ibOffset = mNumIndices32 + totalNumIndices32; totalNumIndices32 += numIndices; } @@ -331,27 +322,29 @@ namespace Ogre { vertexStart = vao->getPrimitiveStart(); numVertices = vao->getPrimitiveCount(); - numIndices = 0; TODO_deal_no_index_buffer; + numIndices = 0; + TODO_deal_no_index_buffer; totalNumVertices += vao->getPrimitiveCount(); } TODO_deal_no_index_buffer; - //If the mesh has a lot of triangles, the voxelizer will test N triangles for every WxHxD - //voxel, which can be very inefficient. By partitioning the submeshes and calculating - //their AABBs, we can perform broadphase culling and skip a lot of triangles + // If the mesh has a lot of triangles, the voxelizer will test N triangles for every WxHxD + // voxel, which can be very inefficient. By partitioning the submeshes and calculating + // their AABBs, we can perform broadphase culling and skip a lot of triangles const uint32 numPartitions = - queuedMesh.indexCountSplit == std::numeric_limits::max() ? - 1u : static_cast( alignToNextMultiple( numIndices, - queuedMesh.indexCountSplit ) / - queuedMesh.indexCountSplit ); + queuedMesh.indexCountSplit == std::numeric_limits::max() + ? 1u + : static_cast( + alignToNextMultiple( numIndices, queuedMesh.indexCountSplit ) / + queuedMesh.indexCountSplit ); queuedMesh.submeshes[subMeshIdx].partSubMeshes.resize( numPartitions ); - for( uint32 partition=0u; partitioncreateUavBuffer( totalNumMeshes, sizeof(float) * 4u * 2u, + const size_t totalNumMeshes = mNumUncompressedPartSubMeshes16 + mNumUncompressedPartSubMeshes32 + + mNumCompressedPartSubMeshes16 + mNumCompressedPartSubMeshes32; + mMeshAabb = mVaoManager->createUavBuffer( totalNumMeshes, sizeof( float ) * 4u * 2u, BB_FLAG_READONLY, 0, false ); - PartitionedSubMesh *partitionedSubMeshGpu = - reinterpret_cast( - OGRE_MALLOC_SIMD( totalNumMeshes * sizeof(PartitionedSubMesh), - MEMCATEGORY_GEOMETRY ) ); + PartitionedSubMesh *partitionedSubMeshGpu = reinterpret_cast( + OGRE_MALLOC_SIMD( totalNumMeshes * sizeof( PartitionedSubMesh ), MEMCATEGORY_GEOMETRY ) ); FreeOnDestructor partitionedSubMeshGpuPtr( partitionedSubMeshGpu ); const size_t numVariants = 1u << c_numAabCalcProperties; size_t submeshStarts[numVariants]; - submeshStarts[0] = 0u; //16-bit uncompressed - submeshStarts[1] = submeshStarts[0] + mNumUncompressedPartSubMeshes16; //32-bit uncompressed - submeshStarts[2] = submeshStarts[1] + mNumUncompressedPartSubMeshes32; //16-bit compressed - submeshStarts[3] = submeshStarts[2] + mNumCompressedPartSubMeshes16; //32-bit compressed - - PartitionedSubMesh *partitionedSubMeshGpuPtrs[numVariants] = - { - partitionedSubMeshGpu + submeshStarts[0], - partitionedSubMeshGpu + submeshStarts[1], - partitionedSubMeshGpu + submeshStarts[2], - partitionedSubMeshGpu + submeshStarts[3] + submeshStarts[0] = 0u; // 16-bit uncompressed + submeshStarts[1] = submeshStarts[0] + mNumUncompressedPartSubMeshes16; // 32-bit uncompressed + submeshStarts[2] = submeshStarts[1] + mNumUncompressedPartSubMeshes32; // 16-bit compressed + submeshStarts[3] = submeshStarts[2] + mNumCompressedPartSubMeshes16; // 32-bit compressed + + PartitionedSubMesh *partitionedSubMeshGpuPtrs[numVariants] = { + partitionedSubMeshGpu + submeshStarts[0], partitionedSubMeshGpu + submeshStarts[1], + partitionedSubMeshGpu + submeshStarts[2], partitionedSubMeshGpu + submeshStarts[3] }; MeshPtrMap::iterator itor = mMeshesV2.begin(); - MeshPtrMap::iterator end = mMeshesV2.end(); + MeshPtrMap::iterator end = mMeshesV2.end(); while( itor != end ) { const Mesh *mesh = itor->first.get(); QueuedMesh &queuedMesh = itor->second; const size_t numSubMeshes = queuedMesh.submeshes.size(); - for( size_t i=0u; igetSubMesh( (uint16)(i) )->mVao[VpNormal].front(); + VertexArrayObject *vao = mesh->getSubMesh( ( uint16 )( i ) )->mVao[VpNormal].front(); IndexBufferPacked *indexBuffer = vao->getIndexBuffer(); const bool is16bit = indexBuffer->getIndexType() == IndexBufferPacked::IT_16BIT; FastArray::iterator itPartSub = - queuedMesh.submeshes[i].partSubMeshes.begin(); + queuedMesh.submeshes[i].partSubMeshes.begin(); FastArray::iterator enPartSub = - queuedMesh.submeshes[i].partSubMeshes.end(); + queuedMesh.submeshes[i].partSubMeshes.end(); while( itPartSub != enPartSub ) { @@ -447,44 +433,41 @@ namespace Ogre partitionedSubMeshGpuPtrs[variantIdx]->vbOffset = itPartSub->vbOffset; partitionedSubMeshGpuPtrs[variantIdx]->ibOffset = itPartSub->ibOffset; partitionedSubMeshGpuPtrs[variantIdx]->numIndices = itPartSub->numIndices; - //VCT/AabbWorldSpace compute shader needs to read aabbSubMeshIdx from - //InstanceBuffer::meshData.w & ~0x80000000u; not from inMeshAabb which is - //what we're filling right now. So set it to 0 to avoid confussion + // VCT/AabbWorldSpace compute shader needs to read aabbSubMeshIdx from + // InstanceBuffer::meshData.w & ~0x80000000u; not from inMeshAabb which is + // what we're filling right now. So set it to 0 to avoid confussion partitionedSubMeshGpuPtrs[variantIdx]->aabbSubMeshIdx = 0; -// const bool needsAabbCalc = numSubMeshes != 1u || -// queuedMesh.submeshes[i].partSubMeshes.size() != 1u; -// if( needsAabbCalc ) -// partitionedSubMeshGpu->numIndices |= 0x80000000; + // const bool needsAabbCalc = numSubMeshes != 1u || + // queuedMesh.submeshes[i].partSubMeshes.size() + // != 1u; + // if( needsAabbCalc ) + // partitionedSubMeshGpu->numIndices |= 0x80000000; ++itPartSub; ++partitionedSubMeshGpuPtrs[variantIdx]; } - } ++itor; } - OGRE_ASSERT_LOW( (size_t)(partitionedSubMeshGpuPtrs[0] - - partitionedSubMeshGpu) == mNumUncompressedPartSubMeshes16 ); - OGRE_ASSERT_LOW( (size_t)(partitionedSubMeshGpuPtrs[1] - - partitionedSubMeshGpuPtrs[0]) == mNumUncompressedPartSubMeshes32 ); - OGRE_ASSERT_LOW( (size_t)(partitionedSubMeshGpuPtrs[2] - - partitionedSubMeshGpuPtrs[1]) == mNumCompressedPartSubMeshes16 ); - OGRE_ASSERT_LOW( (size_t)(partitionedSubMeshGpuPtrs[3] - - partitionedSubMeshGpuPtrs[2] ) == mNumCompressedPartSubMeshes32 ); - - mGpuPartitionedSubMeshes = mVaoManager->createTexBuffer( PFG_RGBA32_UINT, - totalNumMeshes * - sizeof(PartitionedSubMesh), - BT_DEFAULT, - partitionedSubMeshGpuPtr.ptr, - false ); + OGRE_ASSERT_LOW( ( size_t )( partitionedSubMeshGpuPtrs[0] - partitionedSubMeshGpu ) == + mNumUncompressedPartSubMeshes16 ); + OGRE_ASSERT_LOW( ( size_t )( partitionedSubMeshGpuPtrs[1] - partitionedSubMeshGpuPtrs[0] ) == + mNumUncompressedPartSubMeshes32 ); + OGRE_ASSERT_LOW( ( size_t )( partitionedSubMeshGpuPtrs[2] - partitionedSubMeshGpuPtrs[1] ) == + mNumCompressedPartSubMeshes16 ); + OGRE_ASSERT_LOW( ( size_t )( partitionedSubMeshGpuPtrs[3] - partitionedSubMeshGpuPtrs[2] ) == + mNumCompressedPartSubMeshes32 ); + + mGpuPartitionedSubMeshes = + mVaoManager->createTexBuffer( PFG_RGBA32_UINT, totalNumMeshes * sizeof( PartitionedSubMesh ), + BT_DEFAULT, partitionedSubMeshGpuPtr.ptr, false ); } //------------------------------------------------------------------------- void VctVoxelizer::destroyAabbCalculatorMeshData() { - //if( mGpuMeshDataDirty ) + // if( mGpuMeshDataDirty ) if( mGpuPartitionedSubMeshes ) { mVaoManager->destroyTexBuffer( mGpuPartitionedSubMeshes ); @@ -506,7 +489,7 @@ namespace Ogre const unsigned numSubmeshes = mesh->getNumSubMeshes(); - for( unsigned subMeshIdx=0; subMeshIdxgetSubMesh( subMeshIdx ); VertexArrayObject *vao = subMesh->mVao[VpNormal].front(); @@ -521,17 +504,14 @@ namespace Ogre { uint32 indexStart = vao->getPrimitiveStart(); uint32 numIndices = vao->getPrimitiveCount(); - indexBuffer->copyTo( mIndexBuffer16, - mappedBuffers.index16BufferOffset >> 1u, + indexBuffer->copyTo( mIndexBuffer16, mappedBuffers.index16BufferOffset >> 1u, indexStart, numIndices ); mappedBuffers.index16BufferOffset += alignToNextMultiple( numIndices, 4u ); } else { - indexBuffer->copyTo( mIndexBuffer32, - mappedBuffers.index32BufferOffset, - vao->getPrimitiveStart(), - vao->getPrimitiveCount() ); + indexBuffer->copyTo( mIndexBuffer32, mappedBuffers.index32BufferOffset, + vao->getPrimitiveStart(), vao->getPrimitiveCount() ); mappedBuffers.index32BufferOffset += vao->getPrimitiveCount(); } } @@ -541,7 +521,7 @@ namespace Ogre numVertices = vao->getPrimitiveCount(); } - float * RESTRICT_ALIAS uncVertexBuffer = mappedBuffers.uncompressedVertexBuffer; + float *RESTRICT_ALIAS uncVertexBuffer = mappedBuffers.uncompressedVertexBuffer; #ifdef STREAM_DOWNLOAD VertexBufferDownloadHelper &downloadHelper = queuedMesh.submeshes[subMeshIdx].downloadHelper; @@ -559,24 +539,23 @@ namespace Ogre } #endif const VertexBufferDownloadHelper::DownloadData *downloadData = - downloadHelper.getDownloadData().begin(); + downloadHelper.getDownloadData().begin(); VertexElement2 dummy( VET_FLOAT1, VES_TEXTURE_COORDINATES ); - VertexElement2 origElements[3] = - { + VertexElement2 origElements[3] = { downloadData[0].origElements ? *downloadData[0].origElements : dummy, downloadData[1].origElements ? *downloadData[1].origElements : dummy, downloadData[2].origElements ? *downloadData[2].origElements : dummy, }; - //Map the buffers we started downloading in countBuffersSize - uint8 const * srcData[3]; + // Map the buffers we started downloading in countBuffersSize + uint8 const *srcData[3]; downloadHelper.map( srcData ); - for( size_t vertexIdx=0; vertexIdx( pos.x ); @@ -627,9 +607,9 @@ namespace Ogre if( !bCompressed ) { const bool isNewEntry = itor == mMeshesV2.end(); - //Force no compression, even if the entry was already there + // Force no compression, even if the entry was already there QueuedMesh &queuedMesh = mMeshesV2[mesh]; - //const bool wasCompressed = queuedMesh.bCompressed; + // const bool wasCompressed = queuedMesh.bCompressed; queuedMesh.bCompressed = false; if( isNewEntry ) @@ -643,7 +623,7 @@ namespace Ogre } else { - //We can only request with compression if the entry wasn't already there + // We can only request with compression if the entry wasn't already there if( itor == mMeshesV2.end() ) { QueuedMesh queuedMesh; @@ -693,27 +673,26 @@ namespace Ogre void VctVoxelizer::freeBuffers( bool bForceFree ) { if( mIndexBuffer16 && - (bForceFree || mIndexBuffer16->getNumElements() != (mNumIndices16 + 1u) >> 1u) ) + ( bForceFree || mIndexBuffer16->getNumElements() != ( mNumIndices16 + 1u ) >> 1u ) ) { mVaoManager->destroyUavBuffer( mIndexBuffer16 ); mIndexBuffer16 = 0; } - if( mIndexBuffer32 && - (bForceFree || mIndexBuffer32->getNumElements() != mNumIndices32) ) + if( mIndexBuffer32 && ( bForceFree || mIndexBuffer32->getNumElements() != mNumIndices32 ) ) { mVaoManager->destroyUavBuffer( mIndexBuffer32 ); mIndexBuffer32 = 0; } if( mVertexBufferCompressed && - (bForceFree || mVertexBufferCompressed->getNumElements() != mNumVerticesCompressed) ) + ( bForceFree || mVertexBufferCompressed->getNumElements() != mNumVerticesCompressed ) ) { mVaoManager->destroyUavBuffer( mVertexBufferCompressed ); mVertexBufferCompressed = 0; } if( mVertexBufferUncompressed && - (bForceFree || mVertexBufferUncompressed->getNumElements() != mNumVerticesUncompressed) ) + ( bForceFree || mVertexBufferUncompressed->getNumElements() != mNumVerticesUncompressed ) ) { mVaoManager->destroyUavBuffer( mVertexBufferUncompressed ); mVertexBufferUncompressed = 0; @@ -729,20 +708,20 @@ namespace Ogre { OgreProfile( "VctVoxelizer::buildMeshBuffers" ); - mNumVerticesCompressed = 0; - mNumVerticesUncompressed = 0; + mNumVerticesCompressed = 0; + mNumVerticesUncompressed = 0; mNumIndices16 = 0; mNumIndices32 = 0; mNumUncompressedPartSubMeshes16 = 0; mNumUncompressedPartSubMeshes32 = 0; - mNumCompressedPartSubMeshes16 = 0; - mNumCompressedPartSubMeshes32 = 0; + mNumCompressedPartSubMeshes16 = 0; + mNumCompressedPartSubMeshes32 = 0; { OgreProfile( "VctVoxelizer::countBuffersSize aggregated" ); MeshPtrMap::iterator itor = mMeshesV2.begin(); - MeshPtrMap::iterator end = mMeshesV2.end(); + MeshPtrMap::iterator end = mMeshesV2.end(); while( itor != end ) { @@ -755,21 +734,21 @@ namespace Ogre if( mNumIndices16 && !mIndexBuffer16 ) { - //D3D11 does not support 2-byte strides, so we create 4-byte buffers - //and halve the number of indices (rounding up) - mIndexBuffer16 = mVaoManager->createUavBuffer( (mNumIndices16 + 1u) >> 1u, - sizeof(uint32), 0, 0, false ); + // D3D11 does not support 2-byte strides, so we create 4-byte buffers + // and halve the number of indices (rounding up) + mIndexBuffer16 = mVaoManager->createUavBuffer( ( mNumIndices16 + 1u ) >> 1u, + sizeof( uint32 ), 0, 0, false ); } if( mNumIndices32 && !mIndexBuffer32 ) - mIndexBuffer32 = mVaoManager->createUavBuffer( mNumIndices32, sizeof(uint32), 0, 0, false ); + mIndexBuffer32 = + mVaoManager->createUavBuffer( mNumIndices32, sizeof( uint32 ), 0, 0, false ); StagingBuffer *vbUncomprStagingBuffer = - mVaoManager->getStagingBuffer( mNumVerticesUncompressed * sizeof(float) * 8u, true ); + mVaoManager->getStagingBuffer( mNumVerticesUncompressed * sizeof( float ) * 8u, true ); MappedBuffers mappedBuffers; - mappedBuffers.uncompressedVertexBuffer = - reinterpret_cast( vbUncomprStagingBuffer->map( mNumVerticesUncompressed * - sizeof(float) * 8u ) ); + mappedBuffers.uncompressedVertexBuffer = reinterpret_cast( + vbUncomprStagingBuffer->map( mNumVerticesUncompressed * sizeof( float ) * 8u ) ); mappedBuffers.index16BufferOffset = 0u; mappedBuffers.index32BufferOffset = 0u; @@ -780,7 +759,7 @@ namespace Ogre { OgreProfile( "VctVoxelizer::convertMeshUncompressed aggregated" ); MeshPtrMap::iterator itor = mMeshesV2.begin(); - MeshPtrMap::iterator end = mMeshesV2.end(); + MeshPtrMap::iterator end = mMeshesV2.end(); while( itor != end ) { @@ -789,19 +768,17 @@ namespace Ogre } } - OGRE_ASSERT_LOW( (size_t)(mappedBuffers.uncompressedVertexBuffer - - uncompressedVertexBufferStart) <= - mNumVerticesUncompressed * sizeof(float) * 8u ); + OGRE_ASSERT_LOW( + ( size_t )( mappedBuffers.uncompressedVertexBuffer - uncompressedVertexBufferStart ) <= + mNumVerticesUncompressed * sizeof( float ) * 8u ); if( mNumVerticesUncompressed && !mVertexBufferUncompressed ) { - mVertexBufferUncompressed = mVaoManager->createUavBuffer( mNumVerticesUncompressed, - sizeof(float) * 8u, - 0, 0, false ); + mVertexBufferUncompressed = mVaoManager->createUavBuffer( + mNumVerticesUncompressed, sizeof( float ) * 8u, 0, 0, false ); } vbUncomprStagingBuffer->unmap( StagingBuffer::Destination( - mVertexBufferUncompressed, 0u, 0u, - mVertexBufferUncompressed->getTotalSizeBytes() ) ); + mVertexBufferUncompressed, 0u, 0u, mVertexBufferUncompressed->getTotalSizeBytes() ) ); vbUncomprStagingBuffer->removeReferenceCount(); @@ -810,9 +787,7 @@ namespace Ogre //------------------------------------------------------------------------- void VctVoxelizer::createVoxelTextures() { - if( mAlbedoVox && - mAlbedoVox->getWidth() == mWidth && - mAlbedoVox->getHeight() == mHeight && + if( mAlbedoVox && mAlbedoVox->getWidth() == mWidth && mAlbedoVox->getHeight() == mHeight && mAlbedoVox->getDepth() == mDepth ) { mAccumValVox->scheduleTransitionTo( GpuResidency::Resident ); @@ -830,38 +805,29 @@ namespace Ogre if( mNeedsAlbedoMipmaps || mNeedsAllMipmaps ) texFlags |= TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps; - mAlbedoVox = mTextureGpuManager->createTexture( "VctVoxelizer" + - StringConverter::toString( getId() ) + - "/Albedo", - GpuPageOutStrategy::Discard, - texFlags, TextureTypes::Type3D ); + mAlbedoVox = mTextureGpuManager->createTexture( + "VctVoxelizer" + StringConverter::toString( getId() ) + "/Albedo", + GpuPageOutStrategy::Discard, texFlags, TextureTypes::Type3D ); if( !mNeedsAllMipmaps ) texFlags &= ~uint32( TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps ); - mEmissiveVox = mTextureGpuManager->createTexture( "VctVoxelizer" + - StringConverter::toString( getId() ) + - "/Emissive", - GpuPageOutStrategy::Discard, - texFlags, TextureTypes::Type3D ); - mNormalVox = mTextureGpuManager->createTexture( "VctVoxelizer" + - StringConverter::toString( getId() ) + - "/Normal", - GpuPageOutStrategy::Discard, - texFlags, TextureTypes::Type3D ); + mEmissiveVox = mTextureGpuManager->createTexture( + "VctVoxelizer" + StringConverter::toString( getId() ) + "/Emissive", + GpuPageOutStrategy::Discard, texFlags, TextureTypes::Type3D ); + mNormalVox = mTextureGpuManager->createTexture( + "VctVoxelizer" + StringConverter::toString( getId() ) + "/Normal", + GpuPageOutStrategy::Discard, texFlags, TextureTypes::Type3D ); texFlags &= ~uint32( TextureFlags::RenderToTexture | TextureFlags::AllowAutomipmaps ); - mAccumValVox = mTextureGpuManager->createTexture( "VctVoxelizer" + - StringConverter::toString( getId() ) + - "/AccumVal", - GpuPageOutStrategy::Discard, - TextureFlags::NotTexture|texFlags, - TextureTypes::Type3D ); + mAccumValVox = mTextureGpuManager->createTexture( + "VctVoxelizer" + StringConverter::toString( getId() ) + "/AccumVal", + GpuPageOutStrategy::Discard, TextureFlags::NotTexture | texFlags, TextureTypes::Type3D ); } TextureGpu *textures[4] = { mAlbedoVox, mEmissiveVox, mNormalVox, mAccumValVox }; - for( size_t i=0; ischeduleTransitionTo( GpuResidency::OnStorage ); mAlbedoVox->setPixelFormat( PFG_RGBA8_UNORM ); @@ -874,7 +840,7 @@ namespace Ogre const uint8 numMipmaps = PixelFormatGpuUtils::getMaxMipmapCount( mWidth, mHeight, mDepth ); - for( size_t i=0; isetResolution( mWidth, mHeight, mDepth ); @@ -910,7 +876,7 @@ namespace Ogre mRegionToVoxelize = Aabb::BOX_NULL; ItemArray::const_iterator itor = mItems.begin(); - ItemArray::const_iterator end = mItems.end(); + ItemArray::const_iterator end = mItems.end(); while( itor != end ) { @@ -935,7 +901,7 @@ namespace Ogre mBuckets.clear(); ItemArray::const_iterator itor = mItems.begin(); - ItemArray::const_iterator end = mItems.end(); + ItemArray::const_iterator end = mItems.end(); while( itor != end ) { @@ -943,7 +909,7 @@ namespace Ogre MeshPtrMap::const_iterator itMesh = mMeshesV2.find( item->getMesh() ); const size_t numSubItems = item->getNumSubItems(); - for( size_t i=0; igetDatablock(); VctMaterial::DatablockConversionResult convResult = - mVctMaterial->addDatablock( datablock ); + mVctMaterial->addDatablock( datablock ); if( convResult.hasDiffuseTex() ) variant |= VoxelizerJobSetting::HasDiffuseTex; if( convResult.hasEmissiveTex() ) variant |= VoxelizerJobSetting::HasEmissiveTex; - bucket.job = mComputeJobs[variant]; - bucket.materialBuffer = convResult.constBuffer; - bucket.needsTexPool = convResult.hasDiffuseTex() || convResult.hasEmissiveTex(); - bucket.vertexBuffer = itMesh->second.bCompressed ? mVertexBufferCompressed : - mVertexBufferUncompressed; - bucket.indexBuffer = (variant & VoxelizerJobSetting::Index32bit) ? mIndexBuffer32 : - mIndexBuffer16; + bucket.job = mComputeJobs[variant]; + bucket.materialBuffer = convResult.constBuffer; + bucket.needsTexPool = convResult.hasDiffuseTex() || convResult.hasEmissiveTex(); + bucket.vertexBuffer = + itMesh->second.bCompressed ? mVertexBufferCompressed : mVertexBufferUncompressed; + bucket.indexBuffer = + ( variant & VoxelizerJobSetting::Index32bit ) ? mIndexBuffer32 : mIndexBuffer16; QueuedInstance queuedInstance; - queuedInstance.movableObject = item; - queuedInstance.materialIdx = convResult.slotIdx; + queuedInstance.movableObject = item; + queuedInstance.materialIdx = convResult.slotIdx; const size_t numPartitions = itMesh->second.submeshes[i].partSubMeshes.size(); - for( size_t j=0u; jsecond.submeshes[i].partSubMeshes[j]; - queuedInstance.vertexBufferStart = partSubMesh.vbOffset; - queuedInstance.indexBufferStart = partSubMesh.ibOffset; - queuedInstance.numIndices = partSubMesh.numIndices; - queuedInstance.aabbSubMeshIdx = partSubMesh.aabbSubMeshIdx; - queuedInstance.needsAabbUpdate = numPartitions != 1u || numSubItems != 1u; + queuedInstance.vertexBufferStart = partSubMesh.vbOffset; + queuedInstance.indexBufferStart = partSubMesh.ibOffset; + queuedInstance.numIndices = partSubMesh.numIndices; + queuedInstance.aabbSubMeshIdx = partSubMesh.aabbSubMeshIdx; + queuedInstance.needsAabbUpdate = numPartitions != 1u || numSubItems != 1u; mBuckets[bucket].queuedInst.push_back( queuedInstance ); } } @@ -1008,7 +974,7 @@ namespace Ogre OGRE_ASSERT_MEDIUM( itMesh != mMeshesV2.end() ); QueuedSubMeshArray::const_iterator itor = itMesh->second.submeshes.begin(); - QueuedSubMeshArray::const_iterator end = itMesh->second.submeshes.end(); + QueuedSubMeshArray::const_iterator end = itMesh->second.submeshes.end(); while( itor != end ) { @@ -1023,7 +989,7 @@ namespace Ogre { size_t instanceCount = 0; ItemArray::const_iterator itor = mItems.begin(); - ItemArray::const_iterator end = mItems.end(); + ItemArray::const_iterator end = mItems.end(); while( itor != end ) { @@ -1031,7 +997,7 @@ namespace Ogre ++itor; } - const size_t structStride = sizeof(float) * 4u * 6u; + const size_t structStride = sizeof( float ) * 4u * 6u; const size_t elementCount = alignToNextMultiple( instanceCount * mOctants.size(), mAabbWorldSpaceJob->getThreadsPerGroupX() ); @@ -1039,9 +1005,9 @@ namespace Ogre { destroyInstanceBuffers(); mInstanceBuffer = mVaoManager->createUavBuffer( elementCount, structStride, - BB_FLAG_UAV|BB_FLAG_READONLY, 0, false ); - mCpuInstanceBuffer = reinterpret_cast( OGRE_MALLOC_SIMD( elementCount * structStride, - MEMCATEGORY_GENERAL ) ); + BB_FLAG_UAV | BB_FLAG_READONLY, 0, false ); + mCpuInstanceBuffer = reinterpret_cast( + OGRE_MALLOC_SIMD( elementCount * structStride, MEMCATEGORY_GENERAL ) ); mInstanceBufferAsTex = mInstanceBuffer->getAsReadOnlyBufferView(); } } @@ -1067,13 +1033,14 @@ namespace Ogre createInstanceBuffers(); -// float * RESTRICT_ALIAS instanceBuffer = -// reinterpret_cast( mInstanceBuffer->map( 0, mInstanceBuffer->getNumElements() ) ); - float * RESTRICT_ALIAS instanceBuffer = reinterpret_cast( mCpuInstanceBuffer ); + // float * RESTRICT_ALIAS instanceBuffer = + // reinterpret_cast( mInstanceBuffer->map( 0, + // mInstanceBuffer->getNumElements() ) ); + float *RESTRICT_ALIAS instanceBuffer = reinterpret_cast( mCpuInstanceBuffer ); const float *instanceBufferStart = instanceBuffer; const FastArray::const_iterator begin = mOctants.begin(); FastArray::const_iterator itor = begin; - FastArray::const_iterator end = mOctants.end(); + FastArray::const_iterator end = mOctants.end(); while( itor != end ) { @@ -1085,21 +1052,21 @@ namespace Ogre { uint32 numInstancesAfterCulling = 0u; FastArray::const_iterator itQueuedInst = - itBucket->second.queuedInst.begin(); + itBucket->second.queuedInst.begin(); FastArray::const_iterator enQueuedInst = - itBucket->second.queuedInst.end(); + itBucket->second.queuedInst.end(); while( itQueuedInst != enQueuedInst ) { const QueuedInstance &instance = *itQueuedInst; Aabb worldAabb = instance.movableObject->getWorldAabb(); - //Perform culling against this octant. + // Perform culling against this octant. if( octantAabb.intersects( worldAabb ) ) { const Matrix4 &fullTransform = - instance.movableObject->_getParentNodeFullTransform(); - for( size_t i=0; i<12u; ++i ) + instance.movableObject->_getParentNodeFullTransform(); + for( size_t i = 0; i < 12u; ++i ) *instanceBuffer++ = static_cast( fullTransform[0][i] ); *instanceBuffer++ = worldAabb.mCenter.x; @@ -1107,23 +1074,28 @@ namespace Ogre *instanceBuffer++ = worldAabb.mCenter.z; *instanceBuffer++ = 0.0f; - #define AS_U32PTR( x ) reinterpret_cast(x) +#define AS_U32PTR( x ) reinterpret_cast( x ) *instanceBuffer++ = worldAabb.mHalfSize.x; *instanceBuffer++ = worldAabb.mHalfSize.y; *instanceBuffer++ = worldAabb.mHalfSize.z; - *AS_U32PTR( instanceBuffer ) = instance.materialIdx; ++instanceBuffer; + *AS_U32PTR( instanceBuffer ) = instance.materialIdx; + ++instanceBuffer; uint32 aabbSubMeshIdx = instance.aabbSubMeshIdx; if( instance.needsAabbUpdate ) aabbSubMeshIdx |= 0x80000000; - *AS_U32PTR( instanceBuffer ) = instance.vertexBufferStart; ++instanceBuffer; - *AS_U32PTR( instanceBuffer ) = instance.indexBufferStart; ++instanceBuffer; - *AS_U32PTR( instanceBuffer ) = instance.numIndices; ++instanceBuffer; - *AS_U32PTR( instanceBuffer ) = aabbSubMeshIdx; ++instanceBuffer; + *AS_U32PTR( instanceBuffer ) = instance.vertexBufferStart; + ++instanceBuffer; + *AS_U32PTR( instanceBuffer ) = instance.indexBufferStart; + ++instanceBuffer; + *AS_U32PTR( instanceBuffer ) = instance.numIndices; + ++instanceBuffer; + *AS_U32PTR( instanceBuffer ) = aabbSubMeshIdx; + ++instanceBuffer; - #undef AS_U32PTR +#undef AS_U32PTR ++numInstancesAfterCulling; } @@ -1143,16 +1115,17 @@ namespace Ogre ++itor; } - OGRE_ASSERT_LOW( (size_t)(instanceBuffer - instanceBufferStart) * sizeof(float) <= + OGRE_ASSERT_LOW( ( size_t )( instanceBuffer - instanceBufferStart ) * sizeof( float ) <= mInstanceBuffer->getTotalSizeBytes() ); - mTotalNumInstances = static_cast( (instanceBuffer - instanceBufferStart) / - (4u * (3u + 3u)) ); + mTotalNumInstances = + static_cast( ( instanceBuffer - instanceBufferStart ) / ( 4u * ( 3u + 3u ) ) ); - //Fill the remaining bytes with 0 so that mAabbWorldSpaceJob ignores those - memset( instanceBuffer, 0, mInstanceBuffer->getTotalSizeBytes() - - (static_cast(instanceBuffer - instanceBufferStart) * sizeof(float)) ); -// mInstanceBuffer->unmap( UO_UNMAP_ALL ); + // Fill the remaining bytes with 0 so that mAabbWorldSpaceJob ignores those + memset( instanceBuffer, 0, + mInstanceBuffer->getTotalSizeBytes() - + ( static_cast( instanceBuffer - instanceBufferStart ) * sizeof( float ) ) ); + // mInstanceBuffer->unmap( UO_UNMAP_ALL ); mInstanceBuffer->upload( mCpuInstanceBuffer, 0u, mInstanceBuffer->getNumElements() ); } //------------------------------------------------------------------------- @@ -1163,30 +1136,27 @@ namespace Ogre const size_t numVariants = 1u << c_numAabCalcProperties; - OGRE_STATIC_ASSERT( sizeof(mAabbCalculator) / sizeof(mAabbCalculator[0]) == numVariants ); + OGRE_STATIC_ASSERT( sizeof( mAabbCalculator ) / sizeof( mAabbCalculator[0] ) == numVariants ); - const uint32 numMeshes[numVariants] = - { - mNumUncompressedPartSubMeshes16, - mNumUncompressedPartSubMeshes32, - mNumCompressedPartSubMeshes16, - mNumCompressedPartSubMeshes32 - }; + const uint32 numMeshes[numVariants] = { mNumUncompressedPartSubMeshes16, + mNumUncompressedPartSubMeshes32, + mNumCompressedPartSubMeshes16, + mNumCompressedPartSubMeshes32 }; ShaderParams::Param paramMeshRange; - paramMeshRange.name = "meshStart_meshEnd"; + paramMeshRange.name = "meshStart_meshEnd"; uint32 meshStart = 0u; OgreProfileGpuBegin( "VCT Mesh AABB calculation" ); - for( size_t i=0; i_setUavBuffer( 2, bufferSlot ); - DescriptorSetTexture2::BufferSlot texBufSlot(DescriptorSetTexture2::BufferSlot::makeEmpty()); + DescriptorSetTexture2::BufferSlot texBufSlot( + DescriptorSetTexture2::BufferSlot::makeEmpty() ); texBufSlot.buffer = mGpuPartitionedSubMeshes; mAabbCalculator[i]->setTexBuffer( 0, texBufSlot ); @@ -1225,13 +1196,13 @@ namespace Ogre bufferSlot.access = ResourceAccess::ReadWrite; mAabbWorldSpaceJob->_setUavBuffer( 0, bufferSlot ); - DescriptorSetTexture2::BufferSlot texBufSlot(DescriptorSetTexture2::BufferSlot::makeEmpty()); + DescriptorSetTexture2::BufferSlot texBufSlot( DescriptorSetTexture2::BufferSlot::makeEmpty() ); texBufSlot.buffer = mMeshAabb->getAsReadOnlyBufferView(); mAabbWorldSpaceJob->setTexBuffer( 0, texBufSlot ); const uint32 threadsPerGroupX = mAabbWorldSpaceJob->getThreadsPerGroupX(); - mAabbWorldSpaceJob->setNumThreadGroups( (mTotalNumInstances + threadsPerGroupX - 1u) / - threadsPerGroupX, 1u, 1u ); + mAabbWorldSpaceJob->setNumThreadGroups( + ( mTotalNumInstances + threadsPerGroupX - 1u ) / threadsPerGroupX, 1u, 1u ); OgreProfileGpuBegin( "VCT AABB local to world space conversion" ); mAabbWorldSpaceJob->analyzeBarriers( mResourceTransitions ); @@ -1250,15 +1221,15 @@ namespace Ogre OGRE_ASSERT_LOW( mDepth % numOctantsZ == 0 ); Octant octant; - octant.width = mWidth / numOctantsX; - octant.height = mHeight / numOctantsY; - octant.depth = mDepth / numOctantsZ; + octant.width = mWidth / numOctantsX; + octant.height = mHeight / numOctantsY; + octant.depth = mDepth / numOctantsZ; const Vector3 voxelOrigin = mRegionToVoxelize.getMinimum(); - const Vector3 voxelCellSize = mRegionToVoxelize.getSize() / - Vector3( numOctantsX, numOctantsY, numOctantsZ ); + const Vector3 voxelCellSize = + mRegionToVoxelize.getSize() / Vector3( numOctantsX, numOctantsY, numOctantsZ ); - for( uint32 x=0u; xgetCapabilities()->hasCapability( RSC_TYPED_UAV_LOADS ); - for( size_t i=0; igetPixelFormat(); else @@ -1365,7 +1336,7 @@ namespace Ogre uavSlot.access = ResourceAccess::ReadWrite; mComputeJobs[i]->_setUavTexture( 2, uavSlot ); - uavSlot.texture = mNormalVox; + uavSlot.texture = mNormalVox; if( hasTypedUavs ) uavSlot.pixelFormat = mNormalVox->getPixelFormat(); else @@ -1373,7 +1344,7 @@ namespace Ogre uavSlot.access = ResourceAccess::ReadWrite; mComputeJobs[i]->_setUavTexture( 3, uavSlot ); - uavSlot.texture = mEmissiveVox; + uavSlot.texture = mEmissiveVox; if( hasTypedUavs ) uavSlot.pixelFormat = mEmissiveVox->getPixelFormat(); else @@ -1381,12 +1352,13 @@ namespace Ogre uavSlot.access = ResourceAccess::ReadWrite; mComputeJobs[i]->_setUavTexture( 4, uavSlot ); - uavSlot.texture = mAccumValVox; + uavSlot.texture = mAccumValVox; uavSlot.pixelFormat = mAccumValVox->getPixelFormat(); uavSlot.access = ResourceAccess::ReadWrite; mComputeJobs[i]->_setUavTexture( 5, uavSlot ); - DescriptorSetTexture2::BufferSlot texBufSlot(DescriptorSetTexture2::BufferSlot::makeEmpty()); + DescriptorSetTexture2::BufferSlot texBufSlot( + DescriptorSetTexture2::BufferSlot::makeEmpty() ); texBufSlot.buffer = mInstanceBufferAsTex; mComputeJobs[i]->setTexBuffer( 0, texBufSlot ); } @@ -1401,10 +1373,10 @@ namespace Ogre ShaderParams::Param paramVoxelCellSize; ShaderParams::Param paramVoxelPixelOrigin; - paramInstanceRange.name = "instanceStart_instanceEnd"; - paramVoxelOrigin.name = "voxelOrigin"; - paramVoxelCellSize.name = "voxelCellSize"; - paramVoxelPixelOrigin.name="voxelPixelOrigin"; + paramInstanceRange.name = "instanceStart_instanceEnd"; + paramVoxelOrigin.name = "voxelOrigin"; + paramVoxelCellSize.name = "voxelCellSize"; + paramVoxelPixelOrigin.name = "voxelPixelOrigin"; paramVoxelCellSize.setManualValue( getVoxelCellSize() ); @@ -1414,7 +1386,7 @@ namespace Ogre const FastArray::const_iterator begin = mOctants.begin(); FastArray::const_iterator itor = begin; - FastArray::const_iterator end = mOctants.end(); + FastArray::const_iterator end = mOctants.end(); while( itor != end ) { @@ -1482,7 +1454,7 @@ namespace Ogre OgreProfileGpuEnd( "VCT Voxelization Jobs" ); - //This texture is no longer needed, it's not used for the injection phase. Save memory. + // This texture is no longer needed, it's not used for the injection phase. Save memory. mAccumValVox->scheduleTransitionTo( GpuResidency::OnStorage ); if( mNeedsAlbedoMipmaps || mNeedsAllMipmaps ) @@ -1495,4 +1467,4 @@ namespace Ogre OgreProfileGpuEnd( "VCT build" ); } -} +} // namespace Ogre diff --git a/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizerSourceBase.cpp b/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizerSourceBase.cpp index 77689262603..e206ba8e77c 100644 --- a/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizerSourceBase.cpp +++ b/Components/Hlms/Pbs/src/Vct/OgreVctVoxelizerSourceBase.cpp @@ -151,10 +151,7 @@ namespace Ogre return mDebugVisualizationMode; } //------------------------------------------------------------------------- - Vector3 VctVoxelizerSourceBase::getVoxelOrigin() const - { - return mRegionToVoxelize.getMinimum(); - } + Vector3 VctVoxelizerSourceBase::getVoxelOrigin() const { return mRegionToVoxelize.getMinimum(); } //------------------------------------------------------------------------- Vector3 VctVoxelizerSourceBase::getVoxelCellSize() const { @@ -168,10 +165,7 @@ namespace Ogre return Vector3( mWidth, mHeight, mDepth ); } //------------------------------------------------------------------------- - TextureGpuManager *VctVoxelizerSourceBase::getTextureGpuManager() - { - return mTextureGpuManager; - } + TextureGpuManager *VctVoxelizerSourceBase::getTextureGpuManager() { return mTextureGpuManager; } //------------------------------------------------------------------------- RenderSystem *VctVoxelizerSourceBase::getRenderSystem() { return mRenderSystem; } //------------------------------------------------------------------------- diff --git a/Components/Hlms/Pbs/src/Vct/OgreVoxelVisualizer.cpp b/Components/Hlms/Pbs/src/Vct/OgreVoxelVisualizer.cpp index 762a225b7a6..fef7ef0f320 100644 --- a/Components/Hlms/Pbs/src/Vct/OgreVoxelVisualizer.cpp +++ b/Components/Hlms/Pbs/src/Vct/OgreVoxelVisualizer.cpp @@ -30,14 +30,12 @@ THE SOFTWARE. #include "Vct/OgreVoxelVisualizer.h" -#include "Vao/OgreVaoManager.h" -#include "Vao/OgreVertexArrayObject.h" - -#include "OgreSceneManager.h" - #include "OgreMaterialManager.h" -#include "OgreTechnique.h" #include "OgrePass.h" +#include "OgreSceneManager.h" +#include "OgreTechnique.h" +#include "Vao/OgreVaoManager.h" +#include "Vao/OgreVertexArrayObject.h" namespace Ogre { @@ -64,7 +62,7 @@ namespace Ogre VaoManager *vaoManager = mManager->getDestinationRenderSystem()->getVaoManager(); VertexArrayObjectArray::const_iterator itor = mVaoPerLod[0].begin(); - VertexArrayObjectArray::const_iterator end = mVaoPerLod[0].end(); + VertexArrayObjectArray::const_iterator end = mVaoPerLod[0].end(); while( itor != end ) vaoManager->destroyVertexArrayObject( *itor++ ); @@ -80,8 +78,8 @@ namespace Ogre VaoManager *vaoManager = mManager->getDestinationRenderSystem()->getVaoManager(); VertexBufferPackedVec vertexBuffers; - Ogre::VertexArrayObject *vao = vaoManager->createVertexArrayObject( vertexBuffers, 0, - OT_TRIANGLE_STRIP ); + Ogre::VertexArrayObject *vao = + vaoManager->createVertexArrayObject( vertexBuffers, 0, OT_TRIANGLE_STRIP ); mVaoPerLod[0].push_back( vao ); mVaoPerLod[1].push_back( vao ); @@ -100,24 +98,24 @@ namespace Ogre const size_t stringNameBaseSize = matName.size(); matName += StringConverter::toString( getId() ); - MaterialPtr mat = MaterialManager::getSingleton().getByName( - matName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ). - staticCast(); + MaterialPtr mat = MaterialManager::getSingleton() + .getByName( matName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ) + .staticCast(); if( mat.isNull() ) { - MaterialPtr baseMat = MaterialManager::getSingleton().load( - matName.substr( 0u, stringNameBaseSize ), - ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ). - staticCast(); + MaterialPtr baseMat = MaterialManager::getSingleton() + .load( matName.substr( 0u, stringNameBaseSize ), + ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ) + .staticCast(); mat = baseMat->clone( matName ); mat->load(); } setMaterial( mat ); - const uint32 width = texture->getWidth(); + const uint32 width = texture->getWidth(); const uint32 height = texture->getHeight(); - const uint32 depth = texture->getDepth(); + const uint32 depth = texture->getDepth(); VertexArrayObject *vao = mVaoPerLod[0].back(); vao->setPrimitiveRange( 0u, width * height * depth * 16u ); @@ -147,43 +145,40 @@ namespace Ogre mObjectData.mWorldRadius[mObjectData.mIndex] = aabb.getRadius(); } //----------------------------------------------------------------------------------- - const String& VoxelVisualizer::getMovableType() const - { - return BLANKSTRING; - } + const String &VoxelVisualizer::getMovableType() const { return BLANKSTRING; } //----------------------------------------------------------------------------------- - const LightList& VoxelVisualizer::getLights() const + const LightList &VoxelVisualizer::getLights() const { - return this->queryLights(); //Return the data from our MovableObject base class. + return this->queryLights(); // Return the data from our MovableObject base class. } //----------------------------------------------------------------------------------- - void VoxelVisualizer::getRenderOperation( v1::RenderOperation& op , bool casterPass ) + void VoxelVisualizer::getRenderOperation( v1::RenderOperation &op, bool casterPass ) { OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, - "VoxelVisualizer do not implement getRenderOperation." - " You've put a v2 object in " - "the wrong RenderQueue ID (which is set to be compatible with " - "v1::Entity). Do not mix v2 and v1 objects", - "VoxelVisualizer::getRenderOperation" ); + "VoxelVisualizer do not implement getRenderOperation." + " You've put a v2 object in " + "the wrong RenderQueue ID (which is set to be compatible with " + "v1::Entity). Do not mix v2 and v1 objects", + "VoxelVisualizer::getRenderOperation" ); } //----------------------------------------------------------------------------------- - void VoxelVisualizer::getWorldTransforms( Matrix4* xform ) const + void VoxelVisualizer::getWorldTransforms( Matrix4 *xform ) const { OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, - "VoxelVisualizer do not implement getWorldTransforms." - " You've put a v2 object in " - "the wrong RenderQueue ID (which is set to be compatible with " - "v1::Entity). Do not mix v2 and v1 objects", - "VoxelVisualizer::getRenderOperation" ); + "VoxelVisualizer do not implement getWorldTransforms." + " You've put a v2 object in " + "the wrong RenderQueue ID (which is set to be compatible with " + "v1::Entity). Do not mix v2 and v1 objects", + "VoxelVisualizer::getRenderOperation" ); } //----------------------------------------------------------------------------------- bool VoxelVisualizer::getCastsShadows() const { OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED, - "VoxelVisualizer do not implement getCastsShadows." - " You've put a v2 object in " - "the wrong RenderQueue ID (which is set to be compatible with " - "v1::Entity). Do not mix v2 and v1 objects", - "VoxelVisualizer::getRenderOperation" ); + "VoxelVisualizer do not implement getCastsShadows." + " You've put a v2 object in " + "the wrong RenderQueue ID (which is set to be compatible with " + "v1::Entity). Do not mix v2 and v1 objects", + "VoxelVisualizer::getRenderOperation" ); } -} +} // namespace Ogre