mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 08:04:40 +00:00
sunbokeh partly fix, still needs work
This commit is contained in:
parent
5b62df81c7
commit
5f2ab23fac
6 changed files with 83 additions and 21 deletions
|
|
@ -121,7 +121,6 @@ LightFlareData::LightFlareData()
|
||||||
mElementCount( 0 ),
|
mElementCount( 0 ),
|
||||||
mScale( 1.0f ),
|
mScale( 1.0f ),
|
||||||
mOcclusionRadius( 0.0f ),
|
mOcclusionRadius( 0.0f ),
|
||||||
mVisibility( 1.0f ), //sunBokeh feature
|
|
||||||
mRenderReflectPass( true )
|
mRenderReflectPass( true )
|
||||||
{
|
{
|
||||||
dMemset( mElementRect, 0, sizeof( RectF ) * MAX_ELEMENTS );
|
dMemset( mElementRect, 0, sizeof( RectF ) * MAX_ELEMENTS );
|
||||||
|
|
@ -446,8 +445,6 @@ 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 );
|
||||||
|
|
||||||
// Sun visibility, assume 0 at start of frame
|
|
||||||
mVisibility = 0; //sunBokeh feature
|
|
||||||
// Really convert it to screen space.
|
// Really convert it to screen space.
|
||||||
lightPosSS.x -= viewport.point.x;
|
lightPosSS.x -= viewport.point.x;
|
||||||
lightPosSS.y -= viewport.point.y;
|
lightPosSS.y -= viewport.point.y;
|
||||||
|
|
@ -517,7 +514,6 @@ void LightFlareData::prepRender( SceneRenderState *state, LightFlareState *flare
|
||||||
// These are the factors which affect the "alpha" of the flare effect.
|
// These are the factors which affect the "alpha" of the flare effect.
|
||||||
// Modulate more in as appropriate.
|
// Modulate more in as appropriate.
|
||||||
ColorF baseColor = ColorF::WHITE * lightSourceBrightnessScale * occlusionFade;
|
ColorF baseColor = ColorF::WHITE * lightSourceBrightnessScale * occlusionFade;
|
||||||
mVisibility = lightSourceBrightnessScale * fadeInOutScale * occlusionFade; //sunBokeh feature
|
|
||||||
|
|
||||||
// Setup the vertex buffer for the maximum flare elements.
|
// Setup the vertex buffer for the maximum flare elements.
|
||||||
const U32 vertCount = 4 * mElementCount;
|
const U32 vertCount = 4 * mElementCount;
|
||||||
|
|
|
||||||
|
|
@ -94,8 +94,6 @@ public:
|
||||||
|
|
||||||
/// Submits render instances for corona and flare effects.
|
/// Submits render instances for corona and flare effects.
|
||||||
void prepRender( SceneRenderState *state, LightFlareState *flareState );
|
void prepRender( SceneRenderState *state, LightFlareState *flareState );
|
||||||
/// sunBokeh feature
|
|
||||||
F32 getVisibility() const { return mVisibility; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
@ -114,7 +112,6 @@ protected:
|
||||||
static Point3F sBasePoints[4];
|
static Point3F sBasePoints[4];
|
||||||
|
|
||||||
// Fields...
|
// Fields...
|
||||||
F32 mVisibility; //sunBokeh feature
|
|
||||||
F32 mScale;
|
F32 mScale;
|
||||||
bool mFlareEnabled;
|
bool mFlareEnabled;
|
||||||
String mFlareTextureName;
|
String mFlareTextureName;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@
|
||||||
#include "materials/sceneData.h"
|
#include "materials/sceneData.h"
|
||||||
#include "environment/timeOfDay.h"
|
#include "environment/timeOfDay.h"
|
||||||
|
|
||||||
|
|
||||||
ConsoleDocClass( ScatterSky,
|
ConsoleDocClass( ScatterSky,
|
||||||
"@brief Represents both the sun and sky for scenes with a dynamic time of day.\n\n"
|
"@brief Represents both the sun and sky for scenes with a dynamic time of day.\n\n"
|
||||||
|
|
||||||
|
|
@ -655,11 +654,6 @@ void ScatterSky::prepRenderImage( SceneRenderState *state )
|
||||||
state->getRenderPass()->addInst( ri );
|
state->getRenderPass()->addInst( ri );
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// Screen flare occlusion fix //sunBokeh feature
|
|
||||||
F32 screenRadius = GFX->getViewport().extent.y * mFlareScale * 0.01f;
|
|
||||||
Point3F lightWorldPos = state->getCameraPosition() - state->getFarPlane() * mLight->getDirection() * 0.9f;
|
|
||||||
F32 dist = ( lightWorldPos - state->getCameraPosition() ).len();
|
|
||||||
mFlareState.worldRadius = screenRadius * dist / state->getWorldToScreenScale().y;
|
|
||||||
|
|
||||||
// Light flare effect render instance.
|
// Light flare effect render instance.
|
||||||
if ( mFlareData && mNightInterpolant != 1.0f )
|
if ( mFlareData && mNightInterpolant != 1.0f )
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,6 @@ public:
|
||||||
F32 getAzimuth() const { return mSunAzimuth; }
|
F32 getAzimuth() const { return mSunAzimuth; }
|
||||||
///
|
///
|
||||||
F32 getElevation() const { return mSunElevation; }
|
F32 getElevation() const { return mSunElevation; }
|
||||||
/// sunBokeh feature
|
|
||||||
F32 getSunVisibility() const { if (mFlareData) return mFlareData->getVisibility(); else return 0; }
|
|
||||||
// Same method as above, but also checks if the data is valid, needs more CPU time, only use if above method fails
|
|
||||||
//F32 getSunVisibility() const { if dynamic_cast<LightFlareData*>(mFlareData) return mFlareData->getVisibility(); else return 0; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,8 @@
|
||||||
#include "postFx/postEffectManager.h"
|
#include "postFx/postEffectManager.h"
|
||||||
#include "postFx/postEffectVis.h"
|
#include "postFx/postEffectVis.h"
|
||||||
#include "environment/scatterSky.h" //sunBokeh feature
|
#include "environment/scatterSky.h" //sunBokeh feature
|
||||||
|
#include "T3D/gameBase/gameConnection.h" //sunBokeh feature
|
||||||
|
#include "T3D/lightFlareData.h" //sunBokeh feature
|
||||||
|
|
||||||
using namespace Torque;
|
using namespace Torque;
|
||||||
|
|
||||||
|
|
@ -855,9 +857,10 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
|
||||||
|
|
||||||
if( mSunVisibilitySC->isValid() ) //sunBokeh feature
|
if( mSunVisibilitySC->isValid() ) //sunBokeh feature
|
||||||
{
|
{
|
||||||
ScatterSky* pSky = dynamic_cast<ScatterSky*>(Sim::findObject("Himmel"));
|
LightInfo *sunLight = LIGHTMGR->getSpecialLight( LightManager::slSunLightType );
|
||||||
if(pSky)
|
|
||||||
mShaderConsts->set( mSunVisibilitySC, pSky->getSunVisibility() );
|
if(sunLight)
|
||||||
|
mShaderConsts->set( mSunVisibilitySC, _testVisibility(state) );
|
||||||
else
|
else
|
||||||
mShaderConsts->set( mSunVisibilitySC, 0.0f );
|
mShaderConsts->set( mSunVisibilitySC, 0.0f );
|
||||||
}
|
}
|
||||||
|
|
@ -918,6 +921,79 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
|
||||||
iter->value->setToBuffer( mShaderConsts );
|
iter->value->setToBuffer( mShaderConsts );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sunBokeh feature to test if sun is visible
|
||||||
|
F32 PostEffect::_testVisibility(const SceneRenderState *state)
|
||||||
|
{
|
||||||
|
// Grab our projection matrix
|
||||||
|
// from the frustum.
|
||||||
|
Frustum frust = state->getCameraFrustum();
|
||||||
|
MatrixF proj( true );
|
||||||
|
frust.getProjectionMatrix( &proj );
|
||||||
|
|
||||||
|
// Grab the ScatterSky world matrix.
|
||||||
|
MatrixF camMat = state->getCameraTransform();
|
||||||
|
camMat.inverse();
|
||||||
|
MatrixF tmp( true );
|
||||||
|
tmp = camMat;
|
||||||
|
tmp.setPosition( Point3F( 0, 0, 0 ) );
|
||||||
|
|
||||||
|
Point3F sunPos( 0, 0, 0 );
|
||||||
|
|
||||||
|
// Get the light manager and sun light object.
|
||||||
|
LightInfo *sunLight = LIGHTMGR->getSpecialLight( LightManager::slSunLightType );
|
||||||
|
|
||||||
|
// Grab the light direction and scale
|
||||||
|
// by the ScatterSky radius to get the world
|
||||||
|
// space sun position.
|
||||||
|
const VectorF &lightDir = sunLight->getDirection();
|
||||||
|
|
||||||
|
Point3F lightPos = sunLight->getPosition();
|
||||||
|
|
||||||
|
RectI viewPort = GFX->getViewport();
|
||||||
|
|
||||||
|
// Get the screen space sun position.
|
||||||
|
MathUtils::mProjectWorldToScreen(lightPos, &sunPos, viewPort, tmp, proj);
|
||||||
|
|
||||||
|
// And normalize it to the 0 to 1 range.
|
||||||
|
sunPos.x -= (F32)viewPort.point.x;
|
||||||
|
sunPos.y -= (F32)viewPort.point.y;
|
||||||
|
sunPos.x /= (F32)viewPort.extent.x;
|
||||||
|
sunPos.y /= (F32)viewPort.extent.y;
|
||||||
|
|
||||||
|
//------------------------------------------------------------
|
||||||
|
|
||||||
|
const Point3F &camPos = state->getCameraPosition();
|
||||||
|
|
||||||
|
// Use a raycast to determine occlusion.
|
||||||
|
GameConnection *conn = GameConnection::getConnectionToServer();
|
||||||
|
if ( !conn )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const bool fps = conn->isFirstPerson();
|
||||||
|
GameBase *control = conn->getControlObject();
|
||||||
|
if ( control && fps )
|
||||||
|
control->disableCollision();
|
||||||
|
|
||||||
|
RayInfo rayInfo;
|
||||||
|
|
||||||
|
U32 LosMask = STATIC_COLLISION_TYPEMASK |
|
||||||
|
ShapeBaseObjectType |
|
||||||
|
StaticShapeObjectType |
|
||||||
|
ItemObjectType;
|
||||||
|
|
||||||
|
F32 lightVisible = 0.0f;
|
||||||
|
|
||||||
|
if ( !gClientContainer.castRay( camPos, lightPos, LosMask, &rayInfo ) )
|
||||||
|
|
||||||
|
lightVisible = 1.0f ;
|
||||||
|
|
||||||
|
|
||||||
|
if ( control && fps )
|
||||||
|
control->enableCollision();
|
||||||
|
|
||||||
|
return lightVisible;
|
||||||
|
}
|
||||||
|
|
||||||
void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *inTexViewport )
|
void PostEffect::_setupTexture( U32 stage, GFXTexHandle &inputTex, const RectI *inTexViewport )
|
||||||
{
|
{
|
||||||
const String &texFilename = mTexFilename[ stage ];
|
const String &texFilename = mTexFilename[ stage ];
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,9 @@ protected:
|
||||||
|
|
||||||
F32 mRenderPriority;
|
F32 mRenderPriority;
|
||||||
|
|
||||||
|
/// Test sun visibility feature for sunBokeh
|
||||||
|
F32 _testVisibility( const SceneRenderState *state );
|
||||||
|
|
||||||
/// This is true if the effect has been succesfully
|
/// This is true if the effect has been succesfully
|
||||||
/// initialized and all requirements are met for use.
|
/// initialized and all requirements are met for use.
|
||||||
bool mIsValid;
|
bool mIsValid;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue