Unity Kinect v2 with ms-sdk20 green screen keying shader modify transparent background

Source: Internet
Author: User

It's kinect2.0.

Kinect v2 with Ms-sdk20 plugin

In the example of the default greenscreen inside is green, the request is changed to transparent, the following directly on the code

Let's get the background and see if it's transparent.

Shader "Dx11/greenscreenshader" {subshader {///transparent requires this Blend Srcalpha oneminussrcalpha Tags {"Queue" = "alphatest"} Pas s {cgprogram #pragma target 5.0 #pragma vertex vert #pragma fragment frag #include "unitycg.cginc" texture2d _maintex  ;  Sampler SampleType;     struct Vs_input {float4 pos:position; FLOAT2 tex:texcoord0;  }; Structuredbuffer<float2> depthcoordinates;  Structuredbuffer<float> Bodyindexbuffer;     struct Ps_input {float4 pos:sv_position; FLOAT2 tex:texcoord0;  };     Ps_input Vert (Vs_input v) {ps_input o;     O.pos = Mul (UNITY_MATRIX_MVP, V.pos);     O.tex = V.tex;     Flip x texture coordinate to mimic mirror.     o.tex.x = 1-v.tex.x; return o;          } float4 Frag (Ps_input I, in uint Id:sv_instanceid): COLOR {float4 o;     int colorwidth = (int) (i.tex.x * (float) 1920);     int colorheight = (int) (I.TEX.Y * (float) 1080);          int colorindex = (int) (Colorwidth + colorheight * (float) 1920); o = float4 (0, 0, 0, 0);          <--here I set Alpha to zero in my version//to feed into transparent/cutout/diffuse if (!isinf (depthcoordinates[colorindex].x) &&!isnan (depthcoordinates[colorindex].x) && Depthcoor          Dinates[colorindex].x! = 0) | | !isinf (DEPTHCOORDINATES[COLORINDEX].Y) &&!isnan (DEPTHCOORDINATES[COLORINDEX].Y) &&  Depthcoordinates[colorindex].y! = 0) {//We have valid depth data coordinates from our coordinate mapper.         Find player mask from corresponding depth points.         float player = bodyindexbuffer[(int) depthcoordinates[colorindex].x + (int) (DEPTHCOORDINATES[COLORINDEX].Y * 512)];         if (player! = 255) {o = _maintex.sample (SampleType, I.tex);      }else o.a = O.rgb; }//Float4 sampler2[9];//float4 minValue = FLOAT4 (255,255,255,255);//for (int i = 0; i < 9; ++i) {//sampler2[i] = texture2d (SampleType, Gl_texcoord[0].st+ tc_offset[i]); MinValue = min (MinValue, sampler2[i]);//} return o;  } ENDCG}} Fallback Off}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unity Kinect v2 with ms-sdk20 green screen keying shader modify transparent background

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.