Browse Source

Get rid of overrideView_ member in Batch, as it is no longer used by Skybox, and directional light quads can be made to work without it. Cleanup Light code.

Lasse Öörni 11 years ago
parent
commit
d023b06b3d

+ 2 - 2
Source/Urho3D/Graphics/Batch.cpp

@@ -215,9 +215,9 @@ void Batch::Prepare(View* view, bool setModelTransform, bool allowDepthWrite) co
         view->SetGlobalShaderParameters();
         view->SetGlobalShaderParameters();
     
     
     // Set camera shader parameters
     // Set camera shader parameters
-    unsigned cameraHash = overrideView_ ? (unsigned)(size_t)camera_ + 4 : (unsigned)(size_t)camera_;
+    unsigned cameraHash = (unsigned)(size_t)camera_;
     if (graphics->NeedParameterUpdate(SP_CAMERA, reinterpret_cast<void*>(cameraHash)))
     if (graphics->NeedParameterUpdate(SP_CAMERA, reinterpret_cast<void*>(cameraHash)))
-        view->SetCameraShaderParameters(camera_, true, overrideView_);
+        view->SetCameraShaderParameters(camera_, true);
     
     
     // Set viewport shader parameters
     // Set viewport shader parameters
     IntRect viewport = graphics->GetViewport();
     IntRect viewport = graphics->GetViewport();

+ 0 - 3
Source/Urho3D/Graphics/Batch.h

@@ -64,7 +64,6 @@ struct Batch
         numWorldTransforms_(rhs.numWorldTransforms_),
         numWorldTransforms_(rhs.numWorldTransforms_),
         lightQueue_(0),
         lightQueue_(0),
         geometryType_(rhs.geometryType_),
         geometryType_(rhs.geometryType_),
-        overrideView_(rhs.overrideView_),
         isBase_(false)
         isBase_(false)
     {
     {
     }
     }
@@ -102,8 +101,6 @@ struct Batch
     ShaderVariation* pixelShader_;
     ShaderVariation* pixelShader_;
     /// %Geometry type.
     /// %Geometry type.
     GeometryType geometryType_;
     GeometryType geometryType_;
-    /// Override view transform flag. When set, the camera's view transform is replaced with an identity matrix.
-    bool overrideView_;
     /// Base batch flag. This tells to draw the object fully without light optimizations.
     /// Base batch flag. This tells to draw the object fully without light optimizations.
     bool isBase_;
     bool isBase_;
     /// 8-bit light mask for stencil marking in deferred rendering.
     /// 8-bit light mask for stencil marking in deferred rendering.

+ 1 - 2
Source/Urho3D/Graphics/Drawable.cpp

@@ -45,8 +45,7 @@ SourceBatch::SourceBatch() :
     geometry_(0),
     geometry_(0),
     worldTransform_(&Matrix3x4::IDENTITY),
     worldTransform_(&Matrix3x4::IDENTITY),
     numWorldTransforms_(1),
     numWorldTransforms_(1),
-    geometryType_(GEOM_STATIC),
-    overrideView_(false)
+    geometryType_(GEOM_STATIC)
 {
 {
 }
 }
 
 

+ 0 - 2
Source/Urho3D/Graphics/Drawable.h

@@ -94,8 +94,6 @@ struct SourceBatch
     unsigned numWorldTransforms_;
     unsigned numWorldTransforms_;
     /// %Geometry type.
     /// %Geometry type.
     GeometryType geometryType_;
     GeometryType geometryType_;
-    /// Override view transform flag.
-    bool overrideView_;
 };
 };
 
 
 /// Base class for visible components.
 /// Base class for visible components.

+ 10 - 25
Source/Urho3D/Graphics/Light.cpp

@@ -409,29 +409,6 @@ int Light::GetNumShadowSplits() const
     return ret;
     return ret;
 }
 }
 
 
-Matrix3x4 Light::GetDirLightTransform(Camera* camera, bool getNearQuad)
-{
-    if (!camera)
-        return Matrix3x4::IDENTITY;
-
-    Vector3 nearVector, farVector;
-    camera->GetFrustumSize(nearVector, farVector);
-    float nearClip = camera->GetNearClip();
-    float farClip = camera->GetFarClip();
-
-    float distance = getNearQuad ? nearClip : farClip;
-    if (!camera->IsOrthographic())
-        farVector *= (distance / farClip);
-    else
-        farVector.z_ *= (distance / farClip);
-
-    // Set an epsilon from clip planes due to possible inaccuracy
-    /// \todo Rather set an identity projection matrix
-    farVector.z_ = Clamp(farVector.z_, (1.0f + M_LARGE_EPSILON) * nearClip, (1.0f - M_LARGE_EPSILON) * farClip);
-
-    return  Matrix3x4(Vector3(0.0f, 0.0f, farVector.z_), Quaternion::IDENTITY, Vector3(farVector.x_, farVector.y_, 1.0f));
-}
-
 const Matrix3x4& Light::GetVolumeTransform(Camera* camera)
 const Matrix3x4& Light::GetVolumeTransform(Camera* camera)
 {
 {
     if (!node_)
     if (!node_)
@@ -440,8 +417,16 @@ const Matrix3x4& Light::GetVolumeTransform(Camera* camera)
     switch (lightType_)
     switch (lightType_)
     {
     {
     case LIGHT_DIRECTIONAL:
     case LIGHT_DIRECTIONAL:
-        volumeTransform_ = GetDirLightTransform(camera);
-        break;
+        {
+            Matrix3x4 quadTransform;
+            Vector3 near, far;
+            // Position the directional light quad in halfway between far & near planes to prevent depth clipping
+            camera->GetFrustumSize(near, far);
+            quadTransform.SetTranslation(Vector3(0.0f, 0.0f, (camera->GetNearClip() + camera->GetFarClip()) * 0.5f));
+            quadTransform.SetScale(Vector3(far.x_, far.y_, 1.0f)); // Will be oversized, but doesn't matter (gets frustum clipped)
+            volumeTransform_ = camera->GetEffectiveWorldTransform() * quadTransform;
+            break;
+        }
 
 
     case LIGHT_SPOT:
     case LIGHT_SPOT:
         {
         {

+ 0 - 2
Source/Urho3D/Graphics/Light.h

@@ -259,8 +259,6 @@ public:
     void SetIntensitySortValue(const BoundingBox& box);
     void SetIntensitySortValue(const BoundingBox& box);
     /// Set light queue used for this light. Called by View.
     /// Set light queue used for this light. Called by View.
     void SetLightQueue(LightBatchQueue* queue);
     void SetLightQueue(LightBatchQueue* queue);
-    /// Return directional light quad transform for either near or far split.
-    Matrix3x4 GetDirLightTransform(Camera* camera, bool getNearQuad = false);
     /// Return light volume model transform.
     /// Return light volume model transform.
     const Matrix3x4& GetVolumeTransform(Camera* camera);
     const Matrix3x4& GetVolumeTransform(Camera* camera);
     /// Return light queue. Called by View.
     /// Return light queue. Called by View.

+ 4 - 8
Source/Urho3D/Graphics/View.cpp

@@ -643,7 +643,7 @@ void View::SetGlobalShaderParameters()
     }
     }
 }
 }
 
 
-void View::SetCameraShaderParameters(Camera* camera, bool setProjection, bool overrideView)
+void View::SetCameraShaderParameters(Camera* camera, bool setProjection)
 {
 {
     if (!camera)
     if (!camera)
         return;
         return;
@@ -695,10 +695,7 @@ void View::SetCameraShaderParameters(Camera* camera, bool setProjection, bool ov
         projection.m23_ += projection.m33_ * constantBias;
         projection.m23_ += projection.m33_ * constantBias;
         #endif
         #endif
         
         
-        if (overrideView)
-            graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
-        else
-            graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * camera->GetView());
+        graphics_->SetShaderParameter(VSP_VIEWPROJ, projection * camera->GetView());
     }
     }
 }
 }
 
 
@@ -1057,7 +1054,6 @@ void View::GetBatches()
                     volumeBatch.geometryType_ = GEOM_STATIC;
                     volumeBatch.geometryType_ = GEOM_STATIC;
                     volumeBatch.worldTransform_ = &light->GetVolumeTransform(camera_);
                     volumeBatch.worldTransform_ = &light->GetVolumeTransform(camera_);
                     volumeBatch.numWorldTransforms_ = 1;
                     volumeBatch.numWorldTransforms_ = 1;
-                    volumeBatch.overrideView_ = light->GetLightType() == LIGHT_DIRECTIONAL;
                     volumeBatch.camera_ = camera_;
                     volumeBatch.camera_ = camera_;
                     volumeBatch.lightQueue_ = &lightQueue;
                     volumeBatch.lightQueue_ = &lightQueue;
                     volumeBatch.distance_ = light->GetDistance();
                     volumeBatch.distance_ = light->GetDistance();
@@ -1735,7 +1731,7 @@ void View::RenderQuad(RenderPathCommand& command)
         graphics_->SetShaderParameter(k->first_, k->second_);
         graphics_->SetShaderParameter(k->first_, k->second_);
     
     
     SetGlobalShaderParameters();
     SetGlobalShaderParameters();
-    SetCameraShaderParameters(camera_, false, false);
+    SetCameraShaderParameters(camera_, false);
     
     
     // During renderpath commands the G-Buffer or viewport texture is assumed to always be viewport-sized
     // During renderpath commands the G-Buffer or viewport texture is assumed to always be viewport-sized
     IntRect viewport = graphics_->GetViewport();
     IntRect viewport = graphics_->GetViewport();
@@ -2753,7 +2749,7 @@ void View::AddBatchToQueue(BatchQueue& batchQueue, Batch& batch, Technique* tech
         batch.material_ = renderer_->GetDefaultMaterial();
         batch.material_ = renderer_->GetDefaultMaterial();
     
     
     // Convert to instanced if possible
     // Convert to instanced if possible
-    if (allowInstancing && batch.geometryType_ == GEOM_STATIC && batch.geometry_->GetIndexBuffer() && !batch.overrideView_)
+    if (allowInstancing && batch.geometryType_ == GEOM_STATIC && batch.geometry_->GetIndexBuffer())
         batch.geometryType_ = GEOM_INSTANCED;
         batch.geometryType_ = GEOM_INSTANCED;
     
     
     if (batch.geometryType_ == GEOM_INSTANCED)
     if (batch.geometryType_ == GEOM_INSTANCED)

+ 1 - 1
Source/Urho3D/Graphics/View.h

@@ -153,7 +153,7 @@ public:
     /// Set global (per-frame) shader parameters. Called by Batch and internally by View.
     /// Set global (per-frame) shader parameters. Called by Batch and internally by View.
     void SetGlobalShaderParameters();
     void SetGlobalShaderParameters();
     /// Set camera-specific shader parameters. Called by Batch and internally by View.
     /// Set camera-specific shader parameters. Called by Batch and internally by View.
-    void SetCameraShaderParameters(Camera* camera, bool setProjectionMatrix, bool overrideView);
+    void SetCameraShaderParameters(Camera* camera, bool setProjectionMatrix);
     /// Set G-buffer offset and inverse size shader parameters. Called by Batch and internally by View.
     /// Set G-buffer offset and inverse size shader parameters. Called by Batch and internally by View.
     void SetGBufferShaderParameters(const IntVector2& texSize, const IntRect& viewRect);
     void SetGBufferShaderParameters(const IntVector2& texSize, const IntRect& viewRect);