Comments (8)
下面是我摘出来的代码,但是效果却不好,拍摄亮的地方就是一片白,暗点的地方颜色又不对而且都是颗粒感,能帮忙看看嘛
namespace filters {
bool GlowVideoFilter::s_registered = GlowVideoFilter::registerFilter();
bool
GlowVideoFilter::registerFilter()
{
FilterFactory::_register("com.videocore.filters.glow", []() { return new GlowVideoFilter(); });
return true;
}
GlowVideoFilter::GlowVideoFilter()
: IVideoFilter(), m_initialized(false), m_bound(false)
{
}
GlowVideoFilter::~GlowVideoFilter()
{
glDeleteProgram(m_program);
glDeleteVertexArraysOES(1, &m_vao);
}
const char * const
GlowVideoFilter::vertexKernel() const
{
KERNEL(GL_ES2_3, m_language,
attribute vec2 aPos;
attribute vec2 aCoord;
varying vec2 vCoord;
uniform mat4 uMat;
void main(void) {
gl_Position = uMat * vec4(aPos,0.,1.);
vCoord = aCoord;
}
)
return nullptr;
}
const char * const
GlowVideoFilter::pixelKernel() const
{
///*
KERNEL(GL_ES2_3, m_language,
precision highp float;
uniform sampler2D uTex0;
uniform vec2 singleStepOffset;
uniform highp vec4 params;
varying highp vec2 vCoord;
const highp vec3 W = vec3(0.299,0.587,0.114);
const mat3 saturateMatrix = mat3(
1.1102,-0.0598,-0.061,
-0.0774,1.0826,-0.1186,
-0.0228,-0.0228,1.1772);
float hardlight(float color)
{
if(color <= 0.5)
{
color = color * color * 2.0;
}
else
{
color = 1.0 - ((1.0 - color)*(1.0 - color) * 2.0);
}
return color;
}
void main(){
vec2 blurCoordinates[24];
blurCoordinates[0] = vCoord.xy + singleStepOffset * vec2(0.0, -10.0);
blurCoordinates[1] = vCoord.xy + singleStepOffset * vec2(0.0, 10.0);
blurCoordinates[2] = vCoord.xy + singleStepOffset * vec2(-10.0, 0.0);
blurCoordinates[3] = vCoord.xy + singleStepOffset * vec2(10.0, 0.0);
blurCoordinates[4] = vCoord.xy + singleStepOffset * vec2(5.0, -8.0);
blurCoordinates[5] = vCoord.xy + singleStepOffset * vec2(5.0, 8.0);
blurCoordinates[6] = vCoord.xy + singleStepOffset * vec2(-5.0, 8.0);
blurCoordinates[7] = vCoord.xy + singleStepOffset * vec2(-5.0, -8.0);
blurCoordinates[8] = vCoord.xy + singleStepOffset * vec2(8.0, -5.0);
blurCoordinates[9] = vCoord.xy + singleStepOffset * vec2(8.0, 5.0);
blurCoordinates[10] = vCoord.xy + singleStepOffset * vec2(-8.0, 5.0);
blurCoordinates[11] = vCoord.xy + singleStepOffset * vec2(-8.0, -5.0);
blurCoordinates[12] = vCoord.xy + singleStepOffset * vec2(0.0, -6.0);
blurCoordinates[13] = vCoord.xy + singleStepOffset * vec2(0.0, 6.0);
blurCoordinates[14] = vCoord.xy + singleStepOffset * vec2(6.0, 0.0);
blurCoordinates[15] = vCoord.xy + singleStepOffset * vec2(-6.0, 0.0);
blurCoordinates[16] = vCoord.xy + singleStepOffset * vec2(-4.0, -4.0);
blurCoordinates[17] = vCoord.xy + singleStepOffset * vec2(-4.0, 4.0);
blurCoordinates[18] = vCoord.xy + singleStepOffset * vec2(4.0, -4.0);
blurCoordinates[19] = vCoord.xy + singleStepOffset * vec2(4.0, 4.0);
blurCoordinates[20] = vCoord.xy + singleStepOffset * vec2(-2.0, -2.0);
blurCoordinates[21] = vCoord.xy + singleStepOffset * vec2(-2.0, 2.0);
blurCoordinates[22] = vCoord.xy + singleStepOffset * vec2(2.0, -2.0);
blurCoordinates[23] = vCoord.xy + singleStepOffset * vec2(2.0, 2.0);
float sampleColor = texture2D(uTex0, vCoord).g * 22.0;
sampleColor += texture2D(uTex0, blurCoordinates[0]).g;
sampleColor += texture2D(uTex0, blurCoordinates[1]).g;
sampleColor += texture2D(uTex0, blurCoordinates[2]).g;
sampleColor += texture2D(uTex0, blurCoordinates[3]).g;
sampleColor += texture2D(uTex0, blurCoordinates[4]).g;
sampleColor += texture2D(uTex0, blurCoordinates[5]).g;
sampleColor += texture2D(uTex0, blurCoordinates[6]).g;
sampleColor += texture2D(uTex0, blurCoordinates[7]).g;
sampleColor += texture2D(uTex0, blurCoordinates[8]).g;
sampleColor += texture2D(uTex0, blurCoordinates[9]).g;
sampleColor += texture2D(uTex0, blurCoordinates[10]).g;
sampleColor += texture2D(uTex0, blurCoordinates[11]).g;
sampleColor += texture2D(uTex0, blurCoordinates[12]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[13]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[14]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[15]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[16]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[17]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[18]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[19]).g * 2.0;
sampleColor += texture2D(uTex0, blurCoordinates[20]).g * 3.0;
sampleColor += texture2D(uTex0, blurCoordinates[21]).g * 3.0;
sampleColor += texture2D(uTex0, blurCoordinates[22]).g * 3.0;
sampleColor += texture2D(uTex0, blurCoordinates[23]).g * 3.0;
sampleColor = sampleColor / 62.0;
vec3 centralColor = texture2D(uTex0, vCoord).rgb;
float highpass = centralColor.g - sampleColor + 0.5;
for(int i = 0; i < 5;i++)
{
highpass = hardlight(highpass);
}
float lumance = dot(centralColor, W);
float alpha = pow(lumance, params.r);
vec3 smoothColor = centralColor + (centralColor-vec3(highpass))*alpha*0.1;
smoothColor.r = clamp(pow(smoothColor.r, params.g),0.0,1.0);
smoothColor.g = clamp(pow(smoothColor.g, params.g),0.0,1.0);
smoothColor.b = clamp(pow(smoothColor.b, params.g),0.0,1.0);
vec3 lvse = vec3(1.0)-(vec3(1.0)-smoothColor)*(vec3(1.0)-centralColor);
vec3 bianliang = max(smoothColor, centralColor);
vec3 rouguang = 2.0*centralColor*smoothColor + centralColor*centralColor - 2.0*centralColor*centralColor*smoothColor;
gl_FragColor = vec4(mix(centralColor, lvse, alpha), 1.0);
gl_FragColor.rgb = mix(gl_FragColor.rgb, bianliang, alpha);
gl_FragColor.rgb = mix(gl_FragColor.rgb, rouguang, params.b);
vec3 satcolor = gl_FragColor.rgb * saturateMatrix;
gl_FragColor.rgb = mix(gl_FragColor.rgb, satcolor, params.a);
}
)
//*/
/*
KERNEL(GL_ES2_3, m_language,
precision mediump float;
varying vec2 vCoord;
uniform sampler2D uTex0;
const float step_w = 0.0015625;
const float step_h = 0.0027778;
void main(void) {
vec3 t1 = texture2D(uTex0, vec2(vCoord.x - step_w, vCoord.y - step_h)).bgr;
vec3 t2 = texture2D(uTex0, vec2(vCoord.x, vCoord.y - step_h)).bgr;
vec3 t3 = texture2D(uTex0, vec2(vCoord.x + step_w, vCoord.y - step_h)).bgr;
vec3 t4 = texture2D(uTex0, vec2(vCoord.x - step_w, vCoord.y)).bgr;
vec3 t5 = texture2D(uTex0, vCoord).bgr;
vec3 t6 = texture2D(uTex0, vec2(vCoord.x + step_w, vCoord.y)).bgr;
vec3 t7 = texture2D(uTex0, vec2(vCoord.x - step_w, vCoord.y + step_h)).bgr;
vec3 t8 = texture2D(uTex0, vec2(vCoord.x, vCoord.y + step_h)).bgr;
vec3 t9 = texture2D(uTex0, vec2(vCoord.x + step_w, vCoord.y + step_h)).bgr;
vec3 xx= t1 + 2.0*t2 + t3 - t7 - 2.0*t8 - t9;
vec3 yy = t1 - t3 + 2.0*t4 - 2.0*t6 + t7 - t9;
vec3 rr = sqrt(xx * xx + yy * yy);
gl_FragColor.a = 1.0;
gl_FragColor.rgb = rr * 2.0 * t5;
}
)
//*/
return nullptr;
}
void
GlowVideoFilter::initialize()
{
switch(m_language) {
case GL_ES2_3:
case GL_2: {
setProgram(build_program(vertexKernel(), pixelKernel()));
glGenVertexArraysOES(1, &m_vao);
glBindVertexArrayOES(m_vao);
m_uMatrix = glGetUniformLocation(m_program, "uMat");
int attrpos = glGetAttribLocation(m_program, "aPos");
int attrtex = glGetAttribLocation(m_program, "aCoord");
int unitex = glGetUniformLocation(m_program, "uTex0");
int mSingleStepOffsetLocation = glGetUniformLocation(m_program, "singleStepOffset");
int mParamsLocation = glGetUniformLocation(m_program, "params");
glUniform1i(unitex, 0);
glEnableVertexAttribArray(attrpos);
glEnableVertexAttribArray(attrtex);
glVertexAttribPointer(attrpos, BUFFER_SIZE_POSITION, GL_FLOAT, GL_FALSE, BUFFER_STRIDE, BUFFER_OFFSET_POSITION);
glVertexAttribPointer(attrtex, BUFFER_SIZE_POSITION, GL_FLOAT, GL_FALSE, BUFFER_STRIDE, BUFFER_OFFSET_TEXTURE);
GLfloat a[] = {0.33f, 0.63f, 0.4f, 0.35f};
glUniform4fv(mParamsLocation, 1,a);
GLfloat b[] = {2.0/400, 2.0/700};
glUniform2fv(mSingleStepOffsetLocation, 1,b);
m_initialized = true;
}
break;
case GL_3:
break;
}
}
void
GlowVideoFilter::bind()
{
switch(m_language) {
case GL_ES2_3:
case GL_2:
if(!m_bound) {
if(!initialized()) {
initialize();
}
glUseProgram(m_program);
glBindVertexArrayOES(m_vao);
}
glUniformMatrix4fv(m_uMatrix, 1, GL_FALSE, &m_matrix[0][0]);
break;
case GL_3:
break;
}
}
void
GlowVideoFilter::unbind()
{
m_bound = false;
}
}
from magiccamera.
抱歉,水平有限看不出啥问题。。。
from magiccamera.
美颜功能是从MagicBeautyFilter.java和beautify_fragment.glsl两个文件中找就可以了吗
from magiccamera.
是的
from magiccamera.
@wuhaoyu1990 您好,我如果要在拍摄端加美颜滤镜,shader脚本和OpenGL部分需要做什么改变吗
from magiccamera.
我是在GPUImage基础上改的,你试试参照GPUImage看看
uniform sampler2D inputImageTexture;
varying highp vec2 textureCoordinate
这两个和GPUImage里的一样
只需要传入下面两个参数
uniform vec2 singleStepOffset;
uniform highp vec4 params;
from magiccamera.
哈哈 解决了,非常感谢
from magiccamera.
哈哈 解决了,非常感谢
大哥,你把美颜摘出来了吗?现在还能用吗?
from magiccamera.
Related Issues (20)
- Please help on the below Video recording issue
- how to capture full bitmap from after applied effect not draw to GLSurfaceView. HOT 6
- why not upgrade build system,and use cmake to build native code
- Get bitmap is incorrect when capturing from GLSurfaceView after applied Filter (on the device: Huawei has errors)
- 2019:MagicCameraNew 三年前的项目,新工具链已经无法编译,因此整理了一下,适配最新编译环境 HOT 5
- 请问这个项目有使用步骤吗?没有找到啊 HOT 2
- 用opengl shader实时处理问题
- 有事找你
- 录视频崩溃
- 怎么切换拍摄出来的 图片的比例
- 选择滤镜后再去使用美颜没有效果,而且选了滤镜拍摄后存的图是一张黑色图片,而且很小
- android studio版本的没有图片编辑功能啊
- VideoEncoderCore.java 针对视频采集的encodedData(ByteBuffer)是什么颜色格式?
- 这个项目是不是不会再维护了?
- 美颜是对人脸部分进行的,还是对整张图片进行的?
- 如果你启动不了不会配置gradle,请下载这个,我替换成了V4.1.3版本的 HOT 1
- Jni编译问题 HOT 2
- 重新整理该项目(Reorganize the project) HOT 3
- 可以加入图片取色修改和停止修图功能吗
- 美颜不起作用,是什么原因? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magiccamera.