From 43f8adff7993187f304e681b42156d7d58062fa2 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 2 Jul 2013 03:34:49 +0200 Subject: [PATCH] Render left and right deformed view, re #43 --HG-- branch : multipass-stereo --- code/nel/include/nel/3d/stereo_ovr.h | 3 +- code/nel/src/3d/stereo_ovr.cpp | 46 +++++++++++++------ .../client/src/snowballs_client.cpp | 12 +++-- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/code/nel/include/nel/3d/stereo_ovr.h b/code/nel/include/nel/3d/stereo_ovr.h index 8d4a924a6..857c5368f 100644 --- a/code/nel/include/nel/3d/stereo_ovr.h +++ b/code/nel/include/nel/3d/stereo_ovr.h @@ -147,7 +147,8 @@ private: NLMISC::CSmartPtr m_BarrelTex; NL3D::CTextureUser *m_BarrelTexU; NL3D::UMaterial m_BarrelMat; - NLMISC::CQuadUV m_BarrelQuad; + NLMISC::CQuadUV m_BarrelQuadLeft; + NLMISC::CQuadUV m_BarrelQuadRight; CPixelProgram *m_PixelProgram; }; /* class CStereoOVR */ diff --git a/code/nel/src/3d/stereo_ovr.cpp b/code/nel/src/3d/stereo_ovr.cpp index 4405ad313..63dd03d2f 100644 --- a/code/nel/src/3d/stereo_ovr.cpp +++ b/code/nel/src/3d/stereo_ovr.cpp @@ -292,18 +292,29 @@ void CStereoOVR::setDriver(NL3D::UDriver *driver) barrelMat->setDoubleSided(true); barrelMat->setTexture(0, m_BarrelTex); - m_BarrelQuad.V0 = CVector(0.f, 0.f, 0.5f); - m_BarrelQuad.V1 = CVector(1.f, 0.f, 0.5f); - m_BarrelQuad.V2 = CVector(1.f, 1.f, 0.5f); - m_BarrelQuad.V3 = CVector(0.f, 1.f, 0.5f); + m_BarrelQuadLeft.V0 = CVector(0.f, 0.f, 0.5f); + m_BarrelQuadLeft.V1 = CVector(0.5f, 0.f, 0.5f); + m_BarrelQuadLeft.V2 = CVector(0.5f, 1.f, 0.5f); + m_BarrelQuadLeft.V3 = CVector(0.f, 1.f, 0.5f); + + m_BarrelQuadRight.V0 = CVector(0.5f, 0.f, 0.5f); + m_BarrelQuadRight.V1 = CVector(1.f, 0.f, 0.5f); + m_BarrelQuadRight.V2 = CVector(1.f, 1.f, 0.5f); + m_BarrelQuadRight.V3 = CVector(0.5f, 1.f, 0.5f); + nlassert(!drvInternal->isTextureRectangle(m_BarrelTex)); // this code looks no good float newU = drvInternal->isTextureRectangle(m_BarrelTex) ? (float)width : 1.f; float newV = drvInternal->isTextureRectangle(m_BarrelTex) ? (float)height : 1.f; - m_BarrelQuad.Uv0 = CUV(0.f, 0.f); - m_BarrelQuad.Uv1 = CUV(newU, 0.f); - m_BarrelQuad.Uv2 = CUV(newU, newV); - m_BarrelQuad.Uv3 = CUV(0.f, newV); + m_BarrelQuadLeft.Uv0 = CUV(0.f, 0.f); + m_BarrelQuadLeft.Uv1 = CUV(newU * 0.5f, 0.f); + m_BarrelQuadLeft.Uv2 = CUV(newU * 0.5f, newV); + m_BarrelQuadLeft.Uv3 = CUV(0.f, newV); + + m_BarrelQuadRight.Uv0 = CUV(newU * 0.5f, 0.f); + m_BarrelQuadRight.Uv1 = CUV(newU, 0.f); + m_BarrelQuadRight.Uv2 = CUV(newU, newV); + m_BarrelQuadRight.Uv3 = CUV(newU * 0.5f, newV); } else { @@ -525,10 +536,10 @@ bool CStereoOVR::endRenderTarget() barrelMat->setTexture(0, m_BarrelTex); drvInternal->activePixelProgram(m_PixelProgram); - float w = float(vp.getWidth()),// / float(width), - h = float(vp.getHeight()),// / float(height), - x = float(vp.getX()),/// / float(width), - y = float(vp.getY());// / float(height); + float w = float(m_BarrelQuadLeft.V1.x),// / float(width), + h = float(m_BarrelQuadLeft.V2.y),// / float(height), + x = float(m_BarrelQuadLeft.V0.x),/// / float(width), + y = float(m_BarrelQuadLeft.V0.y);// / float(height); float lensOffset = m_DevicePtr->HMDInfo.LensSeparationDistance * 0.5f; float lensShift = m_DevicePtr->HMDInfo.HScreenSize * 0.25f - lensOffset; @@ -549,7 +560,16 @@ bool CStereoOVR::endRenderTarget() drvInternal->setPixelProgramConstant(4, 1, m_DevicePtr->HMDInfo.DistortionK); - m_Driver->drawQuad(m_BarrelQuad, m_BarrelMat); + m_Driver->drawQuad(m_BarrelQuadLeft, m_BarrelMat); + + x = w; + lensCenterX = x + (w - lensViewportShift * 0.5f) * 0.5f; + screenCenterX = x + w * 0.5f; + drvInternal->setPixelProgramConstant(0, lensCenterX, lensCenterY, 0.f, 0.f); + drvInternal->setPixelProgramConstant(1, screenCenterX, screenCenterY, 0.f, 0.f); + + m_Driver->drawQuad(m_BarrelQuadRight, m_BarrelMat); + drvInternal->activePixelProgram(NULL); m_Driver->enableFog(fogEnabled); diff --git a/code/snowballs2/client/src/snowballs_client.cpp b/code/snowballs2/client/src/snowballs_client.cpp index 1faf14d67..2522f48b6 100644 --- a/code/snowballs2/client/src/snowballs_client.cpp +++ b/code/snowballs2/client/src/snowballs_client.cpp @@ -311,15 +311,17 @@ void initCore() // Create the window with config file values Driver->setDisplay(UDriver::CMode(ConfigFile->getVar("ScreenWidth").asInt(), ConfigFile->getVar("ScreenHeight").asInt(), - ConfigFile->getVar("ScreenDepth").asInt())); + ConfigFile->getVar("ScreenDepth").asInt(), + (ConfigFile->getVar("OpenGL").asInt() == 1 ? true : ConfigFile->getVar("ScreenFull").asInt()==0))); // Set the cache size for the font manager(in bytes) Driver->setFontManagerMaxMemory(2097152); // Create a Text context for later text rendering displayLoadingState("Initialize Text"); - Driver->setMode(UDriver::CMode(ConfigFile->getVar("ScreenWidth").asInt(), - ConfigFile->getVar("ScreenHeight").asInt(), - ConfigFile->getVar("ScreenDepth").asInt(), - ConfigFile->getVar("ScreenFull").asInt()==0)); + if (ConfigFile->getVar("OpenGL").asInt() == 1) + Driver->setMode(UDriver::CMode(ConfigFile->getVar("ScreenWidth").asInt(), + ConfigFile->getVar("ScreenHeight").asInt(), + ConfigFile->getVar("ScreenDepth").asInt(), + ConfigFile->getVar("ScreenFull").asInt()==0)); TextContext = Driver->createTextContext(CPath::lookup(ConfigFile->getVar("FontName").asString())); TextContext->setShaded(true); TextContext->setKeep800x600Ratio(false);