mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-05 15:30:00 +01:00
Smoother alpha transition in mixing view. Also force use of opacity
blending in mixing view for clarity.
This commit is contained in:
15
Shader.cpp
15
Shader.cpp
@@ -170,6 +170,8 @@ void ShadingProgram::checkLinkingErr()
|
||||
}
|
||||
|
||||
|
||||
bool Shader::force_blending_opacity = false;
|
||||
|
||||
Shader::Shader() : blending(BLEND_OPACITY)
|
||||
{
|
||||
// create unique id
|
||||
@@ -209,13 +211,20 @@ void Shader::use()
|
||||
program_->setUniform("iResolution", iResolution);
|
||||
|
||||
// Blending Function
|
||||
if ( blending != BLEND_CUSTOM) {
|
||||
if (force_blending_opacity) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(blending_equation[BLEND_OPACITY]);
|
||||
glBlendFunc(blending_source_function[BLEND_OPACITY], blending_destination_function[BLEND_OPACITY]);
|
||||
|
||||
}
|
||||
else if ( blending != BLEND_CUSTOM ) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(blending_equation[blending]);
|
||||
glBlendFunc(blending_source_function[blending], blending_destination_function[blending]);
|
||||
|
||||
// glBlendEquationSeparate(blending_equation[blending], GL_FUNC_ADD);
|
||||
// glBlendFuncSeparate(blending_source_function[blending], blending_destination_function[blending], GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// TODO different blending for alpha and color
|
||||
// glBlendEquationSeparate(blending_equation[blending], GL_FUNC_ADD);
|
||||
// glBlendFuncSeparate(blending_source_function[blending], blending_destination_function[blending], GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
2
Shader.h
2
Shader.h
@@ -65,6 +65,8 @@ public:
|
||||
} BlendMode;
|
||||
BlendMode blending;
|
||||
|
||||
static bool force_blending_opacity;
|
||||
|
||||
protected:
|
||||
ShadingProgram *program_;
|
||||
glm::vec3 iResolution;
|
||||
|
||||
16
Source.cpp
16
Source.cpp
@@ -255,6 +255,18 @@ void Source::setActive (bool on)
|
||||
groups_[View::LAYER]->visible_ = active_;
|
||||
|
||||
}
|
||||
// Transfer functions from coordinates to alpha (1 - transparency)
|
||||
float linear_(float x, float y) {
|
||||
return 1.f - CLAMP( sqrt( ( x * x ) + ( y * y ) ), 0.f, 1.f );
|
||||
}
|
||||
|
||||
float quad_(float x, float y) {
|
||||
return 1.f - CLAMP( ( x * x ) + ( y * y ), 0.f, 1.f );
|
||||
}
|
||||
|
||||
float sin_quad(float x, float y) {
|
||||
return 0.5f + 0.5f * cos( M_PI * CLAMP( ( ( x * x ) + ( y * y ) ), 0.f, 1.f ) );
|
||||
}
|
||||
|
||||
void Source::update(float dt)
|
||||
{
|
||||
@@ -267,8 +279,8 @@ void Source::update(float dt)
|
||||
// ADJUST alpha based on MIXING node
|
||||
// read position of the mixing node and interpret this as transparency of render output
|
||||
glm::vec2 dist = glm::vec2(groups_[View::MIXING]->translation_);
|
||||
float alpha = 1.0 - CLAMP( ( dist.x * dist.x ) + ( dist.y * dist.y ), 0.f, 1.f );
|
||||
blendingshader_->color.a = alpha;
|
||||
// use the prefered transfer function
|
||||
blendingshader_->color.a = sin_quad( dist.x, dist.y );
|
||||
|
||||
// CHANGE update status based on limbo
|
||||
setActive( glm::length(dist) < 1.3f );
|
||||
|
||||
30
View.cpp
30
View.cpp
@@ -243,6 +243,16 @@ MixingView::MixingView() : View(MIXING), limbo_scale_(1.3f)
|
||||
}
|
||||
|
||||
|
||||
void MixingView::draw()
|
||||
{
|
||||
// temporarily force shaders to use opacity blending for rendering icons
|
||||
Shader::force_blending_opacity = true;
|
||||
// draw scene of this view
|
||||
scene.root()->draw(glm::identity<glm::mat4>(), Rendering::manager().Projection());
|
||||
// restore state
|
||||
Shader::force_blending_opacity = false;
|
||||
}
|
||||
|
||||
void MixingView::zoom( float factor )
|
||||
{
|
||||
float z = scene.root()->scale_.x;
|
||||
@@ -331,6 +341,10 @@ void MixingView::setAlpha(Source *s)
|
||||
s->touch();
|
||||
}
|
||||
|
||||
float sin_quad_texture(float x, float y) {
|
||||
return 0.5f + 0.5f * cos( M_PI * CLAMP( ( ( x * x ) + ( y * y ) ) / CIRCLE_PIXEL_RADIUS, 0.f, 1.f ) );
|
||||
}
|
||||
|
||||
uint MixingView::textureMixingQuadratic()
|
||||
{
|
||||
static GLuint texid = 0;
|
||||
@@ -349,14 +363,16 @@ uint MixingView::textureMixingQuadratic()
|
||||
c = -CIRCLE_PIXELS / 2 + 1;
|
||||
for (int j=0; j < CIRCLE_PIXELS / 2; ++j) {
|
||||
// distance to the center
|
||||
distance = (GLfloat) ((c * c) + (l * l)) / CIRCLE_PIXEL_RADIUS;
|
||||
// distance = (GLfloat) sqrt( (GLfloat) ((c * c) + (l * l))) / (GLfloat) sqrt(CIRCLE_PIXEL_RADIUS); // linear
|
||||
// luminance
|
||||
luminance = 255.f * CLAMP( 0.95f - 0.8f * distance, 0.f, 1.f);
|
||||
color[0] = color[1] = color[2] = static_cast<GLubyte>(luminance);
|
||||
// alpha
|
||||
alpha = 255.f * CLAMP( 1.f - distance , 0.f, 1.f);
|
||||
distance = sin_quad_texture( (float) c , (float) l );
|
||||
// distance = 1.f - (GLfloat) ((c * c) + (l * l)) / CIRCLE_PIXEL_RADIUS; // quadratic
|
||||
// distance = 1.f - (GLfloat) sqrt( (GLfloat) ((c * c) + (l * l))) / (GLfloat) sqrt(CIRCLE_PIXEL_RADIUS); // linear
|
||||
|
||||
// transparency
|
||||
alpha = 255.f * CLAMP( distance , 0.f, 1.f);
|
||||
color[3] = static_cast<GLubyte>(alpha);
|
||||
// luminance adjustment
|
||||
luminance = 255.f * CLAMP( 0.2f + 0.75f * distance, 0.f, 1.f);
|
||||
color[0] = color[1] = color[2] = static_cast<GLubyte>(luminance);
|
||||
|
||||
// 1st quadrant
|
||||
memmove(&matrix[ j * 4 + i * CIRCLE_PIXELS * 4 ], color, 4);
|
||||
|
||||
Reference in New Issue
Block a user