Browse Source

Fix for procedural sky rendering to rendertarget

Josh Engebretson 10 years ago
parent
commit
67dfe43c6c
2 changed files with 33 additions and 10 deletions
  1. 30 10
      Source/Atomic/Environment/ProcSky.cpp
  2. 3 0
      Source/Atomic/Environment/ProcSky.h

+ 30 - 10
Source/Atomic/Environment/ProcSky.cpp

@@ -5,6 +5,8 @@
 #include "Precompiled.h"
 #include "Precompiled.h"
 #include "../Core/Context.h"
 #include "../Core/Context.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/Graphics.h"
+#include "../Graphics/GraphicsEvents.h"
+#include "../Graphics/View.h"
 #include "../Scene/Scene.h"
 #include "../Scene/Scene.h"
 #include "../Graphics/Camera.h"
 #include "../Graphics/Camera.h"
 #include "../Scene/SceneEvents.h"
 #include "../Scene/SceneEvents.h"
@@ -39,8 +41,8 @@ ProcSky::ProcSky(Context* context) :
     lastDayTimeUpdate_(-1.0f),
     lastDayTimeUpdate_(-1.0f),
     shadowFade_(1.0f),
     shadowFade_(1.0f),
     customWorldTransform_(Matrix3x4::IDENTITY),
     customWorldTransform_(Matrix3x4::IDENTITY),
-    initialized_(false)
-
+    initialized_(false),
+    flipped_(false)
 {
 {
 
 
 }
 }
@@ -74,10 +76,6 @@ void ProcSky::UpdateBatches(const FrameInfo& frame)
         batches_[i].worldTransform_ = &customWorldTransform_;
         batches_[i].worldTransform_ = &customWorldTransform_;
         batches_[i].numWorldTransforms_ = 1;
         batches_[i].numWorldTransforms_ = 1;
         batches_[i].distance_ = 0.0f;
         batches_[i].distance_ = 0.0f;
-
-
-        // URHO3D UPDATE, this likely breaks proc sky for now
-        // batches_[i].overrideView_ = true;
     }
     }
 
 
 }
 }
@@ -113,10 +111,23 @@ void ProcSky::OnNodeSet(Node* node)
     if (node && node->GetScene())
     if (node && node->GetScene())
     {     
     {     
         SubscribeToEvent(node->GetScene(), E_SCENEUPDATE, HANDLER(ProcSky, HandleSceneUpdate));
         SubscribeToEvent(node->GetScene(), E_SCENEUPDATE, HANDLER(ProcSky, HandleSceneUpdate));
+        SubscribeToEvent(E_BEGINVIEWUPDATE, HANDLER(ProcSky, HandleBeginViewUpdate));
     }
     }
 
 
 }
 }
 
 
+void ProcSky::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData)
+{
+#ifdef ATOMIC_OPENGL
+    flipped_ = false;
+    View* view = static_cast<View*>(eventData[BeginViewUpdate::P_VIEW].GetPtr());
+    if (view && view->GetRenderTarget())
+        flipped_ = true;
+
+#endif
+
+}
+
 void ProcSky::HandleSceneUpdate(StringHash eventType, VariantMap& eventData)
 void ProcSky::HandleSceneUpdate(StringHash eventType, VariantMap& eventData)
 {
 {
 
 
@@ -313,10 +324,19 @@ void ProcSky::UpdateVertexBuffer(const FrameInfo &frame)
     planes[2] = frustum.planes_[PLANE_UP].normal_;
     planes[2] = frustum.planes_[PLANE_UP].normal_;
     planes[3] = frustum.planes_[PLANE_DOWN].normal_;
     planes[3] = frustum.planes_[PLANE_DOWN].normal_;
 
 
+
+    float top = 1.0f;
+    float bottom = -1.0f;
+
+#ifdef ATOMIC_OPENGL
+    top = -1.0f;
+    bottom = 1.0f;
+#endif
+
     // 0 2
     // 0 2
     n = planes[0].CrossProduct(planes[2]);
     n = planes[0].CrossProduct(planes[2]);
     *vdest++ = -1.0f;
     *vdest++ = -1.0f;
-    *vdest++ =  1.0f;
+    *vdest++ =  top;
     *vdest++ =  0.5f;
     *vdest++ =  0.5f;
 
 
     *vdest++ = n.x_;
     *vdest++ = n.x_;
@@ -327,7 +347,7 @@ void ProcSky::UpdateVertexBuffer(const FrameInfo &frame)
     // 3 0
     // 3 0
     n = planes[3].CrossProduct(planes[0]);
     n = planes[3].CrossProduct(planes[0]);
     *vdest++ = -1.0f;
     *vdest++ = -1.0f;
-    *vdest++ = -1.0f;
+    *vdest++ = bottom;
     *vdest++ =  0.5f;
     *vdest++ =  0.5f;
 
 
     *vdest++ = n.x_;
     *vdest++ = n.x_;
@@ -338,7 +358,7 @@ void ProcSky::UpdateVertexBuffer(const FrameInfo &frame)
     // 1 3
     // 1 3
     n = planes[1].CrossProduct(planes[3]);
     n = planes[1].CrossProduct(planes[3]);
     *vdest++ = 1.0f;
     *vdest++ = 1.0f;
-    *vdest++ = -1.0f;
+    *vdest++ = bottom;
     *vdest++ =  0.5f;
     *vdest++ =  0.5f;
 
 
     *vdest++ = n.x_;
     *vdest++ = n.x_;
@@ -350,7 +370,7 @@ void ProcSky::UpdateVertexBuffer(const FrameInfo &frame)
     // 2 1
     // 2 1
     n = planes[2].CrossProduct(planes[1]);
     n = planes[2].CrossProduct(planes[1]);
     *vdest++ = 1.0f;
     *vdest++ = 1.0f;
-    *vdest++ = 1.0f;
+    *vdest++ = top;
     *vdest++ =  0.5f;
     *vdest++ =  0.5f;
 
 
     *vdest++ = n.x_;
     *vdest++ = n.x_;

+ 3 - 0
Source/Atomic/Environment/ProcSky.h

@@ -96,10 +96,13 @@ protected:
     Matrix3x4 customWorldTransform_;
     Matrix3x4 customWorldTransform_;
 
 
     bool initialized_;
     bool initialized_;
+    bool flipped_;
 
 
     void OnNodeSet(Node* node);
     void OnNodeSet(Node* node);
 
 
     void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
     void HandleSceneUpdate(StringHash eventType, VariantMap& eventData);
+    void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
+
     void Initialize();
     void Initialize();
 
 
     void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);
     void ProcessRayQuery(const RayOctreeQuery& query, PODVector<RayQueryResult>& results);