Pārlūkot izejas kodu

Remove cCameraRot uniform. Instead derive from cViewInv as necessary. Closes #1163.

Lasse Öörni 9 gadi atpakaļ
vecāks
revīzija
ed8740428c

+ 2 - 1
Docs/Reference.dox

@@ -1343,13 +1343,14 @@ Vertex shader uniforms:
 - float3 cAmbientStartColor: the start color value for a zone's ambient gradient
 - float3 cAmbientEndColor: the end color value for a zone's ambient gradient
 - float3 cCameraPos: camera's world position
-- float3x3 cCameraRot: camera's world rotation matrix
 - float cNearClip: camera's near clip distance
 - float cFarClip: camera's far clip distance
 - float cDeltaTime: the timestep of the current frame
 - float4 cDepthMode: parameters for calculating a linear depth value between 0-1 to pass to the pixel shader in an interpolator.
 - float cElapsedTime: scene's elapsed time value. Can be used to implement animating materials
 - float4x3 cModel: the world transform matrix of the object being rendered
+- float4x3 cView: the camera's view matrix
+- float4x3 cViewInv: the inverse of the camera's view matrix (camera world transform)
 - float4x4 cViewProj: the camera's concatenated view and projection matrices
 - float4x3 cZone: zone's transform matrix; used for ambient gradient calculations
 

+ 0 - 1
Source/Urho3D/Graphics/GraphicsDefs.cpp

@@ -37,7 +37,6 @@ extern URHO3D_API const StringHash VSP_AMBIENTSTARTCOLOR("AmbientStartColor");
 extern URHO3D_API const StringHash VSP_AMBIENTENDCOLOR("AmbientEndColor");
 extern URHO3D_API const StringHash VSP_BILLBOARDROT("BillboardRot");
 extern URHO3D_API const StringHash VSP_CAMERAPOS("CameraPos");
-extern URHO3D_API const StringHash VSP_CAMERAROT("CameraRot");
 extern URHO3D_API const StringHash VSP_CLIPPLANE("ClipPlane");
 extern URHO3D_API const StringHash VSP_NEARCLIP("NearClip");
 extern URHO3D_API const StringHash VSP_FARCLIP("FarClip");

+ 0 - 1
Source/Urho3D/Graphics/GraphicsDefs.h

@@ -369,7 +369,6 @@ extern URHO3D_API const StringHash VSP_AMBIENTSTARTCOLOR;
 extern URHO3D_API const StringHash VSP_AMBIENTENDCOLOR;
 extern URHO3D_API const StringHash VSP_BILLBOARDROT;
 extern URHO3D_API const StringHash VSP_CAMERAPOS;
-extern URHO3D_API const StringHash VSP_CAMERAROT;
 extern URHO3D_API const StringHash VSP_CLIPPLANE;
 extern URHO3D_API const StringHash VSP_NEARCLIP;
 extern URHO3D_API const StringHash VSP_FARCLIP;

+ 2 - 3
Source/Urho3D/Graphics/View.cpp

@@ -714,7 +714,8 @@ void View::SetCameraShaderParameters(Camera* camera, bool setProjection)
     Matrix3x4 cameraEffectiveTransform = camera->GetEffectiveWorldTransform();
 
     graphics_->SetShaderParameter(VSP_CAMERAPOS, cameraEffectiveTransform.Translation());
-    graphics_->SetShaderParameter(VSP_CAMERAROT, cameraEffectiveTransform.RotationMatrix());
+    graphics_->SetShaderParameter(VSP_VIEWINV, cameraEffectiveTransform);
+    graphics_->SetShaderParameter(VSP_VIEW, camera->GetView());
     graphics_->SetShaderParameter(PSP_CAMERAPOS, cameraEffectiveTransform.Translation());
 
     float nearClip = camera->GetNearClip();
@@ -759,8 +760,6 @@ void View::SetCameraShaderParameters(Camera* camera, bool setProjection)
         projection.m23_ += projection.m33_ * constantBias;
 #endif
 
-        graphics_->SetShaderParameter(VSP_VIEWINV, camera->GetEffectiveWorldTransform());
-        graphics_->SetShaderParameter(VSP_VIEW, camera->GetView());
         graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * camera->GetView());
     }
 }

+ 10 - 3
bin/CoreData/Shaders/GLSL/ScreenPos.glsl

@@ -1,4 +1,11 @@
 #ifdef COMPILEVS
+mat3 GetCameraRot()
+{
+    return mat3(cViewInv[0][0], cViewInv[0][1], cViewInv[0][2],
+        cViewInv[1][0], cViewInv[1][1], cViewInv[1][2],
+        cViewInv[2][0], cViewInv[2][1], cViewInv[2][2]);
+}
+
 vec4 GetScreenPos(vec4 clipPos)
 {
     return vec4(
@@ -36,7 +43,7 @@ vec3 GetFarRay(vec4 clipPos)
         clipPos.y / clipPos.w * cFrustumSize.y,
         cFrustumSize.z);
 
-    return viewRay * cCameraRot;
+    return viewRay * GetCameraRot();
 }
 
 vec3 GetNearRay(vec4 clipPos)
@@ -45,7 +52,7 @@ vec3 GetNearRay(vec4 clipPos)
         clipPos.x / clipPos.w * cFrustumSize.x,
         clipPos.y / clipPos.w * cFrustumSize.y,
         0.0);
-    
-    return (viewRay * cCameraRot) * cDepthMode.x;
+
+    return (viewRay * GetCameraRot()) * cDepthMode.x;
 }
 #endif

+ 0 - 2
bin/CoreData/Shaders/GLSL/Uniforms.glsl

@@ -12,7 +12,6 @@ uniform vec3 cAmbientStartColor;
 uniform vec3 cAmbientEndColor;
 uniform mat3 cBillboardRot;
 uniform vec3 cCameraPos;
-uniform mat3 cCameraRot;
 uniform float cNearClip;
 uniform float cFarClip;
 uniform vec4 cDepthMode;
@@ -99,7 +98,6 @@ uniform FrameVS
 uniform CameraVS
 {
     vec3 cCameraPos;
-    mat3 cCameraRot;
     float cNearClip;
     float cFarClip;
     vec4 cDepthMode;

+ 9 - 2
bin/CoreData/Shaders/HLSL/ScreenPos.hlsl

@@ -1,4 +1,11 @@
 #ifdef COMPILEVS
+float3x3 GetCameraRot()
+{
+    return float3x3(cViewInv[0][0], cViewInv[0][1], cViewInv[0][2],
+        cViewInv[1][0], cViewInv[1][1], cViewInv[1][2],
+        cViewInv[2][0], cViewInv[2][1], cViewInv[2][2]);
+}
+
 float4 GetScreenPos(float4 clipPos)
 {
     return float4(
@@ -36,7 +43,7 @@ float3 GetFarRay(float4 clipPos)
         clipPos.y / clipPos.w * cFrustumSize.y,
         cFrustumSize.z);
 
-    return mul(viewRay, cCameraRot);
+    return mul(viewRay, GetCameraRot());
 }
 
 float3 GetNearRay(float4 clipPos)
@@ -46,6 +53,6 @@ float3 GetNearRay(float4 clipPos)
         clipPos.y / clipPos.w * cFrustumSize.y,
         0.0);
 
-    return mul(viewRay, cCameraRot) * cDepthMode.z;
+    return mul(viewRay, GetCameraRot()) * cDepthMode.z;
 }
 #endif

+ 0 - 2
bin/CoreData/Shaders/HLSL/Uniforms.hlsl

@@ -11,7 +11,6 @@ uniform float3 cAmbientEndColor;
 uniform float3x3 cBillboardRot;
 #endif
 uniform float3 cCameraPos;
-uniform float3x3 cCameraRot;
 uniform float cNearClip;
 uniform float cFarClip;
 uniform float4 cDepthMode;
@@ -89,7 +88,6 @@ cbuffer FrameVS : register(b0)
 cbuffer CameraVS : register(b1)
 {
     float3 cCameraPos;
-    float3x3 cCameraRot;
     float cNearClip;
     float cFarClip;
     float4 cDepthMode;