Kotlin
Creating shader for color inversion
Now our rendererer needs shader let's implement it
- Add fragmentShaderCode to the MyRenderer class:
private val fragmentShaderCode = """
precision mediump float;
uniform sampler2D Ytex;
uniform sampler2D Utex;
uniform sampler2D Vtex;
varying vec2 vTextureCoord;
void main() {
float nx = vTextureCoord.x;
float ny = vTextureCoord.y;
float y = texture2D(Ytex, vec2(nx, ny)).r;
float u = texture2D(Utex, vec2(nx, ny)).r - 0.5;
float v = texture2D(Vtex, vec2(nx, ny)).r - 0.5;
// Inverted Y color
y = 1.0 - 1.1643 * (y - 0.0625);
float r = y + 1.5958 * v;
float g = y - 0.39173 * u - 0.81290 * v;
float b = y + 2.017 * u;
gl_FragColor = vec4(r, g, b, 1.0);
}
""".trimIndent()
To render the video frames, the renderer class uses
OpenGLshaders. In this sample shader produces the inverted color effect, more precisely this is achieved by this liney = 1.0 - 1.1643 * (y - 0.0625);which is inside thefragmentShaderCodeFor full implementation of the renderer check the sample app implementation here
Basic video rendering
Learn how to use a custom video renderer in Kotlin to display a black-and-white version of a video stream using the Vonage Video Android SDK.
Steps
1
Introduction2
Getting Started3
Creating a new project4
Adding the Android SDK5
Setting up authentication6
Requesting permissions7
Creating the Inverted Video Renderer8
Creating a custom Renderer (MyRenderer)9
Publishing a stream to the session10
Connecting Custom Renderer to Publisher/Subscriber11
Running the app12
Conclusion