BearishSun 8 лет назад
Родитель
Сommit
3e10138c98

+ 5 - 0
Source/BansheeCore/CMakeSources.cmake

@@ -22,6 +22,7 @@ set(BS_BANSHEECORE_INC_COMPONENTS
 	"Include/BsCAnimation.h"
 	"Include/BsCBone.h"	
 	"Include/BsCReflectionProbe.h"
+	"Include/BsCSkybox.h"
 )
 
 set(BS_BANSHEECORE_INC_PHYSICS
@@ -99,6 +100,7 @@ set(BS_BANSHEECORE_INC_RENDERER
 	"Include/BsPostProcessSettings.h"
 	"Include/BsRendererExtension.h"
 	"Include/BsReflectionProbe.h"
+	"Include/BsSkybox.h"
 )
 
 set(BS_BANSHEECORE_SRC_LOCALIZATION
@@ -259,6 +261,7 @@ set(BS_BANSHEECORE_SRC_COMPONENTS
 	"Source/BsCAnimation.cpp"
 	"Source/BsCBone.cpp"	
 	"Source/BsCReflectionProbe.cpp"
+	"Source/BsCSkybox.cpp"
 )
 
 set(BS_BANSHEECORE_SRC_IMPORTER
@@ -357,6 +360,7 @@ set(BS_BANSHEECORE_INC_RTTI
 	"Include/BsLightRTTI.h"	
 	"Include/BsReflectionProbeRTTI.h"
 	"Include/BsCReflectionProbeRTTI.h"
+	"Include/BsSkyboxRTTI.h"
 )
 
 set(BS_BANSHEECORE_SRC_RENDERER
@@ -370,6 +374,7 @@ set(BS_BANSHEECORE_SRC_RENDERER
 	"Source/BsPostProcessSettings.cpp"
 	"Source/BsRendererExtension.cpp"
 	"Source/BsReflectionProbe.cpp"
+	"Source/BsSkybox.cpp"
 )
 
 set(BS_BANSHEECORE_SRC_RESOURCES

+ 16 - 1
Source/BansheeCore/Include/BsCReflectionProbe.h

@@ -41,9 +41,24 @@ namespace bs
 	    /** @copydoc ReflectionProbe::setExtents */
 		void setExtents(const Vector3& extents) { mInternal->setExtents(extents); }
 
-	    /** @copydoc ReflectionProbe::getBounds  */
+        /** Retrieves transition distance set by setTransitionDistance(). */
+        float getTransitionDistance() const { return mInternal->getTransitionDistance(); }
+
+        /** @copydoc ReflectionProbe::setTransitionDistance */
+        void setTransitionDistance(float distance) { mInternal->setTransitionDistance(distance); }
+
+        /** @copydoc ReflectionProbe::getCustomTexture */
+        HTexture getCustomTexture() const { return mInternal->getCustomTexture(); }
+
+        /** @copydoc ReflectionProbe::setCustomTexture */
+        void setCustomTexture(const HTexture& texture) { mInternal->setCustomTexture(texture); }
+
+	    /** @copydoc ReflectionProbe::getBounds */
 		Sphere getBounds() const;
 
+        /** @copydoc ReflectionProbe::generate */
+        void generate() { mInternal->generate(); }
+
 		/** @name Internal 
 		 *  @{
 		 */

+ 66 - 0
Source/BansheeCore/Include/BsCSkybox.h

@@ -0,0 +1,66 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsSkybox.h"
+#include "BsComponent.h"
+
+namespace bs 
+{
+	/** @addtogroup Components
+	 *  @{
+	 */
+
+	/**
+	 * @copydoc	Skybox
+	 *
+	 * Wraps Skybox as a Component.
+	 */
+    class BS_CORE_EXPORT CSkybox : public Component
+    {
+    public:
+        CSkybox(const HSceneObject& parent);
+		virtual ~CSkybox();
+
+        /** @copydoc Skybox::getTexture */
+        HTexture getTexture() const { return mInternal->getTexture(); }
+
+        /** @copydoc Skybox::setTexture */
+        void setTexture(const HTexture& texture) { mInternal->setTexture(texture); }
+
+		/** @name Internal 
+		 *  @{
+		 */
+
+	    /**	Returns the skybox that this component wraps. */
+		SPtr<Skybox> _getSkybox() const { return mInternal; }
+
+		/** @} */
+
+    protected:
+		mutable SPtr<Skybox> mInternal;
+
+		/************************************************************************/
+		/* 						COMPONENT OVERRIDES                      		*/
+		/************************************************************************/
+	protected:
+		friend class SceneObject;
+
+		/** @copydoc Component::update */
+		void update() override { }
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class CSkyboxRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		RTTITypeBase* getRTTI() const override;
+
+	protected:
+		CSkybox(); // Serialization only
+     };
+
+	 /** @} */
+}

+ 48 - 0
Source/BansheeCore/Include/BsCSkyboxRTTI.h

@@ -0,0 +1,48 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsCSkybox.h"
+#include "BsGameObjectRTTI.h"
+
+namespace bs
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Engine
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT CSkyboxRTTI : public RTTIType <CSkybox, Component, CSkyboxRTTI>
+	{
+	private:
+		SPtr<Skybox> getInternal(CSkybox* obj) { return obj->mInternal; }
+		void setInternal(CSkybox* obj, SPtr<Skybox> val) { obj->mInternal = val; }
+
+	public:
+        CSkyboxRTTI()
+		{
+			addReflectablePtrField("mInternal", 0, &CSkyboxRTTI::getInternal, &CSkyboxRTTI::setInternal);
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "CSkybox";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_CSkybox;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return GameObjectRTTI::createGameObject<CSkybox>();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
+}

+ 3 - 0
Source/BansheeCore/Include/BsCorePrerequisites.h

@@ -445,6 +445,7 @@ namespace bs
 		class RenderStateManager;
 		class HardwareBufferManager;
 		class ReflectionProbe;
+        class Skybox;
 	}
 }
 
@@ -566,6 +567,8 @@ namespace bs
 		TID_ReflectionProbe = 1131,
 		TID_CReflectionProbe = 1132,
 		TID_CachedTextureData = 1133,
+        TID_Skybox = 1134,
+        TID_CSkybox = 1135,
 
 		// Moved from Engine layer
 		TID_CCamera = 30000,

+ 14 - 0
Source/BansheeCore/Include/BsRenderer.h

@@ -166,6 +166,20 @@ namespace bs
 		 */
 		virtual void notifyReflectionProbeRemoved(ReflectionProbe* probe) { }
 
+		/**
+		 * Called whenever a skybox is created.
+		 *
+		 * @note	Core thread.
+		 */
+		virtual void notifySkyboxAdded(Skybox* skybox) { }
+
+		/**
+		 * Called whenever a skybox is destroyed.
+		 *
+		 * @note	Core thread.
+		 */
+		virtual void notifySkyboxRemoved(Skybox* skybox) { }
+
 		/**
 		 * Creates a new empty renderer mesh data.
 		 *

+ 125 - 0
Source/BansheeCore/Include/BsSkybox.h

@@ -0,0 +1,125 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsIReflectable.h"
+#include "BsCoreObject.h"
+
+namespace bs
+{
+	/** @addtogroup Implementation
+	 *  @{
+	 */
+
+	/** Base class for both core and sim thread implementations of a skybox. */
+	class BS_CORE_EXPORT SkyboxBase
+	{
+	public:
+        SkyboxBase();
+		virtual ~SkyboxBase() { }
+        
+		/**	Checks whether the skybox should be used or not. */
+		bool getIsActive() const { return mIsActive; }
+
+		/**	Sets whether the skybox should be used or not. */
+		void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
+
+		/** Returns an identifier that uniquely identifies the skybox. */
+		const String& getUUID() const { return mUUID; }
+
+		/** 
+		 * Marks the simulation thread object as dirty and notifies the system its data should be synced with its core 
+		 * thread counterpart. 
+		 */
+		virtual void _markCoreDirty() { }
+
+	protected:
+		String mUUID; /**< Identifier that uniquely identifies the skybox. */
+		bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
+	};
+
+	/** Templated base class for both core and sim thread implementations of a skybox. */
+	template<bool Core>
+	class BS_CORE_EXPORT TSkybox : public SkyboxBase
+	{
+		typedef typename TTextureType<Core>::Type TextureType;
+
+	public:
+        TSkybox();
+		virtual ~TSkybox() { }
+
+		/** 
+		 * Assigns an environment map to use for sampling skybox radiance. Must be a cube-map texture, and should ideally
+		 * contain HDR data.
+		 */
+		void setTexture(const TextureType& texture) { mTexture = texture; _markCoreDirty(); }
+
+		/** Gets the texture assigned through setTexture(). */
+		TextureType getTexture() const { return mTexture; }
+
+	protected:
+		TextureType mTexture;
+	};
+
+	/** @} */
+	/** @addtogroup Renderer-Engine-Internal
+	 *  @{
+	 */
+
+	namespace ct { class Skybox; }
+
+	/** Allows you to specify an environment map to use for sampling radiance of the sky. */
+	class BS_CORE_EXPORT Skybox : public IReflectable, public CoreObject, public TSkybox<false>
+	{
+	public:
+		/**	Retrieves an implementation of the skybox usable only from the core thread. */
+		SPtr<ct::Skybox> getCore() const;
+
+		/** Creates a new skybox. */
+		static SPtr<Skybox> create();
+
+	protected:
+        Skybox();
+
+		/** @copydoc CoreObject::createCore */
+		SPtr<ct::CoreObject> createCore() const override;
+
+		/** @copydoc SkyboxBase::_markCoreDirty */
+		void _markCoreDirty() override;
+
+		/** @copydoc CoreObject::syncToCore */
+		CoreSyncData syncToCore(FrameAlloc* allocator) override;
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class SkyboxRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		RTTITypeBase* getRTTI() const override;
+	};
+
+	namespace ct
+	{
+	/** Core thread usable version of a bs::Skybox */
+	class BS_CORE_EXPORT Skybox : public CoreObject, public TSkybox<true>
+	{
+	public:
+		~Skybox();
+
+	protected:
+		friend class bs::Skybox;
+
+        Skybox();
+
+		/** @copydoc CoreObject::initialize */
+		void initialize() override;
+
+		/** @copydoc CoreObject::syncToCore */
+		void syncToCore(const CoreSyncData& data) override;
+	};
+	}
+
+	/** @} */
+}

+ 55 - 0
Source/BansheeCore/Include/BsSkyboxRTTI.h

@@ -0,0 +1,55 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#pragma once
+
+#include "BsCorePrerequisites.h"
+#include "BsRTTIType.h"
+#include "BsSkybox.h"
+
+namespace bs
+{
+	/** @cond RTTI */
+	/** @addtogroup RTTI-Impl-Engine
+	 *  @{
+	 */
+
+	class BS_CORE_EXPORT SkyboxRTTI : public RTTIType <Skybox, IReflectable, SkyboxRTTI>
+	{
+	private:
+		BS_BEGIN_RTTI_MEMBERS
+			BS_RTTI_MEMBER_REFL(mTexture, 0)
+			BS_RTTI_MEMBER_PLAIN(mUUID, 1)
+		BS_END_RTTI_MEMBERS
+	public:
+        SkyboxRTTI()
+			:mInitMembers(this)
+		{ }
+
+		void onDeserializationEnded(IReflectable* obj, const UnorderedMap<String, UINT64>& params) override
+		{
+			// Note: Since this is a CoreObject I should call initialize() right after deserialization,
+			// but since this specific type is used in Components we delay initialization until Component
+			// itself does it. Keep this is mind in case this ever needs to be deserialized for non-Component 
+			// purposes (you'll need to call initialize manually).
+		}
+
+		const String& getRTTIName() override
+		{
+			static String name = "Skybox";
+			return name;
+		}
+
+		UINT32 getRTTIId() override
+		{
+			return TID_Skybox;
+		}
+
+		SPtr<IReflectable> newRTTIObject() override
+		{
+			return Skybox::create();
+		}
+	};
+
+	/** @} */
+	/** @endcond */
+}

+ 1 - 1
Source/BansheeCore/Source/BsCReflectionProbe.cpp

@@ -16,7 +16,7 @@ namespace bs
 		: Component(parent)
 	{
 		setFlag(ComponentFlag::AlwaysRun, true);
-		setName("Light");
+		setName("ReflectionProbe");
 	}
 
 	CReflectionProbe::~CReflectionProbe()

+ 36 - 0
Source/BansheeCore/Source/BsCSkybox.cpp

@@ -0,0 +1,36 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsCSkybox.h"
+#include "BsCSkyboxRTTI.h"
+#include "BsSceneManager.h"
+
+namespace bs
+{
+    CSkybox::CSkybox()
+	{
+		setFlag(ComponentFlag::AlwaysRun, true);
+		setName("Skybox");
+	}
+
+    CSkybox::CSkybox(const HSceneObject& parent)
+		: Component(parent)
+	{
+		setFlag(ComponentFlag::AlwaysRun, true);
+		setName("Skybox");
+	}
+
+    CSkybox::~CSkybox()
+	{
+		mInternal->destroy();
+	}
+
+	RTTITypeBase* CSkybox::getRTTIStatic()
+	{
+		return CSkyboxRTTI::instance();
+	}
+
+	RTTITypeBase* CSkybox::getRTTI() const
+	{
+		return CSkybox::getRTTIStatic();
+	}
+}

+ 139 - 0
Source/BansheeCore/Source/BsSkybox.cpp

@@ -0,0 +1,139 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
+#include "BsSkybox.h"
+#include "BsSkyboxRTTI.h"
+#include "BsSceneObject.h"
+#include "BsFrameAlloc.h"
+#include "BsTexture.h"
+#include "BsRenderer.h"
+#include "BsUUID.h"
+
+namespace bs
+{
+    SkyboxBase::SkyboxBase()
+        : mIsActive(true)
+    { }
+
+    template <bool Core>
+    TSkybox<Core>::TSkybox()
+        : SkyboxBase()
+    { }
+
+    template class TSkybox<true>;
+    template class TSkybox<false>;
+
+    Skybox::Skybox()
+    { }
+
+    SPtr<ct::Skybox> Skybox::getCore() const
+    {
+        return std::static_pointer_cast<ct::Skybox>(mCoreSpecific);
+    }
+
+    SPtr<Skybox> Skybox::create()
+    {
+        Skybox* skybox = new (bs_alloc<Skybox>()) Skybox();
+        SPtr<Skybox> skyboxPtr = bs_core_ptr<Skybox>(skybox);
+        skyboxPtr->_setThisPtr(skyboxPtr);
+        skyboxPtr->mUUID = UUIDGenerator::generateRandom();
+        skyboxPtr->initialize();
+
+        return skyboxPtr;
+    }
+
+    SPtr<ct::CoreObject> Skybox::createCore() const
+    {
+        ct::Skybox* skybox = new (bs_alloc<ct::Skybox>()) ct::Skybox();
+        SPtr<ct::Skybox> skyboxPtr = bs_shared_ptr<ct::Skybox>(skybox);
+        skyboxPtr->mUUID = mUUID;
+        skyboxPtr->_setThisPtr(skyboxPtr);
+
+        return skyboxPtr;
+    }
+
+    CoreSyncData Skybox::syncToCore(FrameAlloc* allocator)
+    {
+        UINT32 size = 0;
+        size += rttiGetElemSize(mIsActive);
+        size += rttiGetElemSize(sizeof(SPtr<ct::Texture>));
+        size += rttiGetElemSize(mUUID);
+
+        UINT8* buffer = allocator->alloc(size);
+
+        char* dataPtr = (char*)buffer;
+        dataPtr = rttiWriteElem(mIsActive, dataPtr);
+        dataPtr = rttiWriteElem(mUUID, dataPtr);
+
+        SPtr<ct::Texture>* texture = new (dataPtr) SPtr<ct::Texture>();
+        if (mTexture.isLoaded(false))
+            *texture = mTexture->getCore();
+        else
+            *texture = nullptr;
+
+        dataPtr += sizeof(SPtr<ct::Texture>);
+
+        return CoreSyncData(buffer, size);
+    }
+
+    void Skybox::_markCoreDirty()
+    {
+        markCoreDirty();
+    }
+
+    RTTITypeBase* Skybox::getRTTIStatic()
+    {
+        return SkyboxRTTI::instance();
+    }
+
+    RTTITypeBase* Skybox::getRTTI() const
+    {
+        return Skybox::getRTTIStatic();
+    }
+
+    namespace ct
+    {
+        Skybox::Skybox()
+        { }
+
+        Skybox::~Skybox()
+        {
+            gRenderer()->notifySkyboxRemoved(this);
+        }
+
+        void Skybox::initialize()
+        {
+            gRenderer()->notifySkyboxAdded(this);
+
+            CoreObject::initialize();
+        }
+
+        void Skybox::syncToCore(const CoreSyncData& data)
+        {
+            char* dataPtr = (char*)data.getBuffer();
+
+            bool oldIsActive = mIsActive;
+
+            dataPtr = rttiReadElem(mIsActive, dataPtr);
+            dataPtr = rttiReadElem(mUUID, dataPtr);
+
+            SPtr<Texture>* texture = (SPtr<Texture>*)dataPtr;
+
+            mTexture = *texture;
+            texture->~SPtr<Texture>();
+            dataPtr += sizeof(SPtr<Texture>);
+
+            if (oldIsActive != mIsActive)
+            {
+                if (mIsActive)
+                    gRenderer()->notifySkyboxAdded(this);
+                else
+                    gRenderer()->notifySkyboxRemoved(this);
+            }
+            else
+            {
+                gRenderer()->notifySkyboxRemoved(this);
+                gRenderer()->notifySkyboxAdded(this);
+            }
+        }
+    }
+}

+ 1 - 1
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -187,7 +187,7 @@ namespace bs { namespace ct
 		bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
 		bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
 
-		return float(bits) * 2.3283064365386963e-10; // 0x100000000
+		return float(bits) * 2.3283064365386963e-10f; // 0x100000000
 	}
 
 	void hammersleySequence(UINT32 i, UINT32 count, float& e0, float& e1)