mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-02-04 16:15:46 +00:00
Flip input to blur textures once, but not in subsequent passes.
This commit is contained in:
@ -91,23 +91,20 @@ auto BlurTexture::GetDescriptorsForBlurLevel(BlurTexture::BlurLevel blurLevel) c
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
void BlurTexture::Update(const PresetState& presetState, const PerFrameContext& perFrameContext)
|
||||
void BlurTexture::Update(const Texture& sourceTexture, const PerFrameContext& perFrameContext)
|
||||
{
|
||||
if (m_blurLevel == BlurLevel::None)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto sourceTexture = presetState.mainTexture.lock();
|
||||
|
||||
if (!sourceTexture ||
|
||||
sourceTexture->Width() == 0 ||
|
||||
sourceTexture->Height() == 0)
|
||||
if (sourceTexture.Width() == 0 ||
|
||||
sourceTexture.Height() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AllocateTextures(*sourceTexture);
|
||||
AllocateTextures(sourceTexture);
|
||||
|
||||
unsigned int const passes = static_cast<int>(m_blurLevel) * 2;
|
||||
auto const blur1EdgeDarken = static_cast<float>(*perFrameContext.blur1_edge_darken);
|
||||
@ -170,16 +167,18 @@ void BlurTexture::Update(const PresetState& presetState, const PerFrameContext&
|
||||
// hook up correct source texture - assume there is only one, at stage 0
|
||||
if (pass == 0)
|
||||
{
|
||||
sourceTexture->Bind(0);
|
||||
sourceTexture.Bind(0);
|
||||
blurShader->SetUniformInt("flipVertical", 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_blurTextures[pass - 1]->Bind(0);
|
||||
blurShader->SetUniformInt("flipVertical", 0);
|
||||
}
|
||||
m_blurSampler->Bind(0);
|
||||
|
||||
float srcWidth = static_cast<float>((pass == 0) ? sourceTexture->Width() : m_blurTextures[pass - 1]->Width());
|
||||
float srcHeight = static_cast<float>((pass == 0) ? sourceTexture->Height() : m_blurTextures[pass - 1]->Height());
|
||||
float srcWidth = static_cast<float>((pass == 0) ? sourceTexture.Width() : m_blurTextures[pass - 1]->Width());
|
||||
float srcHeight = static_cast<float>((pass == 0) ? sourceTexture.Height() : m_blurTextures[pass - 1]->Height());
|
||||
|
||||
float scaleNow = scale[pass / 2];
|
||||
float biasNow = bias[pass / 2];
|
||||
@ -254,7 +253,7 @@ void BlurTexture::Update(const PresetState& presetState, const PerFrameContext&
|
||||
// Bind previous framebuffer and reset viewport size
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, origReadFramebuffer);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, origDrawFramebuffer);
|
||||
glViewport(0, 0, sourceTexture->Width(), sourceTexture->Height());
|
||||
glViewport(0, 0, sourceTexture.Width(), sourceTexture.Height());
|
||||
|
||||
Shader::Unbind();
|
||||
}
|
||||
|
||||
@ -62,10 +62,10 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Renders the required blur passes on the given texture.
|
||||
* @param presetState The preset state with initial values and the main texture.
|
||||
* @param sourceTexture The texture to create the blur levels from.
|
||||
* @param perFrameContext The per-frame variables.
|
||||
*/
|
||||
void Update(const PresetState& presetState, const PerFrameContext& perFrameContext);
|
||||
void Update(const Texture& sourceTexture, const PerFrameContext& perFrameContext);
|
||||
|
||||
/**
|
||||
* @brief Binds the user-readable blur textures to the texture slots starting with the given index.
|
||||
|
||||
@ -116,7 +116,11 @@ void MilkdropPreset::RenderFrame(const libprojectM::Audio::FrameAudioData& audio
|
||||
m_framebuffer.RemoveColorAttachment(m_currentFrameBuffer, 1);
|
||||
|
||||
// Update blur textures
|
||||
m_state.blurTexture.Update(m_state, m_perFrameContext);
|
||||
{
|
||||
const auto warpedImage = m_framebuffer.GetColorAttachmentTexture(m_currentFrameBuffer, 0);
|
||||
assert(warpedImage.get());
|
||||
m_state.blurTexture.Update(*warpedImage, m_perFrameContext);
|
||||
}
|
||||
|
||||
// Draw audio-data-related stuff
|
||||
for (auto& shape : m_customShapes)
|
||||
|
||||
@ -3,9 +3,17 @@ precision mediump float;
|
||||
layout(location = 0) in vec2 vertex_position;
|
||||
layout(location = 1) in vec2 vertex_texture;
|
||||
|
||||
uniform int flipVertical;
|
||||
|
||||
out vec2 fragment_texture;
|
||||
|
||||
void main(){
|
||||
gl_Position = vec4(vertex_position, 0.0, 1.0);
|
||||
fragment_texture = vertex_texture;
|
||||
|
||||
// Vertically flip main texture, but not the already blurred ones.
|
||||
if (flipVertical == 1)
|
||||
{
|
||||
fragment_texture.y = 1.0 - fragment_texture.y;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user