Added ShaderToy support for iMouse to ImageFilter

This commit is contained in:
Bruno Herbelin
2022-07-19 22:43:49 +02:00
parent becaeedff1
commit aee3c8db1b
3 changed files with 15 additions and 9 deletions

View File

@@ -39,8 +39,6 @@ std::string fragmentHeader = "#version 330 core\n"
"in vec2 vertexUV;\n"
"vec3 iChannelResolution[2];\n"
"uniform mat4 iTransform;\n"
"uniform vec4 color;\n"
"uniform float stipple;\n"
"uniform vec3 iResolution;\n"
"uniform sampler2D iChannel0;\n"
"uniform sampler2D iChannel1;\n"
@@ -80,7 +78,7 @@ std::list< FilteringProgram > FilteringProgram::presets = {
int FilteringProgram::getFilterHeaderNumlines()
{
return 16;
return 14;
}
std::string FilteringProgram::getFilterCodeInputs()
@@ -93,7 +91,7 @@ std::string FilteringProgram::getFilterCodeInputs()
"sampler2D iChannel0; // input channel 0 (texture).\n"
"sampler2D iChannel1; // input channel 1 (texture).\n"
"vec4 iDate; // (year, month, day, time in seconds)\n"
"vec4 iMouse; // emulation of mouse input.";
"vec4 iMouse; // simulate mouse input with sliders:";
return filterHeaderHelp;
}
@@ -102,6 +100,8 @@ std::string FilteringProgram::getFilterCodeDefault()
return filterDefault;
}
glm::vec4 FilteringProgram::iMouse = glm::vec4(0.5f,0.5f,0.f,0.f);
////////////////////////////////////////
///// //
//// PROGRAM DEFINING A FILTER ///
@@ -181,7 +181,6 @@ public:
GTimer *timer_;
double iTime_;
uint iFrame_;
glm::vec4 iMouse_;
// list of uniforms to control shader
std::map< std::string, float > uniforms_;
@@ -211,7 +210,6 @@ ImageFilteringShader::ImageFilteringShader(): ImageShader()
timer_ = g_timer_new ();
iTime_ = 0.0;
iFrame_ = 0;
iMouse_ = glm::vec4(0.f);
ImageShader::reset();
}
@@ -242,7 +240,10 @@ void ImageFilteringShader::use()
//
program_->setUniform("iTime", float(iTime_) );
program_->setUniform("iFrame", int(iFrame_) );
program_->setUniform("iMouse", iMouse_ );
// scale iMouse to resolution
glm::vec4 im = FilteringProgram::iMouse * glm::vec4( Rendering::manager().currentAttrib().viewport, 1.f, 1.f);
program_->setUniform("iMouse", im );
// Calculate iTimeDelta
double elapsed = g_timer_elapsed (timer_, NULL);

View File

@@ -61,6 +61,7 @@ public:
static std::string getFilterCodeInputs();
static std::string getFilterCodeDefault();
static std::list< FilteringProgram > presets;
static glm::vec4 iMouse;
};
class Surface;

View File

@@ -44,6 +44,7 @@ using namespace std;
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/string_cast.hpp>
@@ -5451,8 +5452,8 @@ ShaderEditor::ShaderEditor() : WorkspaceWindow("Shader"), current_(nullptr),
}
static const char* const filter_keyword[] = {
"iResolution", "iTime", "iTimeDelta", "iFrame", "iChannelResolution", "iDate",
"iChannel0", "iChannel1", "iTransform", "FragColor", "vertexColor", "vertexUV",
"iResolution", "iTime", "iTimeDelta", "iFrame", "iChannelResolution", "iDate", "iMouse",
"iChannel0", "iChannel1", "iTransform", "FragColor", "vertexColor", "vertexUV"
};
for (auto& k : filter_keyword)
{
@@ -5757,6 +5758,9 @@ void ShaderEditor::Render()
ImGui::InputTextMultiline("##Info", (char *)info.c_str(), info.size(), ImVec2(-1, 8*ImGui::GetTextLineHeightWithSpacing()), ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleColor(2);
ImGui::PopFont();
// sliders iMouse
ImGui::SliderFloat4("##iMouse", glm::value_ptr( FilteringProgram::iMouse ), 0.0, 1.0 );
}
else
ImGui::Spacing();