BearishSun 9 лет назад
Родитель
Сommit
3d48e47f9a

+ 5 - 2
Data/Raw/Engine/Includes/SpriteImage.bslinc

@@ -3,6 +3,7 @@ Parameters =
 	mat4x4 	gWorldTransform;
 	float	gInvViewportWidth;
 	float	gInvViewportHeight;
+	float	gViewportYFlip;
 	color	gTint;
 	
 	Sampler2D	gMainTexSamp : alias("gMainTexture");
@@ -30,6 +31,7 @@ Technique : base("SpriteImage") =
 				float4x4 gWorldTransform;
 				float gInvViewportWidth;
 				float gInvViewportHeight;
+				float gViewportYFlip;
 				float4 gTint;
 			}	
 		};
@@ -45,7 +47,7 @@ Technique : base("SpriteImage") =
 				float4 tfrmdPos = mul(gWorldTransform, float4(inPos.xy, 0, 1));
 
 				float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
-				float tfrmdY = 1.0f - (tfrmdPos.y * gInvViewportHeight);
+				float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
 
 				oPosition = float4(tfrmdX, tfrmdY, 0, 1);
 				oUv = uv;
@@ -82,6 +84,7 @@ Technique : base("SpriteImage") =
 				mat4 gWorldTransform;
 				float gInvViewportWidth;
 				float gInvViewportHeight;
+				float gViewportYFlip;
 				vec4 gTint;
 			};			
 		};		
@@ -103,7 +106,7 @@ Technique : base("SpriteImage") =
 				vec4 tfrmdPos = gWorldTransform * vec4(bs_position.xy, 0, 1);
 
 				float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
-				float tfrmdY = 1.0f - (tfrmdPos.y * gInvViewportHeight);	
+				float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;	
 
 				gl_Position = vec4(tfrmdX, tfrmdY, 0, 1);
 				texcoord0 = bs_texcoord0;

+ 5 - 2
Data/Raw/Engine/Shaders/SpriteText.bsl

@@ -3,6 +3,7 @@ Parameters =
 	mat4x4 	gWorldTransform;
 	float	gInvViewportWidth;
 	float	gInvViewportHeight;
+	float	gViewportYFlip;
 	color	gTint;
 	
 	Sampler2D	gMainTexSamp : alias("gMainTexture");
@@ -37,6 +38,7 @@ Technique =
 				float4x4 gWorldTransform;
 				float gInvViewportWidth;
 				float gInvViewportHeight;
+				float gViewportYFlip;
 				float4 gTint;
 			}	
 		};
@@ -52,7 +54,7 @@ Technique =
 				float4 tfrmdPos = mul(gWorldTransform, float4(inPos.xy, 0, 1));
 
 				float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
-				float tfrmdY = 1.0f - (tfrmdPos.y * gInvViewportHeight);
+				float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
 
 				oPosition = float4(tfrmdX, tfrmdY, 0, 1);
 				oUv = uv;
@@ -96,6 +98,7 @@ Technique =
 				mat4 gWorldTransform;
 				float gInvViewportWidth;
 				float gInvViewportHeight;
+				float gViewportYFlip;
 				vec4 gTint;
 			};			
 		};			
@@ -117,7 +120,7 @@ Technique =
 				vec4 tfrmdPos = gWorldTransform * vec4(bs_position.xy, 0, 1);
 
 				float tfrmdX = -1.0f + (tfrmdPos.x * gInvViewportWidth);
-				float tfrmdY = 1.0f - (tfrmdPos.y * gInvViewportHeight);
+				float tfrmdY = (1.0f - (tfrmdPos.y * gInvViewportHeight)) * gViewportYFlip;
 
 				gl_Position = vec4(tfrmdX, tfrmdY, 0, 1);
 				texcoord0 = bs_texcoord0;

+ 13 - 6
Source/BansheeCore/Include/BsRenderAPI.h

@@ -171,11 +171,11 @@ namespace bs
 	{
 	public:
 		RenderAPIInfo(float horzTexelOffset, float vertTexelOffset, float minDepth, float maxDepth, 
-			VertexElementType vertexColorType, bool vertexColorFlip, bool ndcVerticalTopToBottom, bool columnMajorMatrices, 
-				bool multiThreadedCB)
+			VertexElementType vertexColorType, bool vertexColorFlip, bool uvYAxisUp, bool ndcYAxisDown, 
+				bool columnMajorMatrices, bool multiThreadedCB)
 			: mHorizontalTexelOffset(horzTexelOffset), mVerticalTexelOffset(vertTexelOffset), mMinDepth(minDepth)
 			, mMaxDepth(maxDepth), mVertexColorType(vertexColorType), mVertexColorFlip(vertexColorFlip)
-			, mNDCYAxisDown(ndcVerticalTopToBottom), mColumnMajorMatrices(columnMajorMatrices)
+			, mUVYAxisUp(uvYAxisUp), mNDCYAxisDown(ndcYAxisDown), mColumnMajorMatrices(columnMajorMatrices)
 			, mMultiThreadedCB(multiThreadedCB)
 		{
 			
@@ -203,8 +203,14 @@ namespace bs
 		bool getGpuProgramHasColumnMajorMatrices() const { return mColumnMajorMatrices; }
 		
 		/** 
-		 * Returns true if Y axis in normalized device coordinates points down, false if up. If axis is pointing down the
-		 * NDC at the top is -1, and at the bottom is 1, otherwise reverse.
+		 * Returns true if Y axis in texture (UV) coordinates is pointing up, false if down. If axis is pointing up the axis
+		 * value at the top if 1 and at the bottom 0, otherwise reverse. 
+		 */
+		bool getUVYAxisUp() const { return mUVYAxisUp; }
+
+		/**
+		 * Returns true if the Y axis in NDC coordinates is pointing down, false if up. If axis is pointing down the value
+		 * at the top will -1 and at the bottom 1, otherwise reverse.
 		 */
 		bool getNDCYAxisDown() const { return mNDCYAxisDown; }
 
@@ -221,7 +227,8 @@ namespace bs
 		float mMaxDepth = 1.0f;
 		VertexElementType mVertexColorType = VET_COLOR_ABGR;
 		bool mVertexColorFlip = false;
-		bool mNDCYAxisDown = true;
+		bool mUVYAxisUp = true;
+		bool mNDCYAxisDown = false;
 		bool mColumnMajorMatrices = false;
 		bool mMultiThreadedCB = false;
 	};

+ 1 - 1
Source/BansheeD3D11RenderAPI/Source/BsD3D11RenderAPI.cpp

@@ -1315,7 +1315,7 @@ namespace bs
 
 	const RenderAPIInfo& D3D11RenderAPI::getAPIInfo() const
 	{
-		static RenderAPIInfo info(0.0f, 0.0f, 0.0f, 1.0f, VET_COLOR_ABGR, false, true, false, false);
+		static RenderAPIInfo info(0.0f, 0.0f, 0.0f, 1.0f, VET_COLOR_ABGR, false, false, false, false, false);
 
 		return info;
 	}

+ 1 - 0
Source/BansheeEngine/Include/BsGUIManager.h

@@ -423,6 +423,7 @@ namespace bs
 		BS_PARAM_BLOCK_ENTRY(Matrix4, gWorldTransform)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportWidth)
 		BS_PARAM_BLOCK_ENTRY(float, gInvViewportHeight)
+		BS_PARAM_BLOCK_ENTRY(float, gViewportYFlip)
 		BS_PARAM_BLOCK_ENTRY(Color, gTint)
 	BS_PARAM_BLOCK_END
 

+ 2 - 0
Source/BansheeEngine/Source/BsGUIManager.cpp

@@ -1760,6 +1760,7 @@ namespace bs
 
 		float invViewportWidth = 1.0f / (camera.getViewport()->getWidth() * 0.5f);
 		float invViewportHeight = 1.0f / (camera.getViewport()->getHeight() * 0.5f);
+		float viewflipYFlip = RenderAPI::getAPIInfo().getNDCYAxisDown() ? -1.0f : 1.0f;
 
 		for (auto& entry : renderData)
 		{
@@ -1767,6 +1768,7 @@ namespace bs
 
 			gGUISpriteParamBlockDef.gInvViewportWidth.set(buffer, invViewportWidth);
 			gGUISpriteParamBlockDef.gInvViewportHeight.set(buffer, invViewportHeight);
+			gGUISpriteParamBlockDef.gViewportYFlip.set(buffer, viewflipYFlip);
 
 			buffer->flushToGPU();
 		}

+ 23 - 11
Source/BansheeEngine/Source/BsRendererUtility.cpp

@@ -268,28 +268,40 @@ namespace bs
 	{
 		// Note: Consider drawing the quad using a single large triangle for possibly better performance
 
-		Vector3 vertices[4];
-		vertices[0] = Vector3(-1.0f, 1.0f, 0.0f);
-		vertices[1] = Vector3(1.0f, 1.0f, 0.0f);
-		vertices[2] = Vector3(-1.0f, -1.0f, 0.0f);
-		vertices[3] = Vector3(1.0f, -1.0f, 0.0f);
+		const RenderAPIInfo& rapiInfo = RenderAPICore::instance().getAPIInfo();
 
-		Vector2 uvs[4];
+		Vector3 vertices[4];
 
-		if (RenderAPICore::instance().getAPIInfo().getNDCYAxisDown())
+		if(rapiInfo.getNDCYAxisDown())
 		{
-			uvs[0] = Vector2(uv.x, uv.y);
-			uvs[1] = Vector2(uv.x + uv.width, uv.y);
-			uvs[2] = Vector2(uv.x, uv.y + uv.height);
-			uvs[3] = Vector2(uv.x + uv.width, uv.y + uv.height);
+			vertices[0] = Vector3(-1.0f, -1.0f, 0.0f);
+			vertices[1] = Vector3(1.0f, -1.0f, 0.0f);
+			vertices[2] = Vector3(-1.0f, 1.0f, 0.0f);
+			vertices[3] = Vector3(1.0f, 1.0f, 0.0f);
 		}
 		else
+		{
+			vertices[0] = Vector3(-1.0f, 1.0f, 0.0f);
+			vertices[1] = Vector3(1.0f, 1.0f, 0.0f);
+			vertices[2] = Vector3(-1.0f, -1.0f, 0.0f);
+			vertices[3] = Vector3(1.0f, -1.0f, 0.0f);
+		}
+
+		Vector2 uvs[4];
+		if (rapiInfo.getUVYAxisUp())
 		{
 			uvs[0] = Vector2(uv.x, uv.y + uv.height);
 			uvs[1] = Vector2(uv.x + uv.width, uv.y + uv.height);
 			uvs[2] = Vector2(uv.x, uv.y);
 			uvs[3] = Vector2(uv.x + uv.width, uv.y);
 		}
+		else
+		{
+			uvs[0] = Vector2(uv.x, uv.y);
+			uvs[1] = Vector2(uv.x + uv.width, uv.y);
+			uvs[2] = Vector2(uv.x, uv.y + uv.height);
+			uvs[3] = Vector2(uv.x + uv.width, uv.y + uv.height);
+		}
 
 		for (int i = 0; i < 4; i++)
 		{

+ 1 - 1
Source/BansheeGLRenderAPI/Source/BsGLRenderAPI.cpp

@@ -2234,7 +2234,7 @@ namespace bs
 
 	const RenderAPIInfo& GLRenderAPI::getAPIInfo() const
 	{
-		static RenderAPIInfo info(0.0f, 0.0f, -1.0f, 1.0f, VET_COLOR_ABGR, false, false, true, false);
+		static RenderAPIInfo info(0.0f, 0.0f, -1.0f, 1.0f, VET_COLOR_ABGR, false, true, false, true, false);
 
 		return info;
 	}

+ 1 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanGpuPipelineState.cpp

@@ -171,7 +171,7 @@ namespace bs
 		mRasterizationInfo.rasterizerDiscardEnable = VK_FALSE;
 		mRasterizationInfo.polygonMode = VulkanUtility::getPolygonMode(rstProps.getPolygonMode());
 		mRasterizationInfo.cullMode = VulkanUtility::getCullMode(rstProps.getCullMode());
-		mRasterizationInfo.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
+		mRasterizationInfo.frontFace = VK_FRONT_FACE_CLOCKWISE;
 		mRasterizationInfo.depthBiasEnable = rstProps.getDepthBias() != 0.0f;
 		mRasterizationInfo.depthBiasConstantFactor = rstProps.getDepthBias();
 		mRasterizationInfo.depthBiasSlopeFactor = rstProps.getSlopeScaledDepthBias();

+ 1 - 1
Source/BansheeVulkanRenderAPI/Source/BsVulkanRenderAPI.cpp

@@ -548,7 +548,7 @@ namespace bs
 
 	const RenderAPIInfo& VulkanRenderAPI::getAPIInfo() const
 	{
-		static RenderAPIInfo info(0.0f, 0.0f, 0.0f, 1.0f, VET_COLOR_ABGR, false, false, true, true);
+		static RenderAPIInfo info(0.0f, 0.0f, 0.0f, 1.0f, VET_COLOR_ABGR, false, false, true, true, true);
 
 		return info;
 	}

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

@@ -235,7 +235,7 @@ namespace bs
 		clipToUVScaleOffset.z = viewport->getX() / rtWidth + (halfWidth + rapiInfo.getHorizontalTexelOffset()) / rtWidth;
 		clipToUVScaleOffset.w = viewport->getY() / rtHeight + (halfHeight + rapiInfo.getVerticalTexelOffset()) / rtHeight;
 
-		if (!rapiInfo.getNDCYAxisDown())
+		if (rapiInfo.getUVYAxisUp())
 			clipToUVScaleOffset.y = -clipToUVScaleOffset.y;
 
 		gPerCameraParamDef.gClipToUVScaleOffset.set(mParamBuffer, clipToUVScaleOffset);