我想模糊视频通话中的摄像机预览。对于视频通话,我使用的是Tokbox。但是,模糊摄影机将间隔30秒,然后才能看到正常的摄影机预览。如果有人做到了,请帮忙。
我尝试使用Blurkit库,但没有帮助。最后我更改了一些着色器代码,但是tokbox只允许自定义渲染器一次。 30秒后如何更改。 到目前为止,我已经尝试了
更新
我正在尝试使用不同的片段着色器。 我正在使用2个顶点着色器和2个片段着色器(一个片段和顶点用于普通视图,一个片段和顶点着色器用于模糊视图)。
private final String vertexShaderCode = "uniform mat4 uMVPMatrix;"
+ "attribute vec4 aPosition;\n"
+ "attribute vec2 aTextureCoord;\n"
+ "varying vec2 vTextureCoord;\n" + "void main() {\n"
+ " gl_Position = uMVPMatrix * aPosition;\n"
+ " vTextureCoord = aTextureCoord;\n" + "}\n";
private final String fragmentShaderCode = "precision mediump float;\n"
+ "uniform sampler2D Ytex;\n"
+ "uniform sampler2D Utex,Vtex;\n"
+ "varying vec2 vTextureCoord;\n"
+ "void main(void) {\n"
+ " float nx,ny,r,g,b,y,u,v;\n"
+ " mediump vec4 txl,ux,vx;"
+ " nx=vTextureCoord[0];\n"
+ " ny=vTextureCoord[1];\n"
+ " y=texture2D(Ytex,vec2(nx,ny)).r;\n"
+ " u=texture2D(Utex,vec2(nx,ny)).r;\n"
+ " v=texture2D(Vtex,vec2(nx,ny)).r;\n"
//+ " y=1.0-1.1643*(y-0.0625);\n" // Invert effect
+ " y=1.1643*(y-0.0625);\n" // Normal renderer
+ " u=u-0.5;\n" + " v=v-0.5;\n" + " r=y+1.5958*v;\n"
+ " g=y-0.39173*u-0.81290*v;\n" + " b=y+2.017*u;\n"
+ " gl_FragColor=vec4(r,g,b,1.0);\n" + "}\n";
public static final String vertexShaderCode1 = "" +
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"const int GAUSSIAN_SAMPLES = 9;\n" +
"uniform vec2 singleStepOffset;\n" +
"varying vec2 vTextureCoord;\n" +
"varying vec2 blurCoordinates[GAUSSIAN_SAMPLES];\n" +
"void main()\n" +
"{\n" +
" gl_Position = aPosition;\n" +
" vTextureCoord = aTextureCoord.xy;\n" +
" int multiplier = 0;\n" +
" vec2 blurStep;\n" +
" for (int i = 0; i < GAUSSIAN_SAMPLES; i++)\n" +
" {\n" +
" multiplier = (i - ((GAUSSIAN_SAMPLES - 1) / 2));\n" +
" blurStep = float(multiplier) * singleStepOffset;\n" +
" blurCoordinates[i] = aTextureCoord.xy + blurStep;\n" +
" }\n" +
"}";
public static final String fragmentShaderCode1 = "" +
"uniform sampler2D Ytex;\n" +
" const lowp int GAUSSIAN_SAMPLES = 9;\n" +
" varying highp vec2 textureCoordinate;\n" +
" varying highp vec2 blurCoordinates[GAUSSIAN_SAMPLES];\n" +
" uniform mediump float distanceNormalizationFactor;\n" +
" void main()\n" +
" {\n" +
" lowp vec4 centralColor;\n" +
" lowp float gaussianWeightTotal;\n" +
" lowp vec4 sum;\n" +
" lowp vec4 sampleColor;\n" +
" lowp float distanceFromCentralColor;\n" +
" lowp float gaussianWeight;\n" +
" \n" +
" centralColor = texture2D(Ytex, blurCoordinates[4]);\n" +
" gaussianWeightTotal = 0.18;\n" +
" sum = centralColor * 0.18;\n" +
" \n" +
" sampleColor = texture2D(Ytex, blurCoordinates[0]);\n" +
" distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0);\n" +
" gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor);\n" +
" gaussianWeightTotal += gaussianWeight;\n" +
" sum += sampleColor * gaussianWeight;\n" +
" sampleColor = texture2D(Ytex, blurCoordinates[8]);\n" +
" distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0);\n" +
" gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor);\n" +
" gaussianWeightTotal += gaussianWeight;\n" +
" sum += sampleColor * gaussianWeight;\n" +
" gl_FragColor = sum / gaussianWeightTotal;\n" +
" }";
我想在单击按钮时在两个片段着色器之间切换。我已经尝试过类似的操作 在OnDrawFrame()
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
mProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(mProgram, vertexShader);
GLES20.glAttachShader(mProgram, fragmentShader);
GLES20.glLinkProgram(mProgram);
GLES20.glUseProgram(mProgram);
但是它不起作用。所以我的问题是如何在2个不同的片段着色器之间切换。