VR-Vantage
Loading...
Searching...
No Matches
exampleEffectsPlugin

Overview

When VR-Vantage destroys an entity (typically due to a DIS or HLA/RPR event) it does a number of things. It switches the model from its normal state to it's damaged state. It adds / starts a detonation effect (which is a particle system) that looks like an explosion, with pieces of a generic vehicle flying through the air; it makes a previously placed flame effect on the entity visible(also a particle system); and it makes a previously placed smoke plume visible (particle system).

Expected Result

Effect Plugin Result

Example details

This example loads a terrain (ground_DB II); creates a truck entity using the DtEntityFacade class; shows how to switch between states in a model; and how to create, add and control the three different effects. It also demonstrates how to extend the DtOsgParticleSystemModel to include the ability to modify the model's color through a shader (using code from exampleCustomShaders). Control of the entity's damage state and the smoke color when displayed are bound to keyboard commands.

The method createEntityFacade() creates and add the three particle systems to the entity; one for the detonation, one for the flames, and one for the smoke plume. The smoke plume uses the extended particle system that allows the color to be changed using a shader (see further down). All the effects are made invisible.

The method toggleDamage() checks the current state, and then makes all the effects visible or invisible to create the destroyed or restored effects. The detonation effect is special since it has a specific start and end rather than just a loop; so it is restarted in toggleDamage() when the entity is destroyed. toggleDamage() also toggles the internal model switch to show its damaged state or normal state. This method is called when the 'x' key is pressed. The key binding is set up in the plugin initialization code (found in exampleEffectsPluginInit.cxx). This assumes that the model has been configured with comments on switch node that controls the damage state using the WRM Specification (Fred, you can point to that).

To add the shader from exampleCustomShader that changes the color of the smoke (and all other particle systems that use the new VR-Vantage particle system system), the DtOsgParticleSystemModel class is extended. This class has a distributed (agent-based) interface and is agent-created; therefore a .ocdx file has to be created for it as well (using the dcgen application). This file is used to generate the related agent classes for the object.

The extended class overrides the setInstance() method in the model to be notified when the model instance is created or destroyed, and uses it to set up the shader manager from the shader example. The changeColorOverride() method is added to its distributed interface (so its defined in the .ocdx file as well) and it calls the shader manager's changeColorOverride() method. By extending the distributed model object in this manner, the color change ability will work on remote displays as well as master displays. A final changeColorOverride() method is added to the DtExampleEffectsDriver, which is bound to several different keys (r, <shift-r>, g, <shift-g>, b, and <shift-b>); it in turn calls the equivalent colorChangeOverride() method in the extended particle system.

Building the Example

VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.

Running the Example

This example is a plug-in. You can run it by running ./bin64/exampleEffectPlugin_stealth.bat (on Windows) or ./bin64/exampleEffectPlugin_stealth.sh (on Linux). Use the key "x" to toggle the destroyed state and use the keys r, <shift-r>, g, <shift-g>, b, and <shift-b> to change the color of the smoke. The example plug-in is loaded on a master display. Note that any remote displays should also be configured to load the plug-in in order to see the extended distributed model.

For more information about running examples, please see Running Applications and Examples.

Example Source Files


DtExampleEffectsDriver.cxx

/*****************************************************************************
* Copyright (c) 2022 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#include <vrvCore/DtDe.h>
// Use the VR-Vantage namespace.
// All classes in VR-Vantage are in this namespace.
using namespace makVrv;
//
// Driver implementation
//
: makVrv::DtDriver( am, "DtExampleEffectsDriver" )
, myEntityFacade( 0 )
, myDamagedFlag( false )
, myFlamesAgent( 0 )
, mySmokePlumeAgent( 0 )
, myDetonationAgent( 0 )
{
}
{
}
const std::string& DtExampleEffectsDriver::className() const
{
static std::string name = "DtExampleEffectsDriver";
return name;
}
{
{
{
myDamagedFlag = false;
}
else
{
myEntityFacade->findFacadeFor3d()->setSwitchState(
DtModelSemanticsMapper::States::damage, 3 );
myFlamesAgent->setVisible( true );
mySmokePlumeAgent->setVisible( true );
// Restart the detonation effect
myDetonationAgent->setVisible( true );
myDamagedFlag = true;
}
}
}
{
// Load Ground_DB II programatically.
DtScene& sceneDriver = myAgentManager.de().scene();
std::string groundDbPath = myAgentManager.de().dePathConfiguration().sharedDataPath();
groundDbPath += "/TerrainData/TerrainConfiguration/Ground_DB II.mtf";
sceneDriver.loadTerrain( groundDbPath );
// Create an element that represents the entity.
DtElementID parentElementId = 0;
std::string entityDisplayName = "M-939A Truck";
DtElementID elementId = myAgentManager.createNewUniqueId();
reportElementCreated( elementId, parentElementId, DtElementEntry::Entity );
reportElementAttribute(elementId, new DtElementAttributeElementSubtype(DtElementAttributes::Friendly));
reportElementAttribute(elementId, new DtElementAttributeDriverType("Example Effects Driver"));
reportElementAttribute( elementId, new DtElementAttributeDisplayName(entityDisplayName) );
// Instantiate the entity facade.
const DtModelSetRealizationManager::ModelSetRealizations& setsToRealize =
myAgentManager.de().sharedState().modelSetRealizationManager().modelSetRealizations();
myEntityFacade = createEntityFacade( myAgentManager, elementId, setsToRealize, true );
myEntityFacade->setPosition( DtVector(-250.0, -750.0, 30.) );
myEntityFacade->setOrientation( DtTaitBryan(0., 0., 0.) );
myEntityFacade->setGroundClampingMode( DtGroundClampingUpdater::GroundClampingMode::ClampPositionAndUpright );
myEntityFacade->SetGroundClampingCullCylinderRadiusScale(1000.0);
// Attach to entity.
std::vector<DtUniqueID> objects;
objects.push_back( myEntityFacade->elementId() );
DtInputDriver& inputDriver = myAgentManager.de().driverManager().inputDriver();
inputDriver.currentObserver()->setPrimaryAttachment( objects );
return true;
}
{
{
}
delete myFlamesAgent;
return true;
}
{
return true;
}
{
stop();
start();
}
const DtModelSetRealizationManager::ModelSetRealizations& modelSets, bool distribute )
{
DtEntityFacade* facade = new DtEntityFacade( am,
DtSharedSettingsManager::instance( am.de() ), elementId, modelSets,
distribute );
// Initialize the 3D facade.
DtEntity3dFacade* facade3d = facade->findFacadeFor3d();
if ( facade3d )
{
DtModelSetId modelSet = facade3d->modelSet();
facade3d->setArticulatedModelDefinition("WheeledM-939A25-TonTruck");
// The clean thing to do here would be to extend DtEntityFacade/DtEntity3dFacade
// and add these to it. But for the sake of example its fine to let the driver
// create and own them.
// create the flame effect
myFlamesAgent = DtParticleSystemModelAgent::create( am );
myFlamesAgent->setModelDefinition( "Flames" );
// attach it to the entity
facade3d->sceneObjectAgent().addModel( myFlamesAgent, DtObserverSettingsManager::ShowFire );
// and turn it off by default
myFlamesAgent->setVisible( false );
// For the smoke plume, we use our extended particle system that will allow us to modify
// its color
mySmokePlumeAgent = MyParticleSystemModelAgent::create( am );
mySmokePlumeAgent->setModelDefinition( "SmokePlume" );
facade3d->sceneObjectAgent().addModel( mySmokePlumeAgent, DtObserverSettingsManager::ShowSmokePlumes );
mySmokePlumeAgent->setVisible( false );
// and we'll use this for an initial detonation effect
myDetonationAgent = DtParticleSystemModelAgent::create( am );
myDetonationAgent->setModelDefinition( "DetonationEntityImpact" );
facade3d->sceneObjectAgent().addModel( myDetonationAgent, DtObserverSettingsManager::ShowDetonations );
myDetonationAgent->setVisible( false );
mySceneObjectIds[(int)modelSet] = facade3d->sceneObjectAgent().uniqueId();
}
return facade;
}
void DtExampleEffectsDriver::changeColorOverride(int color, float deltaChange)
{
{
mySmokePlumeAgent->changeColorOverride( color, deltaChange );
}
}
Contains makVrv:DtAgentManager class.
Contains makVrv::DtDataBank class.
Contains makVrv::DtDe class.
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtElementAttributes class.
Contains makVrv::DtElementData class.
Contains makVrv::DtEntity3dFacade class.
Contains makVrv::DtEntityFacade class.
Contains makVrv::DtInputDriver class.
Contains makVrv::DtModelSemanticsMapper class.
Contains makVrv::DtObserver class.
Contains makVrv::DtObserverSettingsManager class.
Contains makVrv::DtScene class.
virtual bool onStart()
makVrv::DtEntityFacade * createEntityFacade(makVrv::DtAgentManager &am, makVrv::DtElementID elementId, const makVrv::DtModelSetRealizationManager::ModelSetRealizations &modelSets, bool distribute)
virtual void toggleDamage(makVrv::DtDe &de)
Function for changing the state of the entity.
virtual bool onTick()
makVrv::DtParticleSystemModelAgent * myDetonationAgent
Definition DtExampleEffectsDriver.h:94
virtual void changeColorOverride(int color, float deltaChange)
SceneObjectIdsByModelSet mySceneObjectIds
Definition DtExampleEffectsDriver.h:83
bool myDamagedFlag
Definition DtExampleEffectsDriver.h:87
makVrv::MyParticleSystemModelAgent * mySmokePlumeAgent
Definition DtExampleEffectsDriver.h:93
virtual bool onStop()
virtual const std::string & className() const
makVrv::DtParticleSystemModelAgent * myFlamesAgent
Definition DtExampleEffectsDriver.h:92
makVrv::DtEntityFacade * myEntityFacade
Definition DtExampleEffectsDriver.h:85
DtExampleEffectsDriver(makVrv::DtAgentManager &am)
CTOR.
virtual ~DtExampleEffectsDriver()
Virtual DTOR.
virtual void slot_displayEngineAdded(const makVrv::DtDeRecord &igRecord)
DtUniqueID uniqueId() const
inline accessor
Definition DtAgent.inl:55
The DtAgentManager manages the distributed scene object framework. This includes the objects and upda...
Definition DtAgentManager.h:39
DtDe & de()
Get the scene manager's Ig object.
Definition DtAgentManager.h:107
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
A Record of an IG instance.
Definition DtDeRecord.h:25
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
DtAgentManager & myAgentManager
Definition DtDriver.h:190
void reportElementCreated(DtElementID id, DtElementID parentId, DtElementEntry::ElementType type)
Report an element created.
void start()
Start the driver. Called by the Master Scene. Calls installAccessories().
void stop()
Stop the driver. Called by the Master Scene. Calls uninstallAccessories().
void reportElementDestroyed(DtElementID id)
Report an element destroyed.
void reportElementAttribute(DtElementID id, DtElementAttribute *attribute)
Report an element attribute changed.
virtual void setSwitchState(int switchToSet, int value)
Sets a switch state.
Definition DtEntity3dFacade.inl:115
DtSceneObjectAgent & sceneObjectAgent()
Returns the scene object agent for this facade.
Definition DtEntity3dFacade.inl:153
virtual void setArticulatedModelDefinition(const std::string &modelName)
Set the entity's model definition names.
Definition DtEntity3dFacade.inl:294
virtual DtModelSetId modelSet() const
Returns the model set being visualized.
Definition DtEntity3dFacade.inl:148
The DtEntityFacade is a facade around agents that make up an entity. This entity facade represents a ...
Definition DtEntityFacade.h:36
const DtEntity3dFacade * findFacadeFor3d() const
Definition DtEntityFacade.inl:125
DtObserver * currentObserver() const
virtual void setVisible(bool isVisible)=0
Set the model visible or invisible.
std::map< DtModelSetId, bool > ModelSetRealizations
Definition DtModelSetRealizationManager.h:42
void setPrimaryAttachment(const ElementList &elements)
bool loadTerrain(const DtUnicode &filePath)
Load the terrain from a file.
virtual void addModel(makVrv::DtModelAgent *modelInstanceOwner, int visualizerType)=0
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtUniqueElementAttribute< std::string, DtElementAttributes::DisplayName > DtElementAttributeDisplayName
Definition DtElementAttributes.h:88
DtModelSetId
Definition DtModelSetEnums.h:20
DtUniqueID DtElementID
Definition DtUniqueID.h:23
DtUniqueElementAttribute< unsigned int, DtElementAttributes::ElementSubtype > DtElementAttributeElementSubtype
Definition DtElementAttributes.h:121
DtUniqueElementAttribute< bool, DtElementAttributes::ObjectVisibility > DtElementAttributeVisibility
Definition DtElementAttributes.h:97
DtUniqueElementAttribute< std::string, DtElementAttributes::DriverType > DtElementAttributeDriverType
Definition DtElementAttributes.h:118
@ damage
Definition DtModelSemanticsMapper.h:45

DtExampleEffectsDriver.h

/*****************************************************************************
* Copyright (c) 2023 MAK Technologies, Inc.
* All rights reserved.
*****************************************************************************/
#pragma once
#include <unordered_map>
#include <matrix/vlTaitBryan.h>
#include <matrix/vlVector.h>
namespace makVrv
{
class DtDe;
class DtEntityFacade;
class DtParticleSystemModelAgent;
class MyParticleSystemModelAgent;
}
{
public:
virtual const std::string& className() const;
virtual bool onStart();
virtual bool onStop();
virtual bool onTick();
virtual void slot_displayEngineAdded( const makVrv::DtDeRecord& igRecord );
virtual void toggleDamage(makVrv::DtDe& de);
// Function for connecting our color-based key bindings to the
// particile system shader manager
virtual void changeColorOverride(int color, float deltaChange);
protected:
protected:
typedef std::unordered_map<int,makVrv::DtUniqueID> SceneObjectIdsByModelSet;
SceneObjectIdsByModelSet mySceneObjectIds;
makVrv::DtEntityFacade* myEntityFacade;
bool myDamagedFlag;
// Agents for creating the flames, smoke plume, and detonation effects. Note
// that for the smoke plume, we use our extended MyParticleSystemModel, which
// creates a shader to modify the smoke plume color
};
Contains makVrv:DtDriver class.
Contains makVrv::DtModelSetRealizationManager class.
Definition DtExampleEffectsDriver.h:33
virtual const std::string & className() const =0
Get this driver's class name.
virtual void slot_displayEngineAdded(const DtDeRecord &igRecord)
Called when a display engine is added. Override if you want the driver to do something when a display...
virtual bool onStart()=0
Start the host output. Create all objects for an existing host connection.
virtual bool onTick()=0
Tick.
virtual bool onStop()=0
Stop the host output. All scene object created by the host should be destroyed.
Agent class for the scene object class: DtParticleSystemModel.
Definition DtParticleSystemModelAgent.hpp:25
Agent class for the scene object class: MyParticleSystemModel.
Definition MyParticleSystemModelAgent.hpp:25
Contains DLL export macros.
#define DT_DLL_EXAMPLEEFFECTSPLUGIN
Definition exampleEffectsPlugin.h:18

exampleEffectsPlugin.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
#ifdef _WIN32
#ifdef EXAMPLEEFFECTSPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEEFFECTSPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEEFFECTSPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEEFFECTSPLUGIN
#endif

exampleEffectsPluginInit.cxx

/******************************************************************************
** Copyright (c) 2024 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <vrvCore/DtDe.h>
{
return true;
}
namespace makVrv
{
{
static vrvSignalsLib::connection postInitializeConnection;
void installDriverAndKeyBindings(DtDe& de)
{
postInitializeConnection.disconnect();
// Create example comm lines driver.
de.agentManager() );
// The driver is now owned by the display engine. Do not delete it.
de.driverManager().addDriver( driver );
// Start the driver, creating the agent.
de.driverManager().startDriver( driver );
// The input driver responds to input events by calling key functions. To
// bind a key to an arbitrary function, there are two steps:
// 1. Create a KeyFunction that calls the desired function and add it
// to the input driver
// 2. Add a key binding from some key to the KeyFunction defined in step 1
// to the keymap
DtInputDriver& inputDriver = de.driverManager().inputDriver();
// Create the Key Functions
keyMapManager.addKeyFunction( "Toggle Damage", boost::bind(
&DtExampleEffectsDriver::toggleDamage, driver, std::ref(de)),
keyMapManager.addKeyFunction( "Inc Red", boost::bind(
keyMapManager.addKeyFunction( "Inc Green", boost::bind(
keyMapManager.addKeyFunction( "Inc Blue", boost::bind(
keyMapManager.addKeyFunction( "Dec Red", boost::bind(
keyMapManager.addKeyFunction( "Dec Green", boost::bind(
keyMapManager.addKeyFunction( "Dec Blue", boost::bind(
DtKeyMap* obsFrame = keyMapManager.findKeyMap( "Observer Frame" );
// Bind the above key functions to some keys in the default
// ("Observer Frame") key map
if ( obsFrame )
{
// Map function to toggle the entity damage state
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_X, "Toggle Damage" );
//map functions for modifying the color of the smoke
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_R, "Inc Red" , DtKeyState::NO_MODIFIER, true);
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_G, "Inc Green", DtKeyState::NO_MODIFIER, true);
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_B, "Inc Blue", DtKeyState::NO_MODIFIER, true);
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_R, "Dec Red" , DtKeyState::SHIFT_MODIFIER, true);
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_G, "Dec Green" , DtKeyState::SHIFT_MODIFIER, true);
inputDriver.addKeyBinding( obsFrame, DtKeyState::KEY_B, "Dec Blue" , DtKeyState::SHIFT_MODIFIER, true);
}
// Don't show the startup dialog for selecting a terrain.
DtQtDeMainWindow& mainWindow = dynamic_cast<DtQtDeMainWindow&>(mw);
mainWindow.hideStartupDialog();
}
void init(DtDe& de)
{
// We only want to create the driver if we are running in master mode.
if (de.isInMasterMode())
{
// The accessory must be created after the DE's initialization is
// finished, to make sure all the objects it uses exist.
postInitializeConnection = de.signal_postInitialize.connect(boost::bind(
&installDriverAndKeyBindings, std::ref(de) ));
}
}
}
}
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtDeMainWindow class.
Contains makVrv::DtKeyMap and related classes.
Contains makVrv::DtKeyMapManager class.
Contains makVrv::DtQtDeMainWindow class.
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
The abstract main window class.
Definition DtDeMainWindow.h:25
DtDeMainWindow & igMainWindow()
Use this accessor to lazily create the singleton instance of the DtDeMainWindow;.
static DtDeMainWindowProvider & instance(DtDe &de)
Get the main window provider instance for a DtDe.
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
void startDriver(DtDriver *driver)
Start a driver driver modifying the scene.
This class's main responsibility is to handle keyboard and mouse events from OSG (Qt events are route...
Definition DtInputDriver.h:46
void addKeyBinding(DtKeyMap *map, DtKeyState::KeyType key, const std::string &functionName, DtKeyState::KeyModifier modifiers=DtKeyState::NO_MODIFIER, bool replace=false, DtKeyEvent::KeyEventType eventType=DtKeyEvent::KEY_DOWN)
bind a key down or key up event (possibly modified) to a function name
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Miscellaneous
Definition DtKeyMapManager.h:45
@ Rendering
Definition DtKeyMapManager.h:43
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_X
Definition DtKeyState.h:79
@ KEY_B
Definition DtKeyState.h:57
@ KEY_G
Definition DtKeyState.h:62
@ KEY_R
Definition DtKeyState.h:73
@ SHIFT_MODIFIER
Definition DtKeyState.h:140
@ NO_MODIFIER
Definition DtKeyState.h:137
The Qt main window. There will be only one of these per DtDe instance. Note, this window will be dest...
Definition DtQtDeMainWindow.h:46
virtual void hideStartupDialog()
Hide startup dialog.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition exampleEffectsPluginInit.h:22
DT_DLL_EXAMPLEEFFECTSPLUGIN void init(DtDe &anIG)

exampleEffectsPluginInit.h

/******************************************************************************
** Copyright (c) 2019 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
// Get proper local export symbol
// Setup proper plugin export symbol
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEEFFECTSPLUGIN
// Export plugging function bool initDeModule(DtDe* de);
namespace makVrv
{
class DtDe;
namespace vrvExampleEffectsPlugin
{
}
}

MyParticleSystemModel.cxx

/******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#include <osg/Uniform>
namespace makVrv
{
//
// Shader manager implementation; taken from exampleCustomShaders
//
//Constructor that sets up the shaders and uniforms for the stateset passed in
MyShaderManager::MyShaderManager( DtDe& de, osg::StateSet *ss )
: myDe(de)
, myModelStateSet(ss)
{
//Create uniforms for the color and scale of the model
myColorToAdd = ss->getOrCreateUniform("colorToAdd", osg::Uniform::FLOAT_VEC3);
myColorToAdd->set(osg::Vec3(0.0f,0.0f,0.0f));
//Virtual Programs are how shaders are handled in VR-Vantage.
// They allow multiple shader functions to be added anywhere in the scenegraph
// and it handles the main function and program creation.
// Just get or create the virtual program for any stateset and
// all nodes below that stateset will use the functions on the virtual program
myVirtualProgram = osgEarth::VirtualProgram::getOrCreate(ss);
//create a function that will add the colorToAdd uniform to the current color.
// customLightingFunction is the name of the function to call from main
// second parameter is the fragment shader code that is to be included in the program
// third parameter is the location (lighting is the second of three fragment locations)
// fourth parameter is a function that can use the current state to disable this function
// fifth parameter is the order (100.0 will make this run after all other lighting functions.)
myVirtualProgram->setFunction("customLightingFunction", R"(
uniform vec3 colorToAdd;
void customLightingFunction(inout vec4 color)
{
color.rgb += colorToAdd;
}
)",
osgEarth::VirtualProgram::LOCATION_FRAGMENT_LIGHTING,
NULL,
100.0
);
}
{
}
//Function for changing the color that will be added to the fragments color
void MyShaderManager::changeColorOverride(int color, float deltaChange)
{
osg::Vec3 curVal;
myColorToAdd->get(curVal);
switch(color)
{
case 0:
curVal.x() += deltaChange;
curVal.x() = curVal.x() < -1.0 ? -1.0 : curVal.x();
curVal.x() = curVal.x() > 1.0 ? 1.0 : curVal.x();
break;
case 1:
curVal.y() += deltaChange;
curVal.y() = curVal.y() < -1.0 ? -1.0 : curVal.y();
curVal.y() = curVal.y() > 1.0 ? 1.0 : curVal.y();
break;
case 2:
curVal.z() += deltaChange;
curVal.z() = curVal.z() < -1.0 ? -1.0 : curVal.z();
curVal.z() = curVal.z() > 1.0 ? 1.0 : curVal.z();
break;
default:
break;
}
myColorToAdd->set(curVal);
}
//
// Extended Particle System Model Implementation
//
{
}
{
}
{
// Call down to base implementation
//Setup the static shader manager once, this is used to add a virtual program to the smoke
// and all other new FX particle systems in order to change their color.
if (!theShaderManager)
{
osg::StateSet* ss = drawable->particleSystemStateSet();
theShaderManager = new MyShaderManager( myDe, ss );
}
}
// Called via the distributed interface; invoke the shader manager
void MyParticleSystemModel::changeColorOverride( int color, float deltaChange )
{
if (theShaderManager)
{
theShaderManager->changeColorOverride( color, deltaChange );
}
}
}
Contains makVrv::DtFxOsgParticleDrawable class.
Contains makVrv::DtOsgModelInstance class.
Contains makVrv::MyParticleSystemModel class.
The OSG wrapper for the opengl rendering code. sets up the right shaders, figures out camera matrix a...
Definition DtFxOsgParticleDrawable.h:30
virtual osg::StateSet * particleSystemStateSet()
actual stateset used insetad of the osg::Drawable::_stateset
virtual void setModelInstance(DtModelInstance *modelInstance)
The base class for all model instances.
Definition DtModelInstance.h:44
A model of a particle system.
Definition DtOsgParticleSystemModel.h:32
static DtParticleSystemManagerInterface & instance(DtDe &de)
gets interface
MyParticleSystemModel(DtDe &de, DtUniqueID &id)
CTOR.
virtual void changeColorOverride(int color, float deltaChange)
static MyShaderManager * theShaderManager
Definition MyParticleSystemModel.h:84
virtual void setModelInstance(DtModelInstance *modelInstance)
virtual ~MyParticleSystemModel()
virtual DTOR
Definition MyParticleSystemModel.h:30
virtual ~MyShaderManager()
DTOR.
MyShaderManager(DtDe &de, osg::StateSet *ss)
virtual void changeColorOverride(int color, float deltaChange)

MyParticleSystemModel.h

/******************************************************************************
** Copyright (c) 2020 MAK Technologies, Inc.
** All rights reserved.
******************************************************************************/
#pragma once
#include <osgEarth/VirtualProgram>
#include <osg/ref_ptr>
namespace osg
{
class StateSet;
class Uniform;
}
namespace makVrv
{
class DtDe;
class DT_DLL_EXAMPLEEFFECTSPLUGIN MyShaderManager
{
public:
MyShaderManager(DtDe& de, osg::StateSet *ss);
virtual ~MyShaderManager();
//Function for changing the color that will be added to the fragments color
virtual void changeColorOverride(int color, float deltaChange);
protected:
DtDe& myDe;
//model state set to attach the custom shaders to
osg::ref_ptr<osg::StateSet> myModelStateSet;
//Uniforms used by the custom shaders
osg::ref_ptr<osg::Uniform> myColorToAdd;
//virtual program for the stateset
osg::ref_ptr<osgEarth::VirtualProgram> myVirtualProgram;
};
class DT_DLL_EXAMPLEEFFECTSPLUGIN MyParticleSystemModel
: public DtOsgParticleSystemModel
{
public:
MyParticleSystemModel(DtDe& de, DtUniqueID& id);
virtual ~MyParticleSystemModel();
virtual void setModelInstance(DtModelInstance* modelInstance );
virtual void changeColorOverride( int color, float deltaChange );
protected:
static MyShaderManager* theShaderManager;
};
}
Contains makVrv::DtOsgParticleSystemModel class.
Contains makVrv::DtUniqueID type.
Definition DtOverlayPolygonModelInstance.h:28