mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
Fix lens flares in VR
This commit is contained in:
parent
14628e3937
commit
c6d2456a7c
3 changed files with 44 additions and 33 deletions
|
|
@ -33,6 +33,7 @@
|
||||||
#include "gfx/gfxOcclusionQuery.h"
|
#include "gfx/gfxOcclusionQuery.h"
|
||||||
#include "gfx/gfxDrawUtil.h"
|
#include "gfx/gfxDrawUtil.h"
|
||||||
#include "gfx/gfxTextureManager.h"
|
#include "gfx/gfxTextureManager.h"
|
||||||
|
#include "gfx/sim/debugDraw.h"
|
||||||
#include "renderInstance/renderPassManager.h"
|
#include "renderInstance/renderPassManager.h"
|
||||||
#include "T3D/gameBase/gameConnection.h"
|
#include "T3D/gameBase/gameConnection.h"
|
||||||
#include "T3D/gameBase/processList.h"
|
#include "T3D/gameBase/processList.h"
|
||||||
|
|
@ -275,12 +276,10 @@ bool LightFlareData::_testVisibility(const SceneRenderState *state, LightFlareSt
|
||||||
// is on scren at all... if not then return
|
// is on scren at all... if not then return
|
||||||
// the last result.
|
// the last result.
|
||||||
const Point3F &lightPos = flareState->lightMat.getPosition();
|
const Point3F &lightPos = flareState->lightMat.getPosition();
|
||||||
const RectI &viewport = GFX->getViewport();
|
const RectI &viewport = RectI(Point2I(0, 0), GFX->getViewport().extent);
|
||||||
MatrixF projMatrix;
|
|
||||||
state->getCameraFrustum().getProjectionMatrix(&projMatrix);
|
MatrixF camProjMatrix = projMatrix = state->getSceneManager()->getNonClipProjection();
|
||||||
if( state->isReflectPass() )
|
bool onScreen = MathUtils::mProjectWorldToScreen( lightPos, outLightPosSS, viewport, GFX->getWorldMatrix(), camProjMatrix );
|
||||||
projMatrix = state->getSceneManager()->getNonClipProjection();
|
|
||||||
bool onScreen = MathUtils::mProjectWorldToScreen( lightPos, outLightPosSS, viewport, GFX->getWorldMatrix(), projMatrix );
|
|
||||||
|
|
||||||
// It is onscreen, so raycast as a simple occlusion test.
|
// It is onscreen, so raycast as a simple occlusion test.
|
||||||
const LightInfo *lightInfo = flareState->lightInfo;
|
const LightInfo *lightInfo = flareState->lightInfo;
|
||||||
|
|
@ -436,6 +435,8 @@ void LightFlareData::prepRender( SceneRenderState *state, LightFlareState *flare
|
||||||
Point3F lightPosSS;
|
Point3F lightPosSS;
|
||||||
bool lightVisible = _testVisibility(state, flareState, &visDelta, &occlusionFade, &lightPosSS);
|
bool lightVisible = _testVisibility(state, flareState, &visDelta, &occlusionFade, &lightPosSS);
|
||||||
|
|
||||||
|
//DebugDrawer::get()->drawBox(flareState->lightMat.getPosition() + Point3F(-0.5, -0.5, -0.5) * 4, flareState->lightMat.getPosition() + Point3F(0.5, 0.5, 0.5) * 4, ColorI::BLUE);
|
||||||
|
|
||||||
// We can only skip rendering if the light is not
|
// We can only skip rendering if the light is not
|
||||||
// visible, and it has elapsed the fade out time.
|
// visible, and it has elapsed the fade out time.
|
||||||
if (mIsZero(occlusionFade) ||
|
if (mIsZero(occlusionFade) ||
|
||||||
|
|
@ -445,18 +446,28 @@ void LightFlareData::prepRender( SceneRenderState *state, LightFlareState *flare
|
||||||
const RectI &viewport = GFX->getViewport();
|
const RectI &viewport = GFX->getViewport();
|
||||||
Point3F oneOverViewportExtent(1.0f / (F32)viewport.extent.x, 1.0f / (F32)viewport.extent.y, 0.0f);
|
Point3F oneOverViewportExtent(1.0f / (F32)viewport.extent.x, 1.0f / (F32)viewport.extent.y, 0.0f);
|
||||||
|
|
||||||
// Really convert it to screen space.
|
|
||||||
lightPosSS.x -= viewport.point.x;
|
|
||||||
lightPosSS.y -= viewport.point.y;
|
|
||||||
lightPosSS *= oneOverViewportExtent;
|
lightPosSS *= oneOverViewportExtent;
|
||||||
lightPosSS = (lightPosSS * 2.0f) - Point3F::One;
|
lightPosSS = (lightPosSS * 2.0f) - Point3F::One;
|
||||||
lightPosSS.y = -lightPosSS.y;
|
lightPosSS.y = -lightPosSS.y;
|
||||||
lightPosSS.z = 0.0f;
|
lightPosSS.z = 0.0f;
|
||||||
|
|
||||||
|
// Determine the center of the current projection so we can converge there
|
||||||
|
Point3F centerProj(0);
|
||||||
|
{
|
||||||
|
MatrixF camProjMatrix = state->getSceneManager()->getNonClipProjection();
|
||||||
|
Point3F outCenterPos;
|
||||||
|
RectI centerViewport = RectI(Point2I(0, 0), viewport.extent);
|
||||||
|
MathUtils::mProjectWorldToScreen(Point3F(0,state->getSceneManager()->getNearClip(),0), &outCenterPos, centerViewport, MatrixF::Identity, camProjMatrix);
|
||||||
|
centerProj = outCenterPos;
|
||||||
|
centerProj *= oneOverViewportExtent;
|
||||||
|
centerProj = (centerProj * 2.0f) - Point3F::One;
|
||||||
|
centerProj.y = -centerProj.y;
|
||||||
|
centerProj.z = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// Take any projection offset into account so that the point where the flare's
|
// Take any projection offset into account so that the point where the flare's
|
||||||
// elements converge is at the 'eye' point rather than the center of the viewport.
|
// elements converge is at the 'eye' point rather than the center of the viewport.
|
||||||
const Point2F& projOffset = state->getCameraFrustum().getProjectionOffset();
|
Point3F flareVec( centerProj - lightPosSS );
|
||||||
Point3F flareVec( -lightPosSS + Point3F(projOffset.x, projOffset.y, 0.0f) );
|
|
||||||
const F32 flareLength = flareVec.len();
|
const F32 flareLength = flareVec.len();
|
||||||
if ( flareLength > 0.0f )
|
if ( flareLength > 0.0f )
|
||||||
flareVec *= 1.0f / flareLength;
|
flareVec *= 1.0f / flareLength;
|
||||||
|
|
|
||||||
|
|
@ -667,11 +667,11 @@ void ScatterSky::prepRenderImage( SceneRenderState *state )
|
||||||
mFlareState.scale = mFlareScale;
|
mFlareState.scale = mFlareScale;
|
||||||
mFlareState.lightInfo = mLight;
|
mFlareState.lightInfo = mLight;
|
||||||
|
|
||||||
Point3F lightPos = state->getCameraPosition() - state->getFarPlane() * mLight->getDirection() * 0.9f;
|
Point3F lightPos = state->getDiffuseCameraPosition() - state->getFarPlane() * mLight->getDirection() * 0.9f;
|
||||||
mFlareState.lightMat.identity();
|
mFlareState.lightMat.identity();
|
||||||
mFlareState.lightMat.setPosition( lightPos );
|
mFlareState.lightMat.setPosition( lightPos );
|
||||||
|
|
||||||
F32 dist = ( lightPos - state->getCameraPosition( ) ).len( );
|
F32 dist = ( lightPos - state->getDiffuseCameraPosition( ) ).len( );
|
||||||
F32 coronaScale = 0.5f;
|
F32 coronaScale = 0.5f;
|
||||||
F32 screenRadius = GFX->getViewport( ).extent.y * coronaScale * 0.5f;
|
F32 screenRadius = GFX->getViewport( ).extent.y * coronaScale * 0.5f;
|
||||||
mFlareState.worldRadius = screenRadius * dist / state->getWorldToScreenScale( ).y;
|
mFlareState.worldRadius = screenRadius * dist / state->getWorldToScreenScale( ).y;
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ void Frustum::setNearFarDist( F32 nearDist, F32 farDist )
|
||||||
// Recalculate the frustum.
|
// Recalculate the frustum.
|
||||||
MatrixF xfm( mTransform );
|
MatrixF xfm( mTransform );
|
||||||
|
|
||||||
const F32 CENTER_EPSILON = 0.01;
|
const F32 CENTER_EPSILON = 0.001;
|
||||||
F32 centerX = mNearLeft + (mNearRight - mNearLeft) * 0.5;
|
F32 centerX = mNearLeft + (mNearRight - mNearLeft) * 0.5;
|
||||||
F32 centerY = mNearBottom + (mNearTop - mNearBottom) * 0.5;
|
F32 centerY = mNearBottom + (mNearTop - mNearBottom) * 0.5;
|
||||||
if ((centerX > CENTER_EPSILON || centerX < -CENTER_EPSILON) || (centerY > CENTER_EPSILON || centerY < -CENTER_EPSILON) )
|
if ((centerX > CENTER_EPSILON || centerX < -CENTER_EPSILON) || (centerY > CENTER_EPSILON || centerY < -CENTER_EPSILON) )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue