unity Kinect v2 with MS-SDK20绿屏抠像shader修改 透明背景
来源:互联网 发布:头戴耳机推荐 知乎 编辑:程序博客网 时间:2024/06/12 01:51
用的是kinect2.0
Kinect v2 with MS-SDK20插件
例子中的默认greenscreen里面是绿色的,要求改成透明的,下面直接上代码
改完后放背景看看吧 是不是透明了
Shader "DX11/GreenScreenShader" { SubShader { //透明就需要这个 Blend SrcAlpha OneMinusSrcAlpha Tags {"Queue"="AlphaTest" } Pass { 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) && depthCoordinates[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}
0 0
- unity Kinect v2 with MS-SDK20绿屏抠像shader修改 透明背景
- unity透明shader
- unity自发光透明shader
- unity自发光透明shader
- Unity Shader学习笔记:透明
- Unity Shader修改Shader属性
- Unity Shader 剔除黑色背景
- Unity Shader 剔除黑色背景
- 用shader使图片背景透明
- Unity Shader 小功能之 透明
- Unity Shader 六 双面透明效果
- Unity Shader入门精要总结--透明效果
- 【Unity Shader入门精要】— 透明效果
- UISearchBar 修改背景颜色透明
- Kinect for Unity V2 代码示例(一)
- Kinect for Unity V2 代码示例(二)
- Kinect for Unity V2 代码示例(三) 手势控制
- 【Unity Shader】用shader控制背景的倾斜渐变
- 在需求分析中就可以避免的那些错误8
- git cherry-pick 时遇到 cannot merge binary files问题解决办法
- 机器学习算法面试—口述(5):回归
- UI18_单例
- HashMap 和ConcurrentHashMap
- unity Kinect v2 with MS-SDK20绿屏抠像shader修改 透明背景
- iOS沙盒路径的查看和使用
- ubuntu12.04向MATLAB/R2014b/toolbox里添加工具箱
- linux内核架构-中断处理机制
- ARP攻击实战之WinArpAttacker
- Win+R+快捷键
- oc 翻译到cocos2dx 过程中的知识点
- OpenCv中混合高斯模型的实现
- 黑马程序员——java基础——Java中的常量及变量