BugFix and code cleanup

Fixed rendering of Mesh by using new TextureShader (instead of ImageShader which is dedicated to square Surfaces). Cleanup includes and code layout.
This commit is contained in:
Bruno Herbelin
2023-12-26 23:08:09 +01:00
parent abdc70121d
commit fde6be3f97
12 changed files with 75 additions and 52 deletions

View File

@@ -489,6 +489,8 @@ set(VMIX_RSC_FILES
${AWESOME_SOLID}
./rsc/shaders/simple.fs
./rsc/shaders/simple.vs
./rsc/shaders/texture.fs
./rsc/shaders/texture.vs
./rsc/shaders/image.fs
./rsc/shaders/mask_elipse.fs
./rsc/shaders/mask_box.fs

30
rsc/shaders/texture.fs Normal file
View File

@@ -0,0 +1,30 @@
#version 330 core
out vec4 FragColor;
in vec4 vertexColor;
in vec2 vertexUV;
// from General Shader
uniform vec3 iResolution; // viewport image resolution (in pixels)
uniform mat4 iTransform; // image transformation
uniform vec4 color;
// Image Shader
uniform sampler2D iChannel0; // input channel (texture id).
void main()
{
// adjust UV
vec4 texcoord = iTransform * vec4(vertexUV.x, vertexUV.y, 0.0, 1.0);
// color is a mix of texture, vertex and uniform colors
vec4 textureColor = texture(iChannel0, texcoord.xy);
vec3 RGB = textureColor.rgb * vertexColor.rgb * color.rgb;
// alpha is a mix of texture, vertex, uniform
float A = textureColor.a * vertexColor.a * color.a;
// output RGB with Alpha pre-multiplied
FragColor = vec4(RGB * A, A);
}

22
rsc/shaders/texture.vs Normal file
View File

@@ -0,0 +1,22 @@
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 texCoord;
out vec4 vertexColor;
out vec2 vertexUV;
uniform mat4 modelview;
uniform mat4 projection;
void main()
{
vec4 pos = modelview * vec4(position, 1.0);
// output
gl_Position = projection * pos;
vertexColor = color;
vertexUV = texCoord;
}

View File

@@ -243,27 +243,6 @@ void ImGuiVisitor::visit(Shader &n)
ImGui::PopID();
}
//void ImGuiVisitor::visit(ImageShader &n)
//{
// ImGui::PushID(std::to_string(n.id()).c_str());
// // get index of the mask used in this ImageShader
// int item_current = n.mask;
//// if (ImGuiToolkit::ButtonIcon(10, 3)) n.mask = 0;
//// ImGui::SameLine(0, IMGUI_SAME_LINE);
// ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
// // combo list of masks
// if ( ImGui::Combo("Mask", &item_current, ImageShader::mask_names, IM_ARRAYSIZE(ImageShader::mask_names) ) )
// {
// if (item_current < (int) ImageShader::mask_presets.size())
// n.mask = item_current;
// else {
// // TODO ask for custom mask
// }
// Action::manager().store("Mask "+ std::string(ImageShader::mask_names[n.mask]));
// }
// ImGui::PopID();
//}
void ImGuiVisitor::visit(ImageProcessingShader &n)
{
ImGuiIO& io = ImGui::GetIO();

View File

@@ -29,7 +29,6 @@
#include "ImageShader.h"
ShadingProgram imageShadingProgram("shaders/image.vs", "shaders/image.fs");
ShadingProgram imageAlphaProgram ("shaders/image.vs", "shaders/imageblending.fs");
std::vector< ShadingProgram > maskPrograms = {
ShadingProgram("shaders/simple.vs", "shaders/simple.fs"),
ShadingProgram("shaders/image.vs", "shaders/mask_draw.fs"),
@@ -97,17 +96,6 @@ void ImageShader::accept(Visitor& v) {
}
AlphaShader::AlphaShader(): ImageShader()
{
// to inverse alpha mode, use dedicated shading program
program_ = &imageAlphaProgram;
// reset instance
reset();
blending = Shader::BLEND_NONE;
}
MaskShader::MaskShader(): Shader(), mode(0)
{
// reset instance

View File

@@ -25,15 +25,6 @@ public:
glm::mat4 iNodes;
};
class AlphaShader : public ImageShader
{
public:
AlphaShader();
};
class MaskShader : public Shader
{

View File

@@ -1319,10 +1319,10 @@ void MediaPlayer::execute_loop_command()
{
if (loop_==LOOP_REWIND) {
rewind();
} else if (loop_ == LOOP_BIDIRECTIONAL) {
}
else if (loop_ == LOOP_BIDIRECTIONAL) {
rate_ *= -1.f;
execute_seek_command();
// execute_seek_command(position_ + (rate_ > 0.f ? media_.dt : media_.dt));
}
else { //LOOP_NONE
if (desired_state_ == GST_STATE_PLAYING) // avoid repeated call

View File

@@ -30,12 +30,9 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/vector_angle.hpp>
#include "RenderingManager.h"
#include "Primitives.h"
#include "Shader.h"
#include "Resource.h"
#include "ImageShader.h"
#include "Visitor.h"
#include "GlmToolkit.h"
#include "Log.h"
#include "Mesh.h"
@@ -187,7 +184,7 @@ bool parsePLY(string ascii,
Log::Warning("Parse error line %d: '%s'", line_number_, line.c_str());
return false;
}
bool float_value = ( type == "float" ) | ( type == "double" );
bool float_value = ( type == "float" ) || ( type == "double" );
elementsProperties[current_element].push_back(plyProperty(name, float_value));
}
// list property : several types & a name (e.g. 'property list uchar uint vertex_indices')
@@ -364,7 +361,7 @@ void Mesh::setTexture(uint textureindex)
{
if (textureindex) {
// replace previous shader with a new Image Shader
replaceShader( new ImageShader );
replaceShader( new TextureShader );
// set texture
textureindex_ = textureindex;
}

View File

@@ -28,7 +28,6 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/rotate_vector.hpp>
#include "ImageShader.h"
#include "Resource.h"
#include "FrameBuffer.h"
#include "Visitor.h"

View File

@@ -45,6 +45,7 @@
// Globals
ShadingProgram *ShadingProgram::currentProgram_ = nullptr;
ShadingProgram simpleShadingProgram("shaders/simple.vs", "shaders/simple.fs");
ShadingProgram textureShadingProgram("shaders/texture.vs", "shaders/texture.fs");
// Blending presets for matching with Shader::BlendModes:
GLenum blending_equation[9] = { GL_FUNC_ADD, // normal
@@ -349,3 +350,10 @@ void Shader::reset()
}
TextureShader::TextureShader() : Shader()
{
program_ = &textureShadingProgram;
Shader::reset();
}

View File

@@ -80,5 +80,12 @@ protected:
ShadingProgram *program_;
};
class TextureShader : public Shader
{
public:
TextureShader();
};
#endif /* __SHADER_H_ */

View File

@@ -856,7 +856,7 @@ void TextureView::draw()
e = 1;
oss << ": Clear " << MASK_PAINT_ACTION_LABEL;
}
if (ImGui::Selectable( ICON_FA_ADJUST " Invert")) {
if (ImGui::Selectable( ICON_FA_THEATER_MASKS " Invert")) {
e = 2;
oss << ": Invert " << MASK_PAINT_ACTION_LABEL;
}