Browse Source

Camera & Light can now be activated/deactivated
Fixed constant buffer spot angles used for lighting calculations

BearishSun 10 years ago
parent
commit
dafc253aca

+ 11 - 0
BansheeEngine/Include/BsCamera.h

@@ -116,6 +116,16 @@ namespace BansheeEngine
 		 */
 		virtual Vector3 getPosition() const { return mPosition; }
 
+		/**
+		 * @brief	Sets should the camera be rendered to or not.
+		 */
+		void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
+		
+		/**
+		 * @brief	Gets whether the camera be rendered to or not.
+		 */
+		bool getIsActive() const { return mIsActive; }
+
 		/**
 		 * @brief	Gets the Z (forward) axis of the object, in world space.
 		 *
@@ -499,6 +509,7 @@ namespace BansheeEngine
 
 		Vector3 mPosition; /**< World space position. */
 		Quaternion mRotation; /**< World space rotation. */
+		bool mIsActive; /**< Is camera being rendered to. */
 
 		ProjectionType mProjType; /**< Type of camera projection. */
 		Radian mHorzFOV; /**< Horizontal field of view represents how wide is the camera angle. */

+ 10 - 2
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -331,6 +331,7 @@ namespace BansheeEngine
 
 			auto textureIO = gImporter().createImportOptions<TextureImportOptions>(inputPath);
 			textureIO->setCPUReadable(true);
+			textureIO->setGenerateMipmaps(false);
 			HTexture splashTexture = gImporter().import<Texture>(inputPath, textureIO);
 
 			PixelDataPtr splashPixelData = splashTexture->getProperties().allocateSubresourceBuffer(0);
@@ -1051,10 +1052,17 @@ namespace BansheeEngine
 			if (FileSystem::exists(outputPath))
 				resource = gResources().load(outputPath);
 
+			ImportOptionsPtr importOptions = gImporter().createImportOptions(filePath);
+			if(importOptions != nullptr && rtti_is_of_type<TextureImportOptions>(importOptions))
+			{
+				SPtr<TextureImportOptions> texImportOptions = std::static_pointer_cast<TextureImportOptions>(importOptions);
+				texImportOptions->setGenerateMipmaps(false);
+			}
+
 			if (resource != nullptr)
-				gImporter().reimport(resource, filePath);
+				gImporter().reimport(resource, filePath, importOptions);
 			else
-				resource = Importer::instance().import(filePath);
+				resource = Importer::instance().import(filePath, importOptions);
 
 			if (resource != nullptr)
 			{

+ 6 - 2
BansheeEngine/Source/BsCamera.cpp

@@ -21,7 +21,7 @@ namespace BansheeEngine
 		:mProjType(PT_PERSPECTIVE), mHorzFOV(Degree(90.0f)), mFarDist(1000.0f),
 		mNearDist(0.05f), mAspect(1.33333333333333f), mOrthoHeight(5), mRecalcFrustum(true), mRecalcFrustumPlanes(true),
 		mCustomViewMatrix(false), mCustomProjMatrix(false), mFrustumExtentsManuallySet(false), mPriority(0), 
-		mLayers(0xFFFFFFFFFFFFFFFF), mRecalcView(true), mCameraFlags(0)
+		mLayers(0xFFFFFFFFFFFFFFFF), mRecalcView(true), mCameraFlags(0), mIsActive(true)
 	{
 		mViewMatrix = Matrix4::ZERO;
 		mProjMatrixRS = Matrix4::ZERO;
@@ -723,12 +723,14 @@ namespace BansheeEngine
 		dataPtr = rttiReadElem(mCustomProjMatrix, dataPtr);
 		dataPtr = rttiReadElem(mFrustumExtentsManuallySet, dataPtr);
 		dataPtr = rttiReadElem(mCameraFlags, dataPtr);
+		dataPtr = rttiReadElem(mIsActive, dataPtr);
 
 		mRecalcFrustum = true;
 		mRecalcFrustumPlanes = true;
 		mRecalcView = true;
 
-		RendererManager::instance().getActive()->_notifyCameraAdded(this);
+		if(mIsActive)
+			RendererManager::instance().getActive()->_notifyCameraAdded(this);
 	}
 
 	Camera::Camera(RenderTargetPtr target, float left, float top, float width, float height)
@@ -797,6 +799,7 @@ namespace BansheeEngine
 		size += rttiGetElemSize(mCustomProjMatrix);
 		size += rttiGetElemSize(mFrustumExtentsManuallySet);
 		size += rttiGetElemSize(mCameraFlags);
+		size += rttiGetElemSize(mIsActive);
 
 		UINT8* buffer = allocator->alloc(size);
 
@@ -815,6 +818,7 @@ namespace BansheeEngine
 		dataPtr = rttiWriteElem(mCustomProjMatrix, dataPtr);
 		dataPtr = rttiWriteElem(mFrustumExtentsManuallySet, dataPtr);
 		dataPtr = rttiWriteElem(mCameraFlags, dataPtr);
+		dataPtr = rttiWriteElem(mIsActive, dataPtr);
 
 		return CoreSyncData(buffer, size);
 	}

+ 1 - 1
BansheeEngine/Source/BsLight.cpp

@@ -12,7 +12,7 @@ namespace BansheeEngine
 {
 	LightBase::LightBase()
 		:mType(LightType::Point), mCastsShadows(false), mRange(10.0f),
-		mIntensity(5.0f), mSpotAngle(45), mColor(Color::White), mIsActive(true)
+		mIntensity(5.0f), mSpotAngle(45), mSpotFalloffAngle(35.0f), mColor(Color::White), mIsActive(true)
 	{
 		mBounds = Sphere(mPosition, mRange);
 	}

+ 10 - 0
BansheeEngine/Source/BsSceneManager.cpp

@@ -109,6 +109,11 @@ namespace BansheeEngine
 
 				handler->_setLastModifiedHash(curHash);
 			}
+
+			if (so->getActive() != handler->getIsActive())
+			{
+				handler->setIsActive(so->getActive());
+			}
 		}
 
 		for (auto& lightPair : mLights)
@@ -124,6 +129,11 @@ namespace BansheeEngine
 
 				handler->_setLastModifiedHash(curHash);
 			}
+
+			if (so->getActive() != handler->getIsActive())
+			{
+				handler->setIsActive(so->getActive());
+			}
 		}
 	}
 

+ 1 - 1
RenderBeast/Include/BsLightRendering.h

@@ -9,7 +9,7 @@ namespace BansheeEngine
 	BS_PARAM_BLOCK_BEGIN(PerLightParamBuffer)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightPositionAndType)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightColorAndIntensity)
-		BS_PARAM_BLOCK_ENTRY(Vector2, gLightSpotAngles)
+		BS_PARAM_BLOCK_ENTRY(Vector3, gLightSpotAngles)
 		BS_PARAM_BLOCK_ENTRY(Vector3, gLightDirection)
 		BS_PARAM_BLOCK_ENTRY(Vector4, gLightGeometry)
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gMatConeTransform)

+ 4 - 3
RenderBeast/Source/BsLightRendering.cpp

@@ -38,9 +38,10 @@ namespace BansheeEngine
 
 		mBuffer.gLightColorAndIntensity.set(colorAndIntensity);
 
-		Vector2 spotAngles;
-		spotAngles.x = light->getSpotFalloffAngle().valueDegrees();
-		spotAngles.y = light->getSpotAngle().valueDegrees();
+		Vector3 spotAngles;
+		spotAngles.x = light->getSpotAngle().valueRadians();
+		spotAngles.y = cos(spotAngles.x);
+		spotAngles.z = 1.0f / (Math::cos(light->getSpotFalloffAngle()) - spotAngles.y);
 
 		mBuffer.gLightSpotAngles.set(spotAngles);
 

+ 5 - 0
SBansheeEngine/Source/BsScriptCamera.cpp

@@ -120,6 +120,11 @@ namespace BansheeEngine
 
 			mLastUpdateHash = curHash;
 		}
+
+		if (parent->getActive() != mCamera->getIsActive())
+		{
+			mCamera->setIsActive(parent->getActive());
+		}
 	}
 
 	void ScriptCamera::internal_Create(MonoObject* managedInstance, ScriptSceneObject* parentSO)

+ 7 - 0
SBansheeEngine/Source/BsScriptLight.cpp

@@ -128,7 +128,14 @@ namespace BansheeEngine
 		HSceneObject parentSO = parent->getNativeSceneObject();
 
 		if (!parentSO.isDestroyed())
+		{
 			thisPtr->getInternal()->_updateTransform(parentSO);
+
+			if (parentSO->getActive() != thisPtr->getInternal()->getIsActive())
+			{
+				thisPtr->getInternal()->setIsActive(parentSO->getActive());
+			}
+		}
 	}
 
 	void ScriptLight::internal_onDestroy(ScriptLight* instance)