我正在尝试在我的GL 4.5应用程序中实现软刷。我已经实现了100%的硬刷,但软刷功能却低于标准。我试图实现的这种类型的绘画模式在Krita被称为“洗”画,是GIMP中的常规模式。
例如:Photoshop中的我有一个低硬度的圆刷和10%的刷子不透明度并按住鼠标并拖动光标我得到一个均匀的笔触,纹理构建到10%的不透明度,除了它渐弱的边缘。如果我再次点击它会因为添加剂混合(?)而增加10%的白色。
在我的软刷纹理应用程序中,由于纹理的不透明度,我总是在鼠标移动时出现条带。在混合当前笔划和BG纹理之后,我尝试了各种混合模式和夹在不透明度上,它们或多或少看起来如下:
pPaintStroke_washF全屏四重着色器
#version 450 core
#extension GL_ARB_bindless_texture : require
in Vert
{
vec2 uv;
} v;
layout(bindless_sampler, location = 0) uniform sampler2D blended_64; // blended bg + stroke
layout(location = 0) out vec4 Ci;
uniform vec4 brushRGBA = vec4(1.f, 1.f, 1.f, .001f);
void main()
{
vec4 blended = texture(blended_64, v.uv);
if (blended.a == 0.f)
Ci = vec4(0.f);
else
{
Ci.rgb = brushRGBA.rgb;
Ci.a = clamp(blended.a, 0.f, brushRGBA.a);
// Ci.a = clamp(blended.a, blended.a, brushRGBA.a);
}
}
应用
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (int i = 0; i < Bresenham.size(); ++i)
{
/*
//bind brushTempN.fbo1
//render Bresenham[i] into it
*/
glBindFramebuffer(GL_FRAMEBUFFER, brushTempN.fbo1);
glViewport(0, 0, brushTempN.width, brushTempN.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
myWin.myGLWidgetSh->glUseProgram2("pPaintStroke_unwashed");
myWin.paintStroke->s->val_3 = glm::vec3((float)Bresenham[i].size / 100);
myWin.paintStroke->t->val_3 = glm::vec3(Bresenham[i].coord, 0.f);
myWin.paintStroke->mvpGet(myWin.allGL[GLidx]);
myWin.paintStroke->render(myWin.allGL[GLidx]);
/*
//bind brushTempN.fbo2
//render bg - starts as 0 (brushBGN.tex1)
//render curr stroke (brushTempN.tex1)
//this blends them
*/
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindFramebuffer(GL_FRAMEBUFFER, brushTempN.fbo2);
glViewport(0, 0, brushTempN.width, brushTempN.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
myWin.myGLWidgetSh->glUseProgram2("pPaintStroke_washBlend");
washBlendPhase = 0; myWin.myFSQ->render(myWin.allGL[GLidx]); //render BG
washBlendPhase = 1; myWin.myFSQ->render(myWin.allGL[GLidx]); //render the curr stroke (brushTempN.tex1)
/*
//bind brushN.fbo1
//read brushTempN.tex2_64
//clamp the blended alpha with Ci.a = clamp(in.a, 0.f, brushRGBA.a)
*/
glBindFramebuffer(GL_FRAMEBUFFER, brushN.fbo1);
glViewport(0, 0, brushN.width, brushN.height);
myWin.myGLWidgetSh->glUseProgram2("pPaintStroke_wash");
myWin.myFSQ->render(myWin.allGL[GLidx]);
/*
//bind brushBGN.fbo1
//copy the above brushN.tex1 into it
*/
glBindFramebuffer(GL_FRAMEBUFFER, brushBGN.fbo1);
glViewport(0, 0, brushBGN.width, brushBGN.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
myWin.myGLWidgetSh->glUseProgram2("pPaintStroke_washBlend");
washBlendPhase = 2; myWin.myFSQ->render(myWin.allGL[GLidx]); //render new BG
}
答案 0 :(得分:2)
您也应该使用添加剂混合。
glBlendFunc(GL_SRC_ALPHA, GL_ONE);