Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Chroma key / green screen - Gideros Forum

Chroma key / green screen

totebototebo Member
edited January 2017 in General questions
How feasible would chroma key be in Gideros? Ideally in real-time using camera. Second best take a photo with camera and key out a colour afterwards.
My Gideros games: www.totebo.com

Comments

  • hgy29hgy29 Maintainer
    Accepted Answer
    Possible using the camera plugin and a shader :)

    Likes: totebo

    +1 -1 (+1 / -0 ) Share on Facebook
  • Nice one, I should have guessed!

    Likes: pie

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 ) Share on Facebook
  • hgy29hgy29 Maintainer
    edited January 2017 Accepted Answer
    For the record:
    require "camera"
     
    local ChromaKeyVShader=
    [[
    attribute vec4 POSITION0;
    attribute vec2 TEXCOORD0;
     
    uniform mat4 g_MVPMatrix;
     
    varying mediump vec2 texCoord;
     
    void main()
    {
    	gl_Position = g_MVPMatrix * POSITION0;
    	texCoord = TEXCOORD0;
    }
    ]]
     
    local ChromaKeyFShader=[[
    uniform lowp sampler2D gCam;
    uniform lowp sampler2D gTexture;
    varying mediump vec2 texCoord;
     
    #ifdef GLES2
    precision mediump float;
    #endif
     
    mediump vec3 rgb2hsv(vec3 c)
    {
        mediump vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
        mediump vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
        mediump vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
     
        mediump float d = q.x - min(q.w, q.y);
        mediump float e = 1.0e-10;
        return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
    }
     
    void main()
    {
    	lowp vec4 colorTex = texture2D(gTexture, texCoord);
    	lowp vec4 colorCam = texture2D(gCam, texCoord);
    	vec3 hsv=rgb2hsv(colorCam.rgb);
    	gl_FragColor=colorTex;
    	if ((hsv.x>0.7)||(hsv.x
    +1 -1 (+2 / -0 ) Share on Facebook
Sign In or Register to comment.