I initially had questions. I decided to start fixing problems myself, and wasn't familiar with how to contribute to git/GitHub projects, so I started posting my version of the code for other people to view and comment on. In general, looking for a way to discuss ideas, problems and solutions.
My intention is to have updates pulled into the main SDK branch. I noticed that some work had been done on the SDK since I started my changes, including file renaming and identifier renaming (eg TitleCaseFunctionNames). I have GitHub Desktop but didn't (and still don't!) know how to get the latest changes from the main repo into my project. Maybe that is "too hard" now and I will just have to post a fork.
I liked some of the ffglquickstart ideas to manage Params, but it had bugs in it and it was duplicating the structure in CFFGLPluginManager, copying everything from one system to the other and overall being a confusing mess.
I have changed my version so quickstart-inspired params now live in the (CFFGL)PluginManager. Code snippets to demonstrate:
PluginManager class/objet:
Code: Select all
// ffgl/PluginManager.h
namespace ffgl
{
class PluginManager
{
public:
/// This function allows you to add a new parameter to the plugin. There is differents kind of
/// parameters available, Adding a parameter allows the plugin to be
/// aware of them, make them available to the host and take of all the communication with it.
/// It can also allow the plugin to automatically pass the current value of each parameter to the
/// shader before drawing (see ffglqs::Plugin::SendParams()).
/// \param param The parameter to add
void AddParam( ParamBase* param );
protected:
// Plugin parameters. ParamBase is used for polymorphism.
std::vector< ParamBase* > params;
Example effect header:
Code: Select all
#pragma once
#include "ffgl/ParamOption.h"
#include "ffglquickstart/Effect.h"
#include "ffglquickstart/ParamHSBAStruct.h"
#include "ffglquickstart/ParamRGBStruct.h"
namespace spxl
{
namespace ffgl
{
namespace effect
{
class SubAdd : public ffglqs::Effect
{
public:
SubAdd();
~SubAdd();
void Update() override;
protected:
ffglqs::ParamRGBStruct adjustment;
ffglqs::ParamHSBAStruct col1;
ffglqs::ParamHSBAStruct col2;
::ffgl::ParamOption* testOption;
};
}// namespace effect
}// namespace ffgl
}// namespace spxl
Example effect code:
Code: Select all
// spxlSubAdd Effect Plugin
// More or less the same result as the AddSubtract sample plugin, with extra parameters for testing purposes.
// The "multiplier" parameter is used to scale the R,G,B addition/subtraction.
// 2019-08-12 ffgl@subpixels.com
// - Created, based on AddSubbtract sample code
#include "spxlSubAdd.h"
#include "ffgl/ParamBool.h"
#include "ffgl/ParamBuffer.h"
#include "ffgl/ParamFloat.h"
#include "ffgl/ParamInteger.h"
#include "ffgl/ParamOption.h"
#include "ffgl/ParamRange.h"
#include "ffgl/ParamText.h"
#include "ffglquickstart/ParamEvent.h"
#include "ffglquickstart/ParamFFT.h"
#include "ffglquickstart/ParamTrigger.h"
using namespace ffgl;
using namespace ffglex;
using namespace ffglqs;
namespace spxl
{
namespace ffgl
{
namespace effect
{
static ::ffgl::PluginInfo pluginInfo(
PluginFactory< SubAdd >,// Create method
#ifdef _DEBUG
"?e01", // Plugin unique ID of maximum length 4.
"?SubAdd",// Plugin name
#else
"_e01", // Plugin unique ID of maximum length 4.
"_SubAdd",// Plugin name
#endif
2, // API major version number
1, // API minor version number
1, // Plugin major version number
0, // Plugin minor version number
PluginType::FF_EFFECT,// Plugin type
"Subtract and Add colours", // Plugin description
"Resolume FFGL Example (mod by ffgl@subpixels.com)"// About
);
static const char _fragmentShaderCode[] = R"(
void main()
{
vec4 color = texture( inputTexture, i_uv );
//The InputTexture contains premultiplied colors, so we need to unpremultiply first to apply our effect on straight colors.
if( color.a > 0.0 )
color.rgb /= color.a;
color.rgb += adjustment * mult;
if (TestBool) color.rgb += col1.rgb * factor1;
if (b2) color.rgb -= col2.rgb * factor2;
//The plugin has to output premultiplied colors, this is how we're premultiplying our straight color while also
//ensuring we aren't going out of the LDR the video engine is working in.
color.rgb = clamp( color.rgb * color.a, vec3( 0.0 ), vec3( color.a ) );
fragColor = color;
}
)";
SubAdd::SubAdd()
{
//We declare that this plugin has a Brightness parameter which is a RGB param.
//The name here must match the one you declared in your fragment shader.
adjustment = AddRGBRangeParam( "Brightness", "adjustment", 0.0f, { -1.0f, 1.0f } );
// Test Parameters
AddParam( new ParamFloat( "Col Mult", "mult", 1.0f ) );
col1 = AddHueColorParam( "MyColor1", "col1", { 0.0f, 1.0f, 0.75f, 1.0f } );
col2 = AddHueColorParam( "MyColor2", "col2", { 0.666667f, 0.9f, 1.0f, 0.5f } );
AddParam( new ParamFloat( "Scale 1", "factor1" ) );
AddParam( new ParamFloat( "Scale 2", "factor2", 0.25f ) );
AddParam( new ParamFloat( "NameTypeValue", ParameterType::FF_TYPE_BRIGHTNESS, 0.9f ) );
AddParam( new ParamBool( "TestBool" ) );
AddParam( new ParamBool( "TestBool2", "b2", true ) );
AddParam( new ParamEvent( "TestEvent" ) );
AddAudioParam( new ParamFFT( "TestFFT", 8 ) );
testOption = new ParamOption( "TestOption", 2U );
testOption->AddOption( { "Test1", 11.1f } );
testOption->AddOption( { "Test2", 22.2f } );
testOption->AddOption( { "Test3", 33.3f } );
AddParam( testOption );
AddParam( new ParamRange( "TestRange", "temperature", 27.5f, { 0.0f, 100.0f } ) );
AddParam( new ParamInteger( "TestInteger", "xscale", 64, { -1920.0f, 1920.0f } ) );
AddParam( new ParamText( "TestText", "Lorem ipsum blah blah amet" ) );
AddParam( new ParamTrigger( "TestTrigger" ) );
SetFragmentShader( _fragmentShaderCode );
SetTimeSupported( true );
}
SubAdd::~SubAdd()
{
}
void SubAdd::Update()
{
// Try out accessing parameter values
float r = adjustment.red->GetFloatValue();
float g = adjustment.green->GetFloatValue();
float b = adjustment.blue->GetFloatValue();
float average = ( r + g + b ) / 3.0f;
HSBAColor color1 = col1.GetColor();
HSBAColor color2 = col2.GetColor();
float hue1 = color1.hue;
std::string uniformName = col1.hue->GetUniformName();
FFUInt32 selectedOption = testOption->GetIndex();
std::string selectedName = testOption->GetOptionName( selectedOption );
float selectedValue;
FFResult res = testOption->GetOptionValue( selectedOption, selectedValue );
float selectedValueDirect = testOption->GetFloatValue();
}
}// namespace effect
}// namespace ffgl
}// namespace spxl