Browse Source

Added a property to modify brightness of the image-based sky light

BearishSun 8 years ago
parent
commit
abf3c6d06f

+ 3 - 2
Data/Raw/Engine/Includes/ReflectionCubemapSampling.bslinc

@@ -46,11 +46,12 @@ Technique : base("ReflectionCubemapSampling") =
 				uint gNumProbes;
 				uint gSkyCubemapAvailable;
 				uint gSkyCubemapNumMips;
+				float gSkyBrightness;
 			}	
 			
 			float3 getSkyIndirectDiffuse(float3 dir)
 			{
-				return gSkyIrradianceTex.SampleLevel(gSkyIrradianceSamp, dir, 0).rgb;
+				return gSkyIrradianceTex.SampleLevel(gSkyIrradianceSamp, dir, 0).rgb * gSkyBrightness;
 			}
 			
 			float3 getSphereReflectionContribution(float normalizedDistance)
@@ -182,7 +183,7 @@ Technique : base("ReflectionCubemapSampling") =
 				if(gSkyCubemapAvailable > 0)
 				{
 					float skyMipLevel = mapRoughnessToMipLevel(roughness, gSkyCubemapNumMips);
-					float4 sample = gSkyReflectionTex.SampleLevel(gSkyReflectionSamp, dir, skyMipLevel);
+					float4 sample = gSkyReflectionTex.SampleLevel(gSkyReflectionSamp, dir, skyMipLevel) * gSkyBrightness;
 					
 					output += sample.rgb * leftoverContribution; 
 				}

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

@@ -29,6 +29,12 @@ namespace bs
 		/** @copydoc Skybox::setTexture */
 		void setTexture(const HTexture& texture) { mInternal->setTexture(texture); }
 
+		/** @copydoc Skybox::setBrightness */
+		void setBrightness(float brightness) { mInternal->setBrightness(brightness); }
+
+		/** @copydoc Skybox::getBrightness */
+		float getBrightness() const { return mInternal->getBrightness(); }
+
 		/** @name Internal
 		 *  @{
 		 */

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

@@ -32,6 +32,15 @@ namespace bs
 		/**	Sets whether the skybox should be used or not. */
 		void setIsActive(bool active) { mIsActive = active; _markCoreDirty(); }
 
+		/** 
+		 * Brightness multiplier that will be applied to skybox values before they're being used. Allows you to make the
+		 * skybox more or less bright. Equal to one by default. 
+		 */
+		void setBrightness(float brightness) { mBrightness = brightness; _markCoreDirty(); }
+
+		/** @see setBrightness */
+		float getBrightness() const { return mBrightness; }
+
 		/** Returns an identifier that uniquely identifies the skybox. */
 		const String& getUUID() const { return mUUID; }
 
@@ -44,6 +53,7 @@ namespace bs
 	protected:
 		String mUUID; /**< Identifier that uniquely identifies the skybox. */
 		bool mIsActive; /**< Determines whether the skybox should be rendered or not. */
+		float mBrightness; /**< Multiplier to apply to evaluated skybox values before using them. */
 	};
 
 	/** Templated base class for both core and sim thread implementations of a skybox. */

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

@@ -19,6 +19,7 @@ namespace bs
 		BS_BEGIN_RTTI_MEMBERS
 			BS_RTTI_MEMBER_REFL(mTexture, 0)
 			BS_RTTI_MEMBER_PLAIN(mUUID, 1)
+			BS_RTTI_MEMBER_PLAIN(mBrightness, 2)
 		BS_END_RTTI_MEMBERS
 	public:
         SkyboxRTTI()

+ 4 - 1
Source/BansheeCore/Source/BsSkybox.cpp

@@ -11,7 +11,7 @@
 namespace bs
 {
 	SkyboxBase::SkyboxBase()
-		: mIsActive(true)
+		: mIsActive(true), mBrightness(1.0f)
 	{ }
 
 	template <bool Core>
@@ -55,6 +55,7 @@ namespace bs
 	{
 		UINT32 size = 0;
 		size += rttiGetElemSize(mIsActive);
+		size += rttiGetElemSize(mBrightness);
 		size += sizeof(SPtr<ct::Texture>);
 		size += rttiGetElemSize(mUUID);
 		size += rttiGetElemSize(getCoreDirtyFlags());
@@ -63,6 +64,7 @@ namespace bs
 
 		char* dataPtr = (char*)buffer;
 		dataPtr = rttiWriteElem(mIsActive, dataPtr);
+		dataPtr = rttiWriteElem(mBrightness, dataPtr);
 		dataPtr = rttiWriteElem(mUUID, dataPtr);
 		dataPtr = rttiWriteElem(getCoreDirtyFlags(), dataPtr);
 
@@ -117,6 +119,7 @@ namespace bs
 			bool oldIsActive = mIsActive;
 
 			dataPtr = rttiReadElem(mIsActive, dataPtr);
+			dataPtr = rttiReadElem(mBrightness, dataPtr);
 			dataPtr = rttiReadElem(mUUID, dataPtr);
 			dataPtr = rttiReadElem(dirtyFlags, dataPtr);
 

+ 3 - 3
Source/RenderBeast/Include/BsLightRendering.h

@@ -95,7 +95,7 @@ namespace bs { namespace ct
 		void setReflectionProbes(const GPUReflProbeData& probeData, const SPtr<Texture>& reflectionCubemaps);
 
 		/** Binds the sky reflection & irradiance textures. Set textures to null if not available. */
-		void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance);
+		void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance, float brightness);
 
 		/** 
 		 * Generates a 2D 2-channel texture containing a pre-integrated G and F factors of the microfactet BRDF. This is an
@@ -152,7 +152,7 @@ namespace bs { namespace ct
 		virtual void setReflectionProbes(const GPUReflProbeData& probeData, const SPtr<Texture>& reflectionCubemaps) = 0;
 
 		/** @copydoc TiledDeferredLighting::setSky() */
-		virtual void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance) = 0;
+		virtual void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance, float brightness) = 0;
 	};
 
 	/** Shader that performs a lighting pass over data stored in the Gbuffer. */
@@ -175,7 +175,7 @@ namespace bs { namespace ct
 		void setReflectionProbes(const GPUReflProbeData& probeData, const SPtr<Texture>& reflectionCubemaps) override;
 
 		/** @copydoc ITiledDeferredLightingMat::setSky() */
-		void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance) override;
+		void setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance, float brightness) override;
 	private:
 		TiledDeferredLighting mInternal;
 	};

+ 1 - 0
Source/RenderBeast/Include/BsReflectionProbeSampling.h

@@ -50,6 +50,7 @@ namespace bs { namespace ct
 		BS_PARAM_BLOCK_ENTRY(INT32, gNumProbes)
 		BS_PARAM_BLOCK_ENTRY(INT32, gSkyCubemapAvailable)
 		BS_PARAM_BLOCK_ENTRY(INT32, gSkyCubemapNumMips)
+		BS_PARAM_BLOCK_ENTRY(float, gSkyBrightness)
 	BS_PARAM_BLOCK_END
 
 	extern ReflProbeParamsParamDef gReflProbeParamsParamDef;

+ 5 - 3
Source/RenderBeast/Source/BsLightRendering.cpp

@@ -231,7 +231,8 @@ namespace bs { namespace ct
 		gReflProbeParamsParamDef.gReflCubemapNumMips.set(mReflectionsParamBuffer, numMips);
 	}
 
-	void TiledDeferredLighting::setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance)
+	void TiledDeferredLighting::setSky(const SPtr<Texture>& skyReflections, const SPtr<Texture>& skyIrradiance, 
+		float brightness)
 	{
 		mSkyReflectionsParam.set(skyReflections);
 		mSkyIrradianceParam.set(skyIrradiance);
@@ -246,6 +247,7 @@ namespace bs { namespace ct
 
 		gReflProbeParamsParamDef.gSkyCubemapNumMips.set(mReflectionsParamBuffer, numMips);
 		gReflProbeParamsParamDef.gSkyCubemapAvailable.set(mReflectionsParamBuffer, skyReflectionsAvailable);
+		gReflProbeParamsParamDef.gSkyBrightness.set(mReflectionsParamBuffer, brightness);
 	}
 
 	// Reverse bits functions used for Hammersley sequence
@@ -421,9 +423,9 @@ namespace bs { namespace ct
 
 	template<int MSAA_COUNT, bool CapturingReflections>
 	void TTiledDeferredLightingMat<MSAA_COUNT, CapturingReflections>::setSky(const SPtr<Texture>& skyReflections,
-		const SPtr<Texture>& skyIrradiance)
+		const SPtr<Texture>& skyIrradiance, float brightness)
 	{
-		mInternal.setSky(skyReflections, skyIrradiance);
+		mInternal.setSky(skyReflections, skyIrradiance, brightness);
 	}
 
 	TiledDeferredLightingMaterials::TiledDeferredLightingMaterials()

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

@@ -1044,7 +1044,7 @@ namespace bs { namespace ct
 
 		lightingMat->setLights(*mGPULightData);
 		lightingMat->setReflectionProbes(*mGPUReflProbeData, mReflCubemapArrayTex);
-		lightingMat->setSky(mSkyboxFilteredReflections, mSkyboxIrradiance);
+		lightingMat->setSky(mSkyboxFilteredReflections, mSkyboxIrradiance, mSkybox->getBrightness());
 
 		lightingMat->execute(renderTargets, perCameraBuffer, mPreintegratedEnvBRDF, viewInfo->renderWithNoLighting());