浏览代码

Fixing directional light rendering for OpenGL

BearishSun 9 年之前
父节点
当前提交
f1ad138e54
共有 3 个文件被更改,包括 23 次插入14 次删除
  1. 6 6
      BansheeEngine/Include/BsCamera.h
  2. 9 0
      BansheeEngine/Source/BsRendererUtility.cpp
  3. 8 8
      MBansheeEngine/Camera.cs

+ 6 - 6
BansheeEngine/Include/BsCamera.h

@@ -305,7 +305,7 @@ namespace BansheeEngine
 		 */
 		Vector2I worldToScreenPoint(const Vector3& worldPoint) const;
 
-		/**	Converts a point in world space to normalized device coordinates (in [0, 1] range). */
+		/**	Converts a point in world space to normalized device coordinates (in [-1, 1] range). */
 		Vector2 worldToNdcPoint(const Vector3& worldPoint) const;
 
 		/** Converts a point in world space to point relative to camera's coordinate system (view space). */
@@ -333,7 +333,7 @@ namespace BansheeEngine
 
 		/**
 		 * Converts a point in screen space (pixels corresponding to render target attached to the camera) to normalized 
-		 * device coordinates (in [0, 1] range).
+		 * device coordinates (in [-1, 1] range).
 		 */
 		Vector2 screenToNdcPoint(const Vector2I& screenPoint) const;
 
@@ -348,12 +348,12 @@ namespace BansheeEngine
 
 		/**
 		 * Converts a point relative to camera's coordinate system (view space) into normalized device coordinates 
-		 * (in [0, 1] range).
+		 * (in [-1, 1] range).
 		 */
 		Vector2 viewToNdcPoint(const Vector3& viewPoint) const;
 
 		/**
-		 * Converts a point in normalized device coordinates ([0, 1] range) to a point in world space.
+		 * Converts a point in normalized device coordinates ([-1, 1] range) to a point in world space.
 		 *
 		 * @param[in]	ndcPoint	Point to transform.
 		 * @param[in]	depth		Depth to place the world point at. The depth is applied to the vector going from camera
@@ -362,7 +362,7 @@ namespace BansheeEngine
 		Vector3 ndcToWorldPoint(const Vector2& ndcPoint, float depth = 0.5f) const;
 
 		/**
-		 * Converts a point in normalized device coordinates ([0, 1] range) to a point relative to camera's coordinate system
+		 * Converts a point in normalized device coordinates ([-1, 1] range) to a point relative to camera's coordinate system
 		 * (view space).
 		 *
 		 * @param[in]	ndcPoint	Point to transform.
@@ -372,7 +372,7 @@ namespace BansheeEngine
 		Vector3 ndcToViewPoint(const Vector2& ndcPoint, float depth = 0.5f) const;
 
 		/**
-		 * Converts a point in normalized device coordinates ([0, 1] range) to a point in screen space (pixels corresponding
+		 * Converts a point in normalized device coordinates ([-1, 1] range) to a point in screen space (pixels corresponding
 		 * to render target attached to the camera).
 		 */
 		Vector2I ndcToScreenPoint(const Vector2& ndcPoint) const;

+ 9 - 0
BansheeEngine/Source/BsRendererUtility.cpp

@@ -335,6 +335,7 @@ namespace BansheeEngine
 	void RendererUtility::drawScreenQuad(const Rect2& uv, const Vector2I& textureSize)
 	{
 		// 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);
@@ -342,11 +343,19 @@ namespace BansheeEngine
 		vertices[3] = Vector3(1.0f, -1.0f, 0.0f);
 
 		Vector2 uvs[4];
+
+		// DX 11
 		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);
 
+		// OpenGL
+		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);
+
 		for (int i = 0; i < 4; i++)
 		{
 			uvs[i].x /= (float)textureSize.x;

+ 8 - 8
MBansheeEngine/Camera.cs

@@ -245,7 +245,7 @@ namespace BansheeEngine
         /// Converts a point in world space to normalized device coordinates.
         /// </summary>
         /// <param name="value">3D point in world space.</param>
-        /// <returns>2D point in normalized device coordinates ([0, 1] range), relative to the camera's viewport.</returns>
+        /// <returns>2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.</returns>
         public Vector2 WorldToNDC(Vector3 value) { return native.WorldToNDC(value); }
 
         /// <summary>
@@ -277,7 +277,7 @@ namespace BansheeEngine
         /// Converts a point in screen space to a point in normalized device coordinates.
         /// </summary>
         /// <param name="value">2D point on the render target attached to the camera, in pixels.</param>
-        /// <returns>2D point in normalized device coordinates ([0, 1] range), relative to the camera's viewport.</returns>
+        /// <returns>2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.</returns>
         public Vector2 ScreenToNDC(Vector2I value) { return native.ScreenToNDC(value); }
 
         /// <summary>
@@ -298,11 +298,11 @@ namespace BansheeEngine
         /// Converts a point relative to camera's coordinate system (view space) to normalized device coordinates.
         /// </summary>
         /// <param name="value">3D point in view space.</param>
-        /// <returns>2D point in normalized device coordinates ([0, 1] range), relative to the camera's viewport.</returns>
+        /// <returns>2D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport.</returns>
         public Vector2 ViewToNDC(Vector3 value) { return native.ViewToNDC(value); }
 
         /// <summary>
-        /// Converts a point relative to camera's viewport in normalized device coordinates ([0, 1] range) into a point in 
+        /// Converts a point relative to camera's viewport in normalized device coordinates ([-1, 1] range) into a point in 
         /// world space.
         /// </summary>
         /// <param name="value">2D point in normalized device coordinates.</param>
@@ -312,7 +312,7 @@ namespace BansheeEngine
         public Vector3 NDCToWorld(Vector2 value, float depth = 0.5f) { return native.NDCToWorld(value, depth); }
 
         /// <summary>
-        /// Converts a point relative to camera's viewport in normalized device coordinates ([0, 1] range) into a point in 
+        /// Converts a point relative to camera's viewport in normalized device coordinates ([-1, 1] range) into a point in 
         /// view space.
         /// </summary>
         /// <param name="value">2D point in normalized device coordinates.</param>
@@ -322,7 +322,7 @@ namespace BansheeEngine
         public Vector3 NDCToView(Vector2 value, float depth = 0.5f) { return native.NDCToView(value, depth); }
 
         /// <summary>
-        /// Converts a point relative to camera's viewport in normalized device coordinates ([0, 1] range) to screen space.
+        /// Converts a point relative to camera's viewport in normalized device coordinates ([-1, 1] range) to screen space.
         /// </summary>
         /// <param name="value">2D point in normalized device coordinates.</param>
         /// <returns>2D point on the render target attached to the camera, in pixels.</returns>
@@ -341,14 +341,14 @@ namespace BansheeEngine
         /// but preserves the depth component.
         /// </summary>
         /// <param name="value">3D point in view space.</param>
-        /// <returns>3D point in normalized device coordinates ([0, 1] range), relative to the camera's viewport. Z value
+        /// <returns>3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. Z value
         ///          range depends on active render API.</returns>
         public Vector3 ProjectPoint(Vector3 value) { return native.ProjectPoint(value); }
 
         /// <summary>
         /// Un-rpojects a point in normalized device coordinates to a point in view space.
         /// </summary>
-        /// <param name="value">3D point in normalized device coordinates ([0, 1] range), relative to the camera's viewport. 
+        /// <param name="value">3D point in normalized device coordinates ([-1, 1] range), relative to the camera's viewport. 
         ///                     Z value range depends on active render API.</param>
         /// <returns>3D point in view space.</returns>
         public Vector3 UnprojectPoint(Vector3 value) { return native.UnprojectPoint(value); }