diff --git a/Engine/source/T3D/lightFlareData.cpp b/Engine/source/T3D/lightFlareData.cpp index 2fae80fa9..8faf7d952 100644 --- a/Engine/source/T3D/lightFlareData.cpp +++ b/Engine/source/T3D/lightFlareData.cpp @@ -121,6 +121,7 @@ LightFlareData::LightFlareData() mElementCount( 0 ), mScale( 1.0f ), mOcclusionRadius( 0.0f ), + mVisibility( 1.0f ), //sunBokeh feature mRenderReflectPass( true ) { dMemset( mElementRect, 0, sizeof( RectF ) * MAX_ELEMENTS ); @@ -445,6 +446,8 @@ void LightFlareData::prepRender( SceneRenderState *state, LightFlareState *flare const RectI &viewport = GFX->getViewport(); 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. lightPosSS.x -= viewport.point.x; 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. // Modulate more in as appropriate. ColorF baseColor = ColorF::WHITE * lightSourceBrightnessScale * occlusionFade; + mVisibility = lightSourceBrightnessScale * fadeInOutScale * occlusionFade; //sunBokeh feature // Setup the vertex buffer for the maximum flare elements. const U32 vertCount = 4 * mElementCount; diff --git a/Engine/source/T3D/lightFlareData.h b/Engine/source/T3D/lightFlareData.h index 333bf1bf5..cd9b4d509 100644 --- a/Engine/source/T3D/lightFlareData.h +++ b/Engine/source/T3D/lightFlareData.h @@ -94,6 +94,8 @@ public: /// Submits render instances for corona and flare effects. void prepRender( SceneRenderState *state, LightFlareState *flareState ); + /// sunBokeh feature + F32 getVisibility() const { return mVisibility; } protected: @@ -112,7 +114,7 @@ protected: static Point3F sBasePoints[4]; // Fields... - + F32 mVisibility; //sunBokeh feature F32 mScale; bool mFlareEnabled; String mFlareTextureName; diff --git a/Engine/source/environment/scatterSky.cpp b/Engine/source/environment/scatterSky.cpp index 3e2d2d890..8df2d6d46 100644 --- a/Engine/source/environment/scatterSky.cpp +++ b/Engine/source/environment/scatterSky.cpp @@ -655,6 +655,11 @@ void ScatterSky::prepRenderImage( SceneRenderState *state ) 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. if ( mFlareData && mNightInterpolant != 1.0f ) diff --git a/Engine/source/environment/scatterSky.h b/Engine/source/environment/scatterSky.h index 66177851d..37bc5c7a4 100644 --- a/Engine/source/environment/scatterSky.h +++ b/Engine/source/environment/scatterSky.h @@ -109,6 +109,10 @@ public: F32 getAzimuth() const { return mSunAzimuth; } /// 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(mFlareData) return mFlareData->getVisibility(); else return 0; } protected: diff --git a/Engine/source/postFx/postEffect.cpp b/Engine/source/postFx/postEffect.cpp index 62c35baf6..4988eb9aa 100644 --- a/Engine/source/postFx/postEffect.cpp +++ b/Engine/source/postFx/postEffect.cpp @@ -44,6 +44,7 @@ #include "materials/shaderData.h" #include "postFx/postEffectManager.h" #include "postFx/postEffectVis.h" +#include "environment/scatterSky.h" //sunBokeh feature using namespace Torque; @@ -303,6 +304,7 @@ PostEffect::PostEffect() mScreenSunPosSC( NULL ), mLightDirectionSC( NULL ), mCameraForwardSC( NULL ), + mSunVisibilitySC( NULL ), //sunBokeh feature mAccumTimeSC( NULL ), mDeltaTimeSC( NULL ), mInvCameraMatSC( NULL ) @@ -602,6 +604,7 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) mScreenSunPosSC = mShader->getShaderConstHandle( "$screenSunPos" ); mLightDirectionSC = mShader->getShaderConstHandle( "$lightDirection" ); mCameraForwardSC = mShader->getShaderConstHandle( "$camForward" ); + mSunVisibilitySC = mShader->getShaderConstHandle( "$sunVisibility" ); //sunBokeh feature mAccumTimeSC = mShader->getShaderConstHandle( "$accumTime" ); mDeltaTimeSC = mShader->getShaderConstHandle( "$deltaTime" ); @@ -849,6 +852,15 @@ void PostEffect::_setupConstants( const SceneRenderState *state ) mat.inverse(); mShaderConsts->set( mInvCameraMatSC, mat, mInvCameraMatSC->getType() ); } + + if( mSunVisibilitySC->isValid() ) //sunBokeh feature + { + ScatterSky* pSky = dynamic_cast(Sim::findObject("Himmel")); + if(pSky) + mShaderConsts->set( mSunVisibilitySC, pSky->getSunVisibility() ); + else + mShaderConsts->set( mSunVisibilitySC, 0.0f ); + } } // if ( state ) diff --git a/Engine/source/postFx/postEffect.h b/Engine/source/postFx/postEffect.h index 812738ba3..06b951600 100644 --- a/Engine/source/postFx/postEffect.h +++ b/Engine/source/postFx/postEffect.h @@ -141,6 +141,7 @@ protected: GFXShaderConstHandle *mAccumTimeSC; GFXShaderConstHandle *mDeltaTimeSC; GFXShaderConstHandle *mInvCameraMatSC; + GFXShaderConstHandle *mSunVisibilitySC; //sunBokeh feature bool mAllowReflectPass;