summaryrefslogtreecommitdiffstats
path: root/unityplugin/GhostCubeScene/src
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-02-07 01:03:16 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-02-07 01:03:16 +0000
commit6e7bac7b34a86f4e8e1a663631d5f260c064ac0a (patch)
tree36ad11810cdb9b722411ec9365cc3f8babbac323 /unityplugin/GhostCubeScene/src
parentUpdate README.md (diff)
downloadDiligentEngine-6e7bac7b34a86f4e8e1a663631d5f260c064ac0a.tar.gz
DiligentEngine-6e7bac7b34a86f4e8e1a663631d5f260c064ac0a.zip
Reworked Win32 native app implementation
Diffstat (limited to 'unityplugin/GhostCubeScene/src')
-rw-r--r--unityplugin/GhostCubeScene/src/GhostCubeScene.cpp18
-rw-r--r--unityplugin/GhostCubeScene/src/GhostCubeScene.h15
-rw-r--r--unityplugin/GhostCubeScene/src/GhostCubeSceneResTrsnHelper.cpp1
3 files changed, 19 insertions, 15 deletions
diff --git a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp
index efd457b..ac8b542 100644
--- a/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp
+++ b/unityplugin/GhostCubeScene/src/GhostCubeScene.cpp
@@ -22,6 +22,7 @@
*/
#include "GhostCubeScene.h"
+#include "PlatformDefinitions.h"
#include "BasicMath.h"
#include <algorithm>
#include "BasicShaderSourceStreamFactory.h"
@@ -29,12 +30,6 @@
#include "MapHelper.h"
#include "CommonlyUsedStates.h"
-#if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS)
-# define D3D12_SUPPORTED 1
-#else
-# define D3D12_SUPPORTED 0
-#endif
-
#if D3D12_SUPPORTED
# include "GhostCubeSceneResTrsnHelper.h"
#endif
@@ -142,7 +137,13 @@ void GhostCubeScene::OnGraphicsInitialized()
#endif
}
-void GhostCubeScene::Render(UnityRenderingEvent RenderEventFunc, double CurrTime, double ElapsedTime)
+void GhostCubeScene::Update(double CurrTime, double ElapsedTime)
+{
+ m_CubeWorldView = scaleMatrix(1, 2, 1) * rotationY(-static_cast<float>(CurrTime) * 2.0f) * rotationX(-PI_F * 0.3f) * translationMatrix(0.f, 0.0f, 10.0f);
+}
+
+
+void GhostCubeScene::Render(UnityRenderingEvent RenderEventFunc)
{
auto pDevice = m_DiligentGraphics->GetDevice();
auto pCtx = m_DiligentGraphics->GetContext();
@@ -169,14 +170,13 @@ void GhostCubeScene::Render(UnityRenderingEvent RenderEventFunc, double CurrTime
// Render ghost cube into the mirror texture
{
// Create fake reflection matrix
- float4x4 CubeWorldView = scaleMatrix(1,2,1) * rotationY( -static_cast<float>(CurrTime) * 2.0f) * rotationX(-PI_F*0.3f) * translationMatrix(0.f, 0.0f, 10.0f);
float NearPlane = 0.3f;
float FarPlane = 1000.f;
if (ReverseZ)
std::swap(NearPlane, FarPlane);
float aspectRatio = 1.0f;
float4x4 ReflectionCameraProj = Projection(PI_F / 4.f, aspectRatio, NearPlane, FarPlane, IsDX);
- auto wvp = CubeWorldView * ReflectionCameraProj;
+ auto wvp = m_CubeWorldView * ReflectionCameraProj;
float fReverseZ = IsDX ? -1.f : +1.f;
SetMatrixFromUnity(wvp._m00, fReverseZ * wvp._m01, wvp._m02, wvp._m03,
wvp._m10, fReverseZ * wvp._m11, wvp._m12, wvp._m13,
diff --git a/unityplugin/GhostCubeScene/src/GhostCubeScene.h b/unityplugin/GhostCubeScene/src/GhostCubeScene.h
index 63f440d..f993791 100644
--- a/unityplugin/GhostCubeScene/src/GhostCubeScene.h
+++ b/unityplugin/GhostCubeScene/src/GhostCubeScene.h
@@ -23,6 +23,7 @@
#include "UnitySceneBase.h"
#include "IUnityInterface.h"
+#include "BasicMath.h"
using TSetMatrixFromUnity = void (UNITY_INTERFACE_API *) (float m00, float m01, float m02, float m03,
float m10, float m11, float m12, float m13,
@@ -30,7 +31,7 @@ using TSetMatrixFromUnity = void (UNITY_INTERFACE_API *) (float m00, float m01,
float m30, float m31, float m32, float m33);
using TSetTexturesFromUnity = void (UNITY_INTERFACE_API *)(void* renderTargetHandle, void *depthBufferHandle);
-class GhostCubeScene : public UnitySceneBase
+class GhostCubeScene final : public UnitySceneBase
{
public:
virtual void OnPluginLoad(TLoadPluginFunction LoadPluginFunctionCallback)override final;
@@ -39,17 +40,19 @@ public:
virtual void OnGraphicsInitialized()override final;
- virtual void Render(UnityRenderingEvent RenderEventFunc, double CurrTime, double ElapsedTime)override final;
+ virtual void Render(UnityRenderingEvent RenderEventFunc)override final;
+ virtual void Update(double CurrTime, double ElapsedTime)override final;
- virtual const char* GetSceneName()override final { return "Ghost Cube Scene"; }
+ virtual const char* GetSceneName()const override final { return "Ghost Cube Scene"; }
- virtual const char* GetPluginName()override final { return "GhostCubePlugin"; }
+ virtual const char* GetPluginName()const override final { return "GhostCubePlugin"; }
private:
friend class GhostCubeSceneResTrsnHelper;
- TSetMatrixFromUnity SetMatrixFromUnity;
- TSetTexturesFromUnity SetTexturesFromUnity;
+ TSetMatrixFromUnity SetMatrixFromUnity = nullptr;
+ TSetTexturesFromUnity SetTexturesFromUnity = nullptr;
+ float4x4 m_CubeWorldView;
Diligent::RefCntAutoPtr<Diligent::ITexture> m_pRenderTarget;
Diligent::RefCntAutoPtr<Diligent::ITexture> m_pDepthBuffer;
diff --git a/unityplugin/GhostCubeScene/src/GhostCubeSceneResTrsnHelper.cpp b/unityplugin/GhostCubeScene/src/GhostCubeSceneResTrsnHelper.cpp
index 71eccb0..39b89c1 100644
--- a/unityplugin/GhostCubeScene/src/GhostCubeSceneResTrsnHelper.cpp
+++ b/unityplugin/GhostCubeScene/src/GhostCubeSceneResTrsnHelper.cpp
@@ -20,6 +20,7 @@
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
+#define NOMINMAX
#include <d3d12.h>
#include "GhostCubeSceneResTrsnHelper.h"