Skip to content

Commit

Permalink
Fix idle preset and filters, load logo textures y-flipped.
Browse files Browse the repository at this point in the history
Idle preset doesn't render the same way as before, as it was presumably adapted to projectM's previous math. It's now a bit more complex, with the M tilting, a sine waveform at the bottom and some other tweaks.

The filter mesh was broken, so the effects didn't render at all.
  • Loading branch information
kblaschke committed Mar 30, 2023
1 parent 4d9f3ff commit 3d7b363
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 228 deletions.
10 changes: 5 additions & 5 deletions src/libprojectM/MilkdropPreset/CustomShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void CustomShape::Initialize(PresetFileParser& parsedFile, int index)
m_border_a = parsedFile.GetFloat(shapecodePrefix + "border_a", m_border_a);

// projectM addition: texture name to use for rendering the shape
m_image = parsedFile.GetString("image", "");
m_image = parsedFile.GetString(shapecodePrefix + "image", "");
}

void CustomShape::CompileCodeAndRunInitExpressions()
Expand Down Expand Up @@ -175,7 +175,7 @@ void CustomShape::Draw()
if (static_cast<int>(*m_perFrameContext.textured) != 0)
{
m_presetState.texturedShader.Bind();
m_presetState.texturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
m_presetState.texturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjectionFlipped);
m_presetState.texturedShader.SetUniformInt("texture_sampler", 0);

// Textured shape, either main texture or texture from "image" key
Expand Down Expand Up @@ -210,7 +210,7 @@ void CustomShape::Draw()
const float angle = cornerProgress * pi * 2.0f + static_cast<float>(*m_perFrameContext.tex_ang) + pi * 0.25f;

vertexData[i].u = 0.5f + 0.5f * cosf(angle) / static_cast<float>(*m_perFrameContext.tex_zoom) * textureAspectY;
vertexData[i].v = 0.5f + 0.5f * sinf(angle) / static_cast<float>(*m_perFrameContext.tex_zoom);
vertexData[i].v = 0.5f - 0.5f * sinf(angle) / static_cast<float>(*m_perFrameContext.tex_zoom);
}

vertexData[sides + 1] = vertexData[1];
Expand All @@ -234,7 +234,7 @@ void CustomShape::Draw()
glBufferData(GL_ARRAY_BUFFER, sizeof(TexturedPoint) * (sides + 2), vertexData.data(), GL_DYNAMIC_DRAW);

m_presetState.untexturedShader.Bind();
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjectionFlipped);

glBindVertexArray(m_vaoIdUntextured);
glDrawArrays(GL_TRIANGLE_FAN, 0, sides + 2);
Expand All @@ -252,7 +252,7 @@ void CustomShape::Draw()
}

m_presetState.untexturedShader.Bind();
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjectionFlipped);

glVertexAttrib4f(1,
static_cast<float>(*m_perFrameContext.border_r),
Expand Down
2 changes: 1 addition & 1 deletion src/libprojectM/MilkdropPreset/CustomWaveform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void CustomWaveform::Draw(const PerFrameContext& presetPerFrameContext)
}

m_presetState.untexturedShader.Bind();
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjection);
m_presetState.untexturedShader.SetUniformMat4x4("vertex_transformation", PresetState::orthogonalProjectionFlipped);

auto iterations = (m_drawThick && !m_useDots) ? 4 : 1;

Expand Down
81 changes: 52 additions & 29 deletions src/libprojectM/MilkdropPreset/Filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@ Filters::Filters(const PresetState& presetState)
RenderItem::Init();
}

void Filters::InitVertexAttrib()
{
glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x)));
}

void Filters::Draw()
{
UpdateMesh();

if (m_viewportWidth == 0 || m_viewportHeight == 0)
{
return;
}

glEnable(GL_BLEND);

m_presetState.untexturedShader.Bind();
Expand Down Expand Up @@ -46,54 +61,62 @@ void Filters::Draw()
}


void Filters::InitVertexAttrib()
{
std::array<RenderItem::Point, 4> points;

float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast<float>(m_presetState.renderContext.viewportSizeX);
float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast<float>(m_presetState.renderContext.viewportSizeY);
points[0].x = -fOnePlusInvWidth;
points[1].x = fOnePlusInvWidth;
points[2].x = -fOnePlusInvWidth;
points[3].x = fOnePlusInvWidth;
points[0].y = fOnePlusInvHeight;
points[1].y = fOnePlusInvHeight;
points[2].y = -fOnePlusInvHeight;
points[3].y = -fOnePlusInvHeight;

glEnableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Point), reinterpret_cast<void*>(offsetof(Point, x)));
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
}

void Filters::Brighten()
{
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBlendFunc(GL_ZERO, GL_DST_COLOR);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

void Filters::Darken()
{
glBlendFunc(GL_ZERO, GL_DST_COLOR);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

void Filters::Solarize()
{
glBlendFunc(GL_ZERO, GL_ONE_MINUS_DST_COLOR);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBlendFunc(GL_DST_COLOR, GL_ONE);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}

void Filters::Invert()
{
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
void Filters::UpdateMesh()
{
if (m_viewportWidth == m_presetState.renderContext.viewportSizeX &&
m_viewportHeight == m_presetState.renderContext.viewportSizeY)
{
return;
}

m_viewportWidth = m_presetState.renderContext.viewportSizeX;
m_viewportHeight = m_presetState.renderContext.viewportSizeY;

std::array<RenderItem::Point, 4> points;

float const fOnePlusInvWidth = 1.0f + 1.0f / static_cast<float>(m_viewportWidth);
float const fOnePlusInvHeight = 1.0f + 1.0f / static_cast<float>(m_viewportHeight);
points[0].x = -fOnePlusInvWidth;
points[1].x = fOnePlusInvWidth;
points[2].x = -fOnePlusInvWidth;
points[3].x = fOnePlusInvWidth;
points[0].y = fOnePlusInvHeight;
points[1].y = fOnePlusInvHeight;
points[2].y = -fOnePlusInvHeight;
points[3].y = -fOnePlusInvHeight;

glBindVertexArray(m_vaoID);
glBindBuffer(GL_ARRAY_BUFFER, m_vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points.data(), GL_STATIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
5 changes: 5 additions & 0 deletions src/libprojectM/MilkdropPreset/Filters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Filters : public RenderItem
void Draw();

private:
void UpdateMesh();

/**
* @brief Brightens the image.
*/
Expand All @@ -42,4 +44,7 @@ class Filters : public RenderItem
void Invert();

const PresetState& m_presetState; //!< The global preset state.

int m_viewportWidth{}; //!< Last known viewport width
int m_viewportHeight{}; //!< Last known viewport height
};
Loading

0 comments on commit 3d7b363

Please sign in to comment.