mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
sunBokeh feature added
This commit is contained in:
parent
5d52864c9f
commit
637a804fd7
6 changed files with 29 additions and 1 deletions
|
|
@ -121,6 +121,7 @@ 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 );
|
||||||
|
|
@ -445,6 +446,8 @@ 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;
|
||||||
|
|
@ -514,6 +517,7 @@ 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,6 +94,8 @@ 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:
|
||||||
|
|
||||||
|
|
@ -112,7 +114,7 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -655,6 +655,11 @@ 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,6 +109,10 @@ 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:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
#include "materials/shaderData.h"
|
#include "materials/shaderData.h"
|
||||||
#include "postFx/postEffectManager.h"
|
#include "postFx/postEffectManager.h"
|
||||||
#include "postFx/postEffectVis.h"
|
#include "postFx/postEffectVis.h"
|
||||||
|
#include "environment/scatterSky.h" //sunBokeh feature
|
||||||
|
|
||||||
using namespace Torque;
|
using namespace Torque;
|
||||||
|
|
||||||
|
|
@ -303,6 +304,7 @@ PostEffect::PostEffect()
|
||||||
mScreenSunPosSC( NULL ),
|
mScreenSunPosSC( NULL ),
|
||||||
mLightDirectionSC( NULL ),
|
mLightDirectionSC( NULL ),
|
||||||
mCameraForwardSC( NULL ),
|
mCameraForwardSC( NULL ),
|
||||||
|
mSunVisibilitySC( NULL ), //sunBokeh feature
|
||||||
mAccumTimeSC( NULL ),
|
mAccumTimeSC( NULL ),
|
||||||
mDeltaTimeSC( NULL ),
|
mDeltaTimeSC( NULL ),
|
||||||
mInvCameraMatSC( NULL )
|
mInvCameraMatSC( NULL )
|
||||||
|
|
@ -602,6 +604,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
|
||||||
mScreenSunPosSC = mShader->getShaderConstHandle( "$screenSunPos" );
|
mScreenSunPosSC = mShader->getShaderConstHandle( "$screenSunPos" );
|
||||||
mLightDirectionSC = mShader->getShaderConstHandle( "$lightDirection" );
|
mLightDirectionSC = mShader->getShaderConstHandle( "$lightDirection" );
|
||||||
mCameraForwardSC = mShader->getShaderConstHandle( "$camForward" );
|
mCameraForwardSC = mShader->getShaderConstHandle( "$camForward" );
|
||||||
|
mSunVisibilitySC = mShader->getShaderConstHandle( "$sunVisibility" ); //sunBokeh feature
|
||||||
|
|
||||||
mAccumTimeSC = mShader->getShaderConstHandle( "$accumTime" );
|
mAccumTimeSC = mShader->getShaderConstHandle( "$accumTime" );
|
||||||
mDeltaTimeSC = mShader->getShaderConstHandle( "$deltaTime" );
|
mDeltaTimeSC = mShader->getShaderConstHandle( "$deltaTime" );
|
||||||
|
|
@ -849,6 +852,15 @@ void PostEffect::_setupConstants( const SceneRenderState *state )
|
||||||
mat.inverse();
|
mat.inverse();
|
||||||
mShaderConsts->set( mInvCameraMatSC, mat, mInvCameraMatSC->getType() );
|
mShaderConsts->set( mInvCameraMatSC, mat, mInvCameraMatSC->getType() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( mSunVisibilitySC->isValid() ) //sunBokeh feature
|
||||||
|
{
|
||||||
|
ScatterSky* pSky = dynamic_cast<ScatterSky*>(Sim::findObject("Himmel"));
|
||||||
|
if(pSky)
|
||||||
|
mShaderConsts->set( mSunVisibilitySC, pSky->getSunVisibility() );
|
||||||
|
else
|
||||||
|
mShaderConsts->set( mSunVisibilitySC, 0.0f );
|
||||||
|
}
|
||||||
|
|
||||||
} // if ( state )
|
} // if ( state )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ protected:
|
||||||
GFXShaderConstHandle *mAccumTimeSC;
|
GFXShaderConstHandle *mAccumTimeSC;
|
||||||
GFXShaderConstHandle *mDeltaTimeSC;
|
GFXShaderConstHandle *mDeltaTimeSC;
|
||||||
GFXShaderConstHandle *mInvCameraMatSC;
|
GFXShaderConstHandle *mInvCameraMatSC;
|
||||||
|
GFXShaderConstHandle *mSunVisibilitySC; //sunBokeh feature
|
||||||
|
|
||||||
bool mAllowReflectPass;
|
bool mAllowReflectPass;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue