Browse Source

GUIRenderTexture now uses a non-transparent shader

Marko Pintera 11 năm trước cách đây
mục cha
commit
b1e42e1c76

+ 1 - 1
BansheeEditor/Source/BsGUIWindowDropArea.cpp

@@ -16,7 +16,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	GUIWindowDropArea::GUIWindowDropArea(const String& styleName, const GUILayoutOptions& layoutOptions)
 	GUIWindowDropArea::GUIWindowDropArea(const String& styleName, const GUILayoutOptions& layoutOptions)
-		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::ScaleToFit, layoutOptions)
+		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::ScaleToFit, true, layoutOptions)
 	{ }
 	{ }
 
 
 	GUIWindowDropArea::~GUIWindowDropArea()
 	GUIWindowDropArea::~GUIWindowDropArea()

+ 1 - 1
BansheeEditor/Source/BsGUIWindowFrame.cpp

@@ -19,7 +19,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	GUIWindowFrame::GUIWindowFrame(const String& styleName, const GUILayoutOptions& layoutOptions)
 	GUIWindowFrame::GUIWindowFrame(const String& styleName, const GUILayoutOptions& layoutOptions)
-		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::StretchToFit, layoutOptions)
+		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::StretchToFit, true, layoutOptions)
 	{
 	{
 
 
 	}
 	}

+ 11 - 0
BansheeEngine/Include/BsBuiltinResources.h

@@ -90,6 +90,11 @@ namespace BansheeEngine
 		 */
 		 */
 		GUIMaterialInfo createSpriteImageMaterial() const;
 		GUIMaterialInfo createSpriteImageMaterial() const;
 
 
+		/**
+		* @brief	Creates material used for non-transparent image sprite rendering (e.g. images in GUI).
+		*/
+		GUIMaterialInfo createSpriteNonAlphaImageMaterial() const;
+
 		/**
 		/**
 		 * @brief	Creates a material used as a replacement when no other material is usable.
 		 * @brief	Creates a material used as a replacement when no other material is usable.
 		 */
 		 */
@@ -143,6 +148,11 @@ namespace BansheeEngine
 		 */
 		 */
 		void initSpriteImageShader();
 		void initSpriteImageShader();
 
 
+		/**
+		 * @brief	Loads an compiles a shader for non-transparent image sprite rendering.
+		 */
+		void initSpriteNonAlphaImageShader();
+
 		/**
 		/**
 		 * @brief	Loads an compiles a simple shader to be used with no other is usable.
 		 * @brief	Loads an compiles a simple shader to be used with no other is usable.
 		 */
 		 */
@@ -167,6 +177,7 @@ namespace BansheeEngine
 
 
 		ShaderPtr mShaderSpriteText;
 		ShaderPtr mShaderSpriteText;
 		ShaderPtr mShaderSpriteImage;
 		ShaderPtr mShaderSpriteImage;
+		ShaderPtr mShaderSpriteNonAlphaImage;
 		ShaderPtr mShaderDummy;
 		ShaderPtr mShaderDummy;
 
 
 		WString mActiveShaderSubFolder;
 		WString mActiveShaderSubFolder;

+ 17 - 0
BansheeEngine/Include/BsGUIMaterialManager.h

@@ -35,6 +35,16 @@ namespace BansheeEngine
 		 */
 		 */
 		const GUIMaterialInfo& requestImageMaterial(const HTexture& texture, const Color& tint) const;
 		const GUIMaterialInfo& requestImageMaterial(const HTexture& texture, const Color& tint) const;
 
 
+		/**
+		 * @brief	Creates a new material, or returns a reference to an existing one based on
+		 * 			the provided primary texture.
+		 * 			
+		 *			Returned material can be used for non-transparent image rendering.
+		 *			
+		 *			Make sure to release all materials with a call to "releaseMaterial()".
+		 */
+		const GUIMaterialInfo& requestNonAlphaImageMaterial(const HTexture& texture, const Color& tint) const;
+
 		/**
 		/**
 		 * @brief	Releases the held reference to the material. This allows us to fully unload a material
 		 * @brief	Releases the held reference to the material. This allows us to fully unload a material
 		 * 			and their textures when they are no longer being used.
 		 * 			and their textures when they are no longer being used.
@@ -53,6 +63,12 @@ namespace BansheeEngine
 		 */
 		 */
 		const GUIMaterialInfo* findExistingImageMaterial(const HTexture& texture, const Color& tint) const;
 		const GUIMaterialInfo* findExistingImageMaterial(const HTexture& texture, const Color& tint) const;
 
 
+		/**
+		 * @brief	Attempts to find an existing non-transparent image material with the specified color and tint.
+		 *			Returns null if one cannot be found.
+		 */
+		const GUIMaterialInfo* findExistingNonAlphaImageMaterial(const HTexture& texture, const Color& tint) const;
+
 		/**
 		/**
 		 * @brief	Releases all internal materials, whether they are used or not.
 		 * @brief	Releases all internal materials, whether they are used or not.
 		 */
 		 */
@@ -75,5 +91,6 @@ namespace BansheeEngine
 
 
 		mutable Vector<GUIMaterial> mTextMaterials;
 		mutable Vector<GUIMaterial> mTextMaterials;
 		mutable Vector<GUIMaterial> mImageMaterials;
 		mutable Vector<GUIMaterial> mImageMaterials;
+		mutable Vector<GUIMaterial> mNonAlphaImageMaterials;
 	};
 	};
 }
 }

+ 31 - 2
BansheeEngine/Include/BsGUITexture.h

@@ -28,6 +28,34 @@ namespace BansheeEngine
 		 */
 		 */
 		static const String& getGUITypeName();
 		static const String& getGUITypeName();
 
 
+		/**
+		 * @brief	Creates a new GUI texture element.
+		 *
+		 * @param	texture			Texture element to display.
+		 * @param	scale			Scale mode to use when sizing the texture.
+		 * @param	transparent		Determines should the texture be rendered with transparency active.
+		 * @param	layoutOptions	Options that allows you to control how is the element positioned in
+		 *							GUI layout. This will override any similar options set by style.
+		 * @param	styleName		Optional style to use for the element. Style will be retrieved
+		 *							from GUISkin of the GUIWidget the element is used on. If not specified
+		 *							default style is used.
+		 */
+		static GUITexture* create(const HSpriteTexture& texture, GUIImageScaleMode scale, bool transparent,
+			const GUIOptions& layoutOptions, const String& styleName = StringUtil::BLANK);
+
+		/**
+		 * @brief	Creates a new GUI texture element.
+		 *
+		 * @param	texture			Texture element to display.
+		 * @param	scale			Scale mode to use when sizing the texture.
+		 * @param	transparent		Determines should the texture be rendered with transparency active.
+		 * @param	styleName		Optional style to use for the element. Style will be retrieved
+		 *							from GUISkin of the GUIWidget the element is used on. If not specified
+		 *							default style is used.
+		 */
+		static GUITexture* create(const HSpriteTexture& texture, GUIImageScaleMode scale, bool transparent,
+			const String& styleName = StringUtil::BLANK);
+
 		/**
 		/**
 		 * @brief	Creates a new GUI texture element.
 		 * @brief	Creates a new GUI texture element.
 		 *
 		 *
@@ -54,7 +82,6 @@ namespace BansheeEngine
 		static GUITexture* create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 		static GUITexture* create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 			const String& styleName = StringUtil::BLANK);
 			const String& styleName = StringUtil::BLANK);
 
 
-
 		/**
 		/**
 		 * @brief	Creates a new GUI texture element. Uses the default StretchToFit scale mode.
 		 * @brief	Creates a new GUI texture element. Uses the default StretchToFit scale mode.
 		 *
 		 *
@@ -138,7 +165,8 @@ namespace BansheeEngine
 		 */
 		 */
 		virtual Vector2I _getOptimalSize() const;
 		virtual Vector2I _getOptimalSize() const;
 	protected:
 	protected:
-		GUITexture(const String& styleName, const HSpriteTexture& texture, GUIImageScaleMode scale, const GUILayoutOptions& layoutOptions);
+		GUITexture(const String& styleName, const HSpriteTexture& texture, GUIImageScaleMode scale, 
+			bool transparent, const GUILayoutOptions& layoutOptions);
 		virtual ~GUITexture();
 		virtual ~GUITexture();
 
 
 		/**
 		/**
@@ -176,6 +204,7 @@ namespace BansheeEngine
 		HSpriteTexture mActiveTexture;
 		HSpriteTexture mActiveTexture;
 		IMAGE_SPRITE_DESC mDesc;
 		IMAGE_SPRITE_DESC mDesc;
 		GUIImageScaleMode mScaleMode;
 		GUIImageScaleMode mScaleMode;
+		bool mTransparent;
 		bool mUsingStyleTexture;
 		bool mUsingStyleTexture;
 	};
 	};
 }
 }

+ 2 - 1
BansheeEngine/Include/BsImageSprite.h

@@ -14,7 +14,7 @@ namespace BansheeEngine
 	{
 	{
 		IMAGE_SPRITE_DESC()
 		IMAGE_SPRITE_DESC()
 			:width(0), height(0), anchor(SA_TopLeft), borderLeft(0), borderRight(0), 
 			:width(0), height(0), anchor(SA_TopLeft), borderLeft(0), borderRight(0), 
-			borderTop(0), borderBottom(0), uvScale(1.0f, 1.0f), uvOffset(0.0f, 0.0f)
+			borderTop(0), borderBottom(0), uvScale(1.0f, 1.0f), uvOffset(0.0f, 0.0f), transparent(true)
 		{ }
 		{ }
 
 
 		UINT32 width; /**< Width of the image in pixels. */
 		UINT32 width; /**< Width of the image in pixels. */
@@ -22,6 +22,7 @@ namespace BansheeEngine
 		SpriteAnchor anchor; /**< Determines where in the provided bounds will the sprite be placed. */
 		SpriteAnchor anchor; /**< Determines where in the provided bounds will the sprite be placed. */
 		Vector2 uvScale; /**< Scale applied to UV width/height used for rendering the sprite. */
 		Vector2 uvScale; /**< Scale applied to UV width/height used for rendering the sprite. */
 		Vector2 uvOffset; /**< Offset applied to UV coordinates when rendering the sprite. */
 		Vector2 uvOffset; /**< Offset applied to UV coordinates when rendering the sprite. */
+		bool transparent; /**< Should the sprite be rendered with transparency. */
 
 
 		SpriteTexturePtr texture; /**< Texture to overlay on the sprite. */
 		SpriteTexturePtr texture; /**< Texture to overlay on the sprite. */
 		Color color; /**< Color tint to apply to the sprite. */
 		Color color; /**< Color tint to apply to the sprite. */

+ 45 - 0
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -197,6 +197,7 @@ namespace BansheeEngine
 
 
 		initSpriteTextShader();
 		initSpriteTextShader();
 		initSpriteImageShader();
 		initSpriteImageShader();
+		initSpriteNonAlphaImageShader();
 		initDummyShader();
 		initDummyShader();
 
 
 		mWhiteSpriteTexture = getSkinTexture(WhiteTex);
 		mWhiteSpriteTexture = getSkinTexture(WhiteTex);
@@ -882,6 +883,36 @@ namespace BansheeEngine
 		newPass->setDepthStencilState(depthState);
 		newPass->setDepthStencilState(depthState);
 	}
 	}
 
 
+	void BuiltinResources::initSpriteNonAlphaImageShader()
+	{
+		HGpuProgram vsProgram = getGpuProgram(ShaderSpriteImageVSFile);
+		HGpuProgram psProgram = getGpuProgram(ShaderSpriteImagePSFile);
+
+		mShaderSpriteNonAlphaImage = Shader::create("NonAlphaImageSpriteShader");
+
+		mShaderSpriteNonAlphaImage->addParameter("worldTransform", "worldTransform", GPDT_MATRIX_4X4);
+		mShaderSpriteNonAlphaImage->addParameter("invViewportWidth", "invViewportWidth", GPDT_FLOAT1);
+		mShaderSpriteNonAlphaImage->addParameter("invViewportHeight", "invViewportHeight", GPDT_FLOAT1);
+
+		mShaderSpriteNonAlphaImage->addParameter("mainTexSamp", "mainTexSamp", GPOT_SAMPLER2D);
+		mShaderSpriteNonAlphaImage->addParameter("mainTexSamp", "mainTexture", GPOT_SAMPLER2D);
+
+		mShaderSpriteNonAlphaImage->addParameter("mainTexture", "mainTexture", GPOT_TEXTURE2D);
+		mShaderSpriteNonAlphaImage->addParameter("tint", "tint", GPDT_FLOAT4);
+
+		TechniquePtr newTechnique = mShaderSpriteNonAlphaImage->addTechnique(mActiveRenderSystem, RendererInvariant);
+		PassPtr newPass = newTechnique->addPass();
+		newPass->setVertexProgram(vsProgram);
+		newPass->setFragmentProgram(psProgram);
+
+		DEPTH_STENCIL_STATE_DESC depthStateDesc;
+		depthStateDesc.depthReadEnable = false;
+		depthStateDesc.depthWriteEnable = false;
+
+		HDepthStencilState depthState = DepthStencilState::create(depthStateDesc);
+		newPass->setDepthStencilState(depthState);
+	}
+
 	void BuiltinResources::initDummyShader()
 	void BuiltinResources::initDummyShader()
 	{
 	{
 		HGpuProgram vsProgram = getGpuProgram(ShaderDummyVSFile);
 		HGpuProgram vsProgram = getGpuProgram(ShaderDummyVSFile);
@@ -985,6 +1016,20 @@ namespace BansheeEngine
 		return info;
 		return info;
 	}
 	}
 
 
+	GUIMaterialInfo BuiltinResources::createSpriteNonAlphaImageMaterial() const
+	{
+		GUIMaterialInfo info;
+		info.material = Material::create(mShaderSpriteNonAlphaImage);
+		info.invViewportWidth = info.material->getParamFloat("invViewportWidth");
+		info.invViewportHeight = info.material->getParamFloat("invViewportHeight");
+		info.worldTransform = info.material->getParamMat4("worldTransform");
+		info.mainTexture = info.material->getParamTexture("mainTexture");
+		info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
+		info.tint = info.material->getParamVec4("tint");
+
+		return info;
+	}
+
 	HMaterial BuiltinResources::createDummyMaterial() const
 	HMaterial BuiltinResources::createDummyMaterial() const
 	{
 	{
 		return Material::create(mShaderDummy);
 		return Material::create(mShaderDummy);

+ 37 - 0
BansheeEngine/Source/BsGUIMaterialManager.cpp

@@ -58,6 +58,27 @@ namespace BansheeEngine
 		return guiMat.handle;
 		return guiMat.handle;
 	}
 	}
 
 
+	const GUIMaterialInfo& GUIMaterialManager::requestNonAlphaImageMaterial(const HTexture& texture, const Color& tint) const
+	{
+		Vector4 vecColor(tint.r, tint.g, tint.b, tint.a);
+
+		const GUIMaterialInfo* matInfo = findExistingNonAlphaImageMaterial(texture, tint);
+		if (matInfo != nullptr)
+			return *matInfo;
+
+		mNonAlphaImageMaterials.push_back(GUIMaterial());
+
+		GUIMaterial& guiMat = mNonAlphaImageMaterials[mNonAlphaImageMaterials.size() - 1];
+		guiMat.handle = BuiltinResources::instance().createSpriteNonAlphaImageMaterial();
+
+		guiMat.handle.mainTexSampler.set(mGUISamplerState);
+		guiMat.handle.mainTexture.set(texture);
+		guiMat.handle.tint.set(vecColor);
+		guiMat.refCount = 1;
+
+		return guiMat.handle;
+	}
+
 	const GUIMaterialInfo* GUIMaterialManager::findExistingTextMaterial(const HTexture& texture, const Color& tint) const
 	const GUIMaterialInfo* GUIMaterialManager::findExistingTextMaterial(const HTexture& texture, const Color& tint) const
 	{
 	{
 		Vector4 vecColor(tint.r, tint.g, tint.b, tint.a);
 		Vector4 vecColor(tint.r, tint.g, tint.b, tint.a);
@@ -90,6 +111,22 @@ namespace BansheeEngine
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
+	const GUIMaterialInfo* GUIMaterialManager::findExistingNonAlphaImageMaterial(const HTexture& texture, const Color& tint) const
+	{
+		Vector4 vecColor(tint.r, tint.g, tint.b, tint.a);
+
+		for (auto& matHandle : mNonAlphaImageMaterials)
+		{
+			if (matHandle.handle.mainTexture.get() == texture && matHandle.handle.tint.get() == vecColor)
+			{
+				matHandle.refCount++;
+				return &matHandle.handle;
+			}
+		}
+
+		return nullptr;
+	}
+
 	void GUIMaterialManager::releaseMaterial(const GUIMaterialInfo& material) const
 	void GUIMaterialManager::releaseMaterial(const GUIMaterialInfo& material) const
 	{
 	{
 		bool released = false;
 		bool released = false;

+ 2 - 1
BansheeEngine/Source/BsGUIRenderTexture.cpp

@@ -14,7 +14,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	GUIRenderTexture::GUIRenderTexture(const String& styleName, const RenderTexturePtr& texture, const GUILayoutOptions& layoutOptions)
 	GUIRenderTexture::GUIRenderTexture(const String& styleName, const RenderTexturePtr& texture, const GUILayoutOptions& layoutOptions)
-		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::StretchToFit, layoutOptions)
+		:GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::StretchToFit, false, layoutOptions)
 	{
 	{
 		setRenderTexture(texture);
 		setRenderTexture(texture);
 	}
 	}
@@ -71,6 +71,7 @@ namespace BansheeEngine
 
 
 		mDesc.width = mWidth;
 		mDesc.width = mWidth;
 		mDesc.height = mHeight;
 		mDesc.height = mHeight;
+		mDesc.transparent = false;
 
 
 		mImageSprite->update(mDesc);
 		mImageSprite->update(mDesc);
 
 

+ 26 - 10
BansheeEngine/Source/BsGUITexture.cpp

@@ -15,8 +15,9 @@ namespace BansheeEngine
 	}
 	}
 
 
 	GUITexture::GUITexture(const String& styleName, const HSpriteTexture& texture, 
 	GUITexture::GUITexture(const String& styleName, const HSpriteTexture& texture, 
-		GUIImageScaleMode scale, const GUILayoutOptions& layoutOptions)
-		:GUIElement(styleName, layoutOptions), mScaleMode(scale), mUsingStyleTexture(false)
+		GUIImageScaleMode scale, bool transparent, const GUILayoutOptions& layoutOptions)
+		:GUIElement(styleName, layoutOptions), mScaleMode(scale), mUsingStyleTexture(false),
+		mTransparent(transparent)
 	{
 	{
 		mImageSprite = bs_new<ImageSprite, PoolAlloc>();
 		mImageSprite = bs_new<ImageSprite, PoolAlloc>();
 
 
@@ -34,55 +35,69 @@ namespace BansheeEngine
 		bs_delete<PoolAlloc>(mImageSprite);
 		bs_delete<PoolAlloc>(mImageSprite);
 	}
 	}
 
 
+	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, bool transparent,
+		const GUIOptions& layoutOptions, const String& styleName)
+	{
+		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName),
+			texture, scale, transparent, GUILayoutOptions::create(layoutOptions));
+	}
+
+	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, bool transparent,
+		const String& styleName)
+	{
+		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName),
+			texture, scale, transparent, GUILayoutOptions::create());
+	}
+
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 		const GUIOptions& layoutOptions, const String& styleName)
 		const GUIOptions& layoutOptions, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			texture, scale, GUILayoutOptions::create(layoutOptions));
+			texture, scale, true, GUILayoutOptions::create(layoutOptions));
 	}
 	}
 
 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, GUIImageScaleMode scale, 
 		const String& styleName)
 		const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			texture, scale, GUILayoutOptions::create());
+			texture, scale, true, GUILayoutOptions::create());
 	}
 	}
 
 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, 
 		const GUIOptions& layoutOptions, const String& styleName)
 		const GUIOptions& layoutOptions, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			texture, GUIImageScaleMode::StretchToFit, GUILayoutOptions::create(layoutOptions));
+			texture, GUIImageScaleMode::StretchToFit, true, GUILayoutOptions::create(layoutOptions));
 	}
 	}
 
 
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, const String& styleName)
 	GUITexture* GUITexture::create(const HSpriteTexture& texture, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName),
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName),
-			texture, GUIImageScaleMode::StretchToFit, GUILayoutOptions::create());
+			texture, GUIImageScaleMode::StretchToFit, true, GUILayoutOptions::create());
 	}
 	}
 
 
 	GUITexture* GUITexture::create(GUIImageScaleMode scale, const GUIOptions& layoutOptions, const String& styleName)
 	GUITexture* GUITexture::create(GUIImageScaleMode scale, const GUIOptions& layoutOptions, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			HSpriteTexture(), scale, GUILayoutOptions::create(layoutOptions));
+			HSpriteTexture(), scale, true, GUILayoutOptions::create(layoutOptions));
 	}
 	}
 
 
 	GUITexture* GUITexture::create(GUIImageScaleMode scale, const String& styleName)
 	GUITexture* GUITexture::create(GUIImageScaleMode scale, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			HSpriteTexture(), scale, GUILayoutOptions::create());
+			HSpriteTexture(), scale, true, GUILayoutOptions::create());
 	}
 	}
 
 
 	GUITexture* GUITexture::create(const GUIOptions& layoutOptions, const String& styleName)
 	GUITexture* GUITexture::create(const GUIOptions& layoutOptions, const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			HSpriteTexture(), GUIImageScaleMode::StretchToFit, GUILayoutOptions::create(layoutOptions));
+			HSpriteTexture(), GUIImageScaleMode::StretchToFit, true, GUILayoutOptions::create(layoutOptions));
 	}
 	}
 
 
 	GUITexture* GUITexture::create(const String& styleName)
 	GUITexture* GUITexture::create(const String& styleName)
 	{
 	{
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
 		return new (bs_alloc<GUITexture, PoolAlloc>()) GUITexture(getStyleName<GUITexture>(styleName), 
-			HSpriteTexture(), GUIImageScaleMode::StretchToFit, GUILayoutOptions::create());
+			HSpriteTexture(), GUIImageScaleMode::StretchToFit, true, GUILayoutOptions::create());
 	}
 	}
 
 
 	void GUITexture::setTexture(const HSpriteTexture& texture)
 	void GUITexture::setTexture(const HSpriteTexture& texture)
@@ -117,6 +132,7 @@ namespace BansheeEngine
 		mDesc.borderRight = _getStyle()->border.right;
 		mDesc.borderRight = _getStyle()->border.right;
 		mDesc.borderTop = _getStyle()->border.top;
 		mDesc.borderTop = _getStyle()->border.top;
 		mDesc.borderBottom = _getStyle()->border.bottom;
 		mDesc.borderBottom = _getStyle()->border.bottom;
+		mDesc.transparent = mTransparent;
 
 
 		if(mUsingStyleTexture)
 		if(mUsingStyleTexture)
 			mActiveTexture = _getStyle()->normal.texture;
 			mActiveTexture = _getStyle()->normal.texture;

+ 14 - 3
BansheeEngine/Source/BsImageSprite.cpp

@@ -61,7 +61,13 @@ namespace BansheeEngine
 				getNewMaterial = true;
 				getNewMaterial = true;
 			else
 			else
 			{
 			{
-				const GUIMaterialInfo* matInfo = GUIMaterialManager::instance().findExistingImageMaterial(tex, desc.color);
+				const GUIMaterialInfo* matInfo = nullptr;
+				
+				if (desc.transparent)
+					matInfo = GUIMaterialManager::instance().findExistingImageMaterial(tex, desc.color);
+				else
+					matInfo = GUIMaterialManager::instance().findExistingNonAlphaImageMaterial(tex, desc.color);
+
 				if(matInfo == nullptr)
 				if(matInfo == nullptr)
 				{
 				{
 					getNewMaterial = true;
 					getNewMaterial = true;
@@ -76,8 +82,13 @@ namespace BansheeEngine
 				}
 				}
 			}
 			}
 
 
-			if(getNewMaterial)
-				renderElem.matInfo = GUIMaterialManager::instance().requestImageMaterial(tex, desc.color);
+			if (getNewMaterial)
+			{
+				if (desc.transparent)
+					renderElem.matInfo = GUIMaterialManager::instance().requestImageMaterial(tex, desc.color);
+				else
+					renderElem.matInfo = GUIMaterialManager::instance().requestNonAlphaImageMaterial(tex, desc.color);
+			}
 
 
 			texPage++;
 			texPage++;
 		}
 		}

+ 25 - 5
MBansheeEngine/GUI/GUITexture.cs

@@ -13,24 +13,44 @@ namespace BansheeEngine
 
 
     public sealed class GUITexture : GUIElement
     public sealed class GUITexture : GUIElement
     {
     {
+        public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, bool transparent, string style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, scale, transparent, style, options);
+        }
+
+        public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, bool transparent, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, scale, transparent, "", options);
+        }
+
+        public GUITexture(SpriteTexture texture, bool transparent, string style, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, transparent, style, options);
+        }
+
+        public GUITexture(SpriteTexture texture, bool transparent, params GUIOption[] options)
+        {
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, transparent, "", options);
+        }
+
         public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, string style, params GUIOption[] options)
         public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, string style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, texture, scale, style, options);
+            Internal_CreateInstance(this, texture, scale, true, style, options);
         }
         }
 
 
         public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
         public GUITexture(SpriteTexture texture, GUIImageScaleMode scale, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, texture, scale, "", options);
+            Internal_CreateInstance(this, texture, scale, true, "", options);
         }
         }
 
 
         public GUITexture(SpriteTexture texture, string style, params GUIOption[] options)
         public GUITexture(SpriteTexture texture, string style, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, style, options);
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, true, style, options);
         }
         }
 
 
         public GUITexture(SpriteTexture texture, params GUIOption[] options)
         public GUITexture(SpriteTexture texture, params GUIOption[] options)
         {
         {
-            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, "", options);
+            Internal_CreateInstance(this, texture, GUIImageScaleMode.StretchToFit, true, "", options);
         }
         }
 
 
         public void SetTexture(SpriteTexture texture)
         public void SetTexture(SpriteTexture texture)
@@ -40,7 +60,7 @@ namespace BansheeEngine
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
         private static extern void Internal_CreateInstance(GUITexture instance, SpriteTexture texture,
-            GUIImageScaleMode scale, string style, GUIOption[] options);
+            GUIImageScaleMode scale, bool transparent, string style, GUIOption[] options);
 
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetTexture(IntPtr nativeInstance, SpriteTexture texture);
         private static extern void Internal_SetTexture(IntPtr nativeInstance, SpriteTexture texture);

+ 1 - 1
SBansheeEngine/Include/BsScriptGUITexture.h

@@ -13,7 +13,7 @@ namespace BansheeEngine
 
 
 	private:
 	private:
 		static void internal_createInstance(MonoObject* instance, MonoObject* texture, 
 		static void internal_createInstance(MonoObject* instance, MonoObject* texture, 
-			GUIImageScaleMode scale, MonoString* style, MonoArray* guiOptions);
+			GUIImageScaleMode scale, bool transparent, MonoString* style, MonoArray* guiOptions);
 		static void internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture);
 		static void internal_setTexture(ScriptGUITexture* nativeInstance, MonoObject* texture);
 
 
 		ScriptGUITexture(MonoObject* instance, GUITexture* texture);
 		ScriptGUITexture(MonoObject* instance, GUITexture* texture);

+ 2 - 2
SBansheeEngine/Source/BsScriptGUITexture.cpp

@@ -30,7 +30,7 @@ namespace BansheeEngine
 	}
 	}
 
 
 	void ScriptGUITexture::internal_createInstance(MonoObject* instance, MonoObject* texture, 
 	void ScriptGUITexture::internal_createInstance(MonoObject* instance, MonoObject* texture, 
-		GUIImageScaleMode scale, MonoString* style, MonoArray* guiOptions)
+		GUIImageScaleMode scale, bool transparent, MonoString* style, MonoArray* guiOptions)
 	{
 	{
 		GUIOptions options;
 		GUIOptions options;
 
 
@@ -42,7 +42,7 @@ namespace BansheeEngine
 		if(texture != nullptr)
 		if(texture != nullptr)
 			nativeTexture = ScriptSpriteTexture::toNative(texture)->getInternalValue();
 			nativeTexture = ScriptSpriteTexture::toNative(texture)->getInternalValue();
 
 
-		GUITexture* guiTexture = GUITexture::create(nativeTexture, scale, options, toString(MonoUtil::monoToWString(style)));
+		GUITexture* guiTexture = GUITexture::create(nativeTexture, scale, transparent, options, toString(MonoUtil::monoToWString(style)));
 
 
 		ScriptGUITexture* nativeInstance = new (bs_alloc<ScriptGUITexture>()) ScriptGUITexture(instance, guiTexture);
 		ScriptGUITexture* nativeInstance = new (bs_alloc<ScriptGUITexture>()) ScriptGUITexture(instance, guiTexture);
 	}
 	}

+ 0 - 1
SceneView.txt

@@ -7,7 +7,6 @@ Add a way to render GUI image without alpha
 Line slider collider intersection doesn't work properly
 Line slider collider intersection doesn't work properly
 Handles need to render in front of everything
 Handles need to render in front of everything
 Clicking on empty space needs to deselect everything
 Clicking on empty space needs to deselect everything
-D3D11HardwareBuffer::writeData provides incorrect parameters to UpdateSubresource() (length & offset)
 
 
 Test gizmos
 Test gizmos
  - HOOK UP GIZMO SELECTION and test it
  - HOOK UP GIZMO SELECTION and test it