mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Merge branch 'GlowingParticles' of https://github.com/lukaspj/Torque3D into glowParticles
Conflicts: Engine/source/renderInstance/renderParticleMgr.cpp
This commit is contained in:
commit
98048fd974
11 changed files with 179 additions and 63 deletions
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "platform/platform.h"
|
||||
#include "renderInstance/renderGlowMgr.h"
|
||||
#include "renderInstance/renderParticleMgr.h"
|
||||
|
||||
#include "scene/sceneManager.h"
|
||||
#include "scene/sceneRenderState.h"
|
||||
|
|
@ -89,6 +90,9 @@ RenderGlowMgr::RenderGlowMgr()
|
|||
{
|
||||
notifyType( RenderPassManager::RIT_Decal );
|
||||
notifyType( RenderPassManager::RIT_Translucent );
|
||||
notifyType( RenderPassManager::RIT_Particle );
|
||||
|
||||
mParticleRenderMgr = NULL;
|
||||
|
||||
mNamedTarget.registerWithName( "glowbuffer" );
|
||||
mTargetSizeType = WindowSize;
|
||||
|
|
@ -122,6 +126,14 @@ void RenderGlowMgr::addElement( RenderInst *inst )
|
|||
// manner so we can skip glow in a non-diffuse render pass.
|
||||
//if ( !mParentManager->getSceneManager()->getSceneState()->isDiffusePass() )
|
||||
//return RenderBinManager::arSkipped;
|
||||
ParticleRenderInst *particleInst = NULL;
|
||||
if(inst->type == RenderPassManager::RIT_Particle)
|
||||
particleInst = static_cast<ParticleRenderInst*>(inst);
|
||||
if(particleInst && particleInst->glow)
|
||||
{
|
||||
internalAddElement(inst);
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip it if we don't have a glowing material.
|
||||
BaseMatInstance *matInst = getMaterial( inst );
|
||||
|
|
@ -171,7 +183,31 @@ void RenderGlowMgr::render( SceneRenderState *state )
|
|||
|
||||
for( U32 j=0; j<binSize; )
|
||||
{
|
||||
MeshRenderInst *ri = static_cast<MeshRenderInst*>(mElementList[j].inst);
|
||||
RenderInst *_ri = mElementList[j].inst;
|
||||
if(_ri->type == RenderPassManager::RIT_Particle)
|
||||
{
|
||||
// Find the particle render manager (if we don't have it)
|
||||
if(mParticleRenderMgr == NULL)
|
||||
{
|
||||
RenderPassManager *rpm = state->getRenderPass();
|
||||
for( U32 i = 0; i < rpm->getManagerCount(); i++ )
|
||||
{
|
||||
RenderBinManager *bin = rpm->getManager(i);
|
||||
if( bin->getRenderInstType() == RenderParticleMgr::RIT_Particles )
|
||||
{
|
||||
mParticleRenderMgr = reinterpret_cast<RenderParticleMgr *>(bin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParticleRenderInst *ri = static_cast<ParticleRenderInst*>(_ri);
|
||||
mParticleRenderMgr->renderParticle(ri, state);
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
|
||||
MeshRenderInst *ri = static_cast<MeshRenderInst*>(_ri);
|
||||
|
||||
setupSGData( ri, sgData );
|
||||
|
||||
|
|
@ -191,6 +227,9 @@ void RenderGlowMgr::render( SceneRenderState *state )
|
|||
U32 a;
|
||||
for( a=j; a<binSize; a++ )
|
||||
{
|
||||
if (mElementList[a].inst->type == RenderPassManager::RIT_Particle)
|
||||
break;
|
||||
|
||||
MeshRenderInst *passRI = static_cast<MeshRenderInst*>(mElementList[a].inst);
|
||||
|
||||
if ( newPassNeeded( ri, passRI ) )
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#ifndef _TEXTARGETBIN_MGR_H_
|
||||
#include "renderInstance/renderTexTargetBinManager.h"
|
||||
#endif
|
||||
#include <renderInstance/renderParticleMgr.h>
|
||||
|
||||
|
||||
class PostEffect;
|
||||
|
|
@ -82,7 +83,7 @@ protected:
|
|||
};
|
||||
|
||||
SimObjectPtr<PostEffect> mGlowEffect;
|
||||
|
||||
RenderParticleMgr *mParticleRenderMgr;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -399,64 +399,7 @@ void RenderParticleMgr::renderInstance(ParticleRenderInst *ri, SceneRenderState
|
|||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mModelViewProjSC, *ri->modelViewProj );
|
||||
}
|
||||
|
||||
// We want to turn everything into variation on a pre-multiplied alpha blend
|
||||
F32 alphaFactor = 0.0f, alphaScale = 1.0f;
|
||||
switch(ri->blendStyle)
|
||||
{
|
||||
// SrcAlpha, InvSrcAlpha
|
||||
case ParticleRenderInst::BlendNormal:
|
||||
alphaFactor = 1.0f;
|
||||
break;
|
||||
|
||||
// SrcAlpha, One
|
||||
case ParticleRenderInst::BlendAdditive:
|
||||
alphaFactor = 1.0f;
|
||||
alphaScale = 0.0f;
|
||||
break;
|
||||
|
||||
// SrcColor, One
|
||||
case ParticleRenderInst::BlendGreyscale:
|
||||
alphaFactor = -1.0f;
|
||||
alphaScale = 0.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mAlphaFactorSC, alphaFactor );
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mAlphaScaleSC, alphaScale );
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mFSModelViewProjSC, *ri->modelViewProj );
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mOneOverFarSC, 1.0f / state->getFarPlane() );
|
||||
|
||||
if ( mParticleShaderConsts.mOneOverSoftnessSC->isValid() )
|
||||
{
|
||||
F32 oneOverSoftness = 1.0f;
|
||||
if ( ri->softnessDistance > 0.0f )
|
||||
oneOverSoftness = 1.0f / ( ri->softnessDistance / state->getFarPlane() );
|
||||
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mOneOverSoftnessSC, oneOverSoftness );
|
||||
}
|
||||
|
||||
GFX->setShader( mParticleShader );
|
||||
GFX->setShaderConstBuffer( mParticleShaderConsts.mShaderConsts );
|
||||
|
||||
GFX->setTexture( mParticleShaderConsts.mSamplerDiffuse->getSamplerRegister(), ri->diffuseTex );
|
||||
|
||||
// Set up the prepass texture.
|
||||
if ( mParticleShaderConsts.mPrePassTargetParamsSC->isValid() )
|
||||
{
|
||||
GFXTextureObject *texObject = mPrepassTarget ? mPrepassTarget->getTexture(0) : NULL;
|
||||
GFX->setTexture( mParticleShaderConsts.mSamplerPrePassTex->getSamplerRegister(), texObject );
|
||||
|
||||
Point4F rtParams( 0.0f, 0.0f, 1.0f, 1.0f );
|
||||
if ( texObject )
|
||||
ScreenSpace::RenderTargetParameters(texObject->getSize(), mPrepassTarget->getViewport(), rtParams);
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mPrePassTargetParamsSC, rtParams );
|
||||
}
|
||||
|
||||
GFX->setPrimitiveBuffer( *ri->primBuff );
|
||||
GFX->setVertexBuffer( *ri->vertBuff );
|
||||
|
||||
GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, ri->count * 4, 0, ri->count * 2 );
|
||||
renderParticle(ri, state);
|
||||
}
|
||||
else if(ri->systemState == PSS_AwaitingCompositeDraw)
|
||||
{
|
||||
|
|
@ -530,6 +473,68 @@ void RenderParticleMgr::renderInstance(ParticleRenderInst *ri, SceneRenderState
|
|||
}
|
||||
}
|
||||
|
||||
void RenderParticleMgr::renderParticle(ParticleRenderInst* ri, SceneRenderState* state)
|
||||
{
|
||||
// We want to turn everything into variation on a pre-multiplied alpha blend
|
||||
F32 alphaFactor = 0.0f, alphaScale = 1.0f;
|
||||
switch(ri->blendStyle)
|
||||
{
|
||||
// SrcAlpha, InvSrcAlpha
|
||||
case ParticleRenderInst::BlendNormal:
|
||||
alphaFactor = 1.0f;
|
||||
break;
|
||||
|
||||
// SrcAlpha, One
|
||||
case ParticleRenderInst::BlendAdditive:
|
||||
alphaFactor = 1.0f;
|
||||
alphaScale = 0.0f;
|
||||
break;
|
||||
|
||||
// SrcColor, One
|
||||
case ParticleRenderInst::BlendGreyscale:
|
||||
alphaFactor = -1.0f;
|
||||
alphaScale = 0.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mAlphaFactorSC, alphaFactor );
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mAlphaScaleSC, alphaScale );
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mFSModelViewProjSC, *ri->modelViewProj );
|
||||
mParticleShaderConsts.mShaderConsts->setSafe( mParticleShaderConsts.mOneOverFarSC, 1.0f / state->getFarPlane() );
|
||||
|
||||
if ( mParticleShaderConsts.mOneOverSoftnessSC->isValid() )
|
||||
{
|
||||
F32 oneOverSoftness = 1.0f;
|
||||
if ( ri->softnessDistance > 0.0f )
|
||||
oneOverSoftness = 1.0f / ( ri->softnessDistance / state->getFarPlane() );
|
||||
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mOneOverSoftnessSC, oneOverSoftness );
|
||||
}
|
||||
|
||||
GFX->setShader( mParticleShader );
|
||||
GFX->setShaderConstBuffer( mParticleShaderConsts.mShaderConsts );
|
||||
|
||||
GFX->setTexture( mParticleShaderConsts.mSamplerDiffuse->getSamplerRegister(), ri->diffuseTex );
|
||||
|
||||
// Set up the prepass texture.
|
||||
if ( mParticleShaderConsts.mPrePassTargetParamsSC->isValid() )
|
||||
{
|
||||
GFXTextureObject *texObject = mPrepassTarget ? mPrepassTarget->getTexture(0) : NULL;
|
||||
GFX->setTexture( mParticleShaderConsts.mSamplerPrePassTex->getSamplerRegister(), texObject );
|
||||
|
||||
Point4F rtParams( 0.0f, 0.0f, 1.0f, 1.0f );
|
||||
if ( texObject )
|
||||
ScreenSpace::RenderTargetParameters(texObject->getSize(), mPrepassTarget->getViewport(), rtParams);
|
||||
|
||||
mParticleShaderConsts.mShaderConsts->set( mParticleShaderConsts.mPrePassTargetParamsSC, rtParams );
|
||||
}
|
||||
|
||||
GFX->setPrimitiveBuffer( *ri->primBuff );
|
||||
GFX->setVertexBuffer( *ri->vertBuff );
|
||||
|
||||
GFX->drawIndexedPrimitive( GFXTriangleList, 0, 0, ri->count * 4, 0, ri->count * 2 );
|
||||
}
|
||||
|
||||
bool RenderParticleMgr::_initShader()
|
||||
{
|
||||
ShaderData *shaderData = NULL;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ protected:
|
|||
// Not only a helper method, but a method for the RenderTranslucentMgr to
|
||||
// request a particle system draw
|
||||
void renderInstance(ParticleRenderInst *ri, SceneRenderState *state);
|
||||
|
||||
public:
|
||||
void renderParticle(ParticleRenderInst *ri, SceneRenderState *state);
|
||||
protected:
|
||||
bool mOffscreenRenderEnabled;
|
||||
|
||||
/// The prepass render target used for the
|
||||
|
|
|
|||
|
|
@ -392,6 +392,8 @@ struct ParticleRenderInst : public RenderInst
|
|||
/// The total particle count to render.
|
||||
S32 count;
|
||||
|
||||
bool glow;
|
||||
|
||||
/// The combined model, camera, and projection transform.
|
||||
const MatrixF *modelViewProj;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue