mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-16 20:59:59 +01:00
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:
@@ -489,6 +489,8 @@ set(VMIX_RSC_FILES
|
|||||||
${AWESOME_SOLID}
|
${AWESOME_SOLID}
|
||||||
./rsc/shaders/simple.fs
|
./rsc/shaders/simple.fs
|
||||||
./rsc/shaders/simple.vs
|
./rsc/shaders/simple.vs
|
||||||
|
./rsc/shaders/texture.fs
|
||||||
|
./rsc/shaders/texture.vs
|
||||||
./rsc/shaders/image.fs
|
./rsc/shaders/image.fs
|
||||||
./rsc/shaders/mask_elipse.fs
|
./rsc/shaders/mask_elipse.fs
|
||||||
./rsc/shaders/mask_box.fs
|
./rsc/shaders/mask_box.fs
|
||||||
|
|||||||
30
rsc/shaders/texture.fs
Normal file
30
rsc/shaders/texture.fs
Normal 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
22
rsc/shaders/texture.vs
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -243,27 +243,6 @@ void ImGuiVisitor::visit(Shader &n)
|
|||||||
ImGui::PopID();
|
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)
|
void ImGuiVisitor::visit(ImageProcessingShader &n)
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
#include "ImageShader.h"
|
#include "ImageShader.h"
|
||||||
|
|
||||||
ShadingProgram imageShadingProgram("shaders/image.vs", "shaders/image.fs");
|
ShadingProgram imageShadingProgram("shaders/image.vs", "shaders/image.fs");
|
||||||
ShadingProgram imageAlphaProgram ("shaders/image.vs", "shaders/imageblending.fs");
|
|
||||||
std::vector< ShadingProgram > maskPrograms = {
|
std::vector< ShadingProgram > maskPrograms = {
|
||||||
ShadingProgram("shaders/simple.vs", "shaders/simple.fs"),
|
ShadingProgram("shaders/simple.vs", "shaders/simple.fs"),
|
||||||
ShadingProgram("shaders/image.vs", "shaders/mask_draw.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)
|
MaskShader::MaskShader(): Shader(), mode(0)
|
||||||
{
|
{
|
||||||
// reset instance
|
// reset instance
|
||||||
|
|||||||
@@ -25,15 +25,6 @@ public:
|
|||||||
glm::mat4 iNodes;
|
glm::mat4 iNodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AlphaShader : public ImageShader
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
AlphaShader();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class MaskShader : public Shader
|
class MaskShader : public Shader
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -1319,10 +1319,10 @@ void MediaPlayer::execute_loop_command()
|
|||||||
{
|
{
|
||||||
if (loop_==LOOP_REWIND) {
|
if (loop_==LOOP_REWIND) {
|
||||||
rewind();
|
rewind();
|
||||||
} else if (loop_ == LOOP_BIDIRECTIONAL) {
|
}
|
||||||
|
else if (loop_ == LOOP_BIDIRECTIONAL) {
|
||||||
rate_ *= -1.f;
|
rate_ *= -1.f;
|
||||||
execute_seek_command();
|
execute_seek_command();
|
||||||
// execute_seek_command(position_ + (rate_ > 0.f ? media_.dt : media_.dt));
|
|
||||||
}
|
}
|
||||||
else { //LOOP_NONE
|
else { //LOOP_NONE
|
||||||
if (desired_state_ == GST_STATE_PLAYING) // avoid repeated call
|
if (desired_state_ == GST_STATE_PLAYING) // avoid repeated call
|
||||||
|
|||||||
@@ -30,12 +30,9 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtx/vector_angle.hpp>
|
#include <glm/gtx/vector_angle.hpp>
|
||||||
|
|
||||||
#include "RenderingManager.h"
|
#include "Shader.h"
|
||||||
#include "Primitives.h"
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "ImageShader.h"
|
|
||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
#include "GlmToolkit.h"
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
@@ -187,7 +184,7 @@ bool parsePLY(string ascii,
|
|||||||
Log::Warning("Parse error line %d: '%s'", line_number_, line.c_str());
|
Log::Warning("Parse error line %d: '%s'", line_number_, line.c_str());
|
||||||
return false;
|
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));
|
elementsProperties[current_element].push_back(plyProperty(name, float_value));
|
||||||
}
|
}
|
||||||
// list property : several types & a name (e.g. 'property list uchar uint vertex_indices')
|
// 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) {
|
if (textureindex) {
|
||||||
// replace previous shader with a new Image Shader
|
// replace previous shader with a new Image Shader
|
||||||
replaceShader( new ImageShader );
|
replaceShader( new TextureShader );
|
||||||
// set texture
|
// set texture
|
||||||
textureindex_ = textureindex;
|
textureindex_ = textureindex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
#define GLM_ENABLE_EXPERIMENTAL
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/gtx/rotate_vector.hpp>
|
#include <glm/gtx/rotate_vector.hpp>
|
||||||
|
|
||||||
#include "ImageShader.h"
|
|
||||||
#include "Resource.h"
|
#include "Resource.h"
|
||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "Visitor.h"
|
#include "Visitor.h"
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
// Globals
|
// Globals
|
||||||
ShadingProgram *ShadingProgram::currentProgram_ = nullptr;
|
ShadingProgram *ShadingProgram::currentProgram_ = nullptr;
|
||||||
ShadingProgram simpleShadingProgram("shaders/simple.vs", "shaders/simple.fs");
|
ShadingProgram simpleShadingProgram("shaders/simple.vs", "shaders/simple.fs");
|
||||||
|
ShadingProgram textureShadingProgram("shaders/texture.vs", "shaders/texture.fs");
|
||||||
|
|
||||||
// Blending presets for matching with Shader::BlendModes:
|
// Blending presets for matching with Shader::BlendModes:
|
||||||
GLenum blending_equation[9] = { GL_FUNC_ADD, // normal
|
GLenum blending_equation[9] = { GL_FUNC_ADD, // normal
|
||||||
@@ -349,3 +350,10 @@ void Shader::reset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TextureShader::TextureShader() : Shader()
|
||||||
|
{
|
||||||
|
program_ = &textureShadingProgram;
|
||||||
|
Shader::reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,5 +80,12 @@ protected:
|
|||||||
ShadingProgram *program_;
|
ShadingProgram *program_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TextureShader : public Shader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextureShader();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __SHADER_H_ */
|
#endif /* __SHADER_H_ */
|
||||||
|
|||||||
@@ -856,7 +856,7 @@ void TextureView::draw()
|
|||||||
e = 1;
|
e = 1;
|
||||||
oss << ": Clear " << MASK_PAINT_ACTION_LABEL;
|
oss << ": Clear " << MASK_PAINT_ACTION_LABEL;
|
||||||
}
|
}
|
||||||
if (ImGui::Selectable( ICON_FA_ADJUST " Invert")) {
|
if (ImGui::Selectable( ICON_FA_THEATER_MASKS " Invert")) {
|
||||||
e = 2;
|
e = 2;
|
||||||
oss << ": Invert " << MASK_PAINT_ACTION_LABEL;
|
oss << ": Invert " << MASK_PAINT_ACTION_LABEL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user