Unity 窗体透明
文章转自游戏蛮牛:http://www.manew.com/forum.php?mod=viewthread&tid=103087&_dsign=ec6d9a3d
using System;
using System.Runtime.InteropServices;
using UnityEngine;public class TransparentWindow : MonoBehaviour
{[SerializeField]private Material m_Material;private struct MARGINS{public int cxLeftWidth;public int cxRightWidth;public int cyTopHeight;public int cyBottomHeight;}// Define function signatures to import from Windows APIs[DllImport("user32.dll")]private static extern IntPtr GetActiveWindow();[DllImport("user32.dll")]private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);[DllImport("Dwmapi.dll")]private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);// Definitions of window stylesconst int GWL_STYLE = -16;const uint WS_POPUP = 0x80000000;const uint WS_VISIBLE = 0x10000000;void Start(){
#if !UNITY_EDITORvar margins = new MARGINS() { cxLeftWidth = -1 };// Get a handle to the windowvar hwnd = GetActiveWindow();// Set properties of the window// See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspxSetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);// Extend the window into the client area//See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512%28v=vs.85%29.aspx DwmExtendFrameIntoClientArea(hwnd, ref margins);
#endif}// Pass the output of the camera to the custom material// for chroma replacementvoid OnRenderImage(RenderTexture from, RenderTexture to){Graphics.Blit(from, to, m_Material);}
}
Shader "Custom/ChromakeyTransparent" {Properties{_MainTex("Base (RGB)", 2D) = "white" {}_TransparentColourKey("Transparent Colour Key", Color) = (0,0,0,1)_TransparencyTolerance("Transparency Tolerance", Float) = 0.01}SubShader{Pass{Tags{ "RenderType" = "Opaque" }LOD 200CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"struct a2v{float4 pos : POSITION;float2 uv : TEXCOORD0;};struct v2f{float4 pos : SV_POSITION;float2 uv : TEXCOORD0;};v2f vert(a2v input){v2f output;output.pos = UnityObjectToClipPos(input.pos);output.uv = input.uv;return output;}sampler2D _MainTex;float3 _TransparentColourKey;float _TransparencyTolerance;float4 frag(v2f input) : SV_Target{// What is the colour that *would* be rendered here?float4 colour = tex2D(_MainTex, input.uv);// Calculate the different in each component from the chosen transparency colourfloat deltaR = abs(colour.r - _TransparentColourKey.r);float deltaG = abs(colour.g - _TransparentColourKey.g);float deltaB = abs(colour.b - _TransparentColourKey.b);// If colour is within tolerance, write a transparent pixelif (deltaR < _TransparencyTolerance && deltaG < _TransparencyTolerance && deltaB < _TransparencyTolerance){return float4(0.0f, 0.0f, 0.0f, 0.0f);}// Otherwise, return the regular colourreturn colour;}ENDCG}}
}
Unity 窗体透明相关推荐
- delphi 窗体透明详解TransparentColorValue,窗体透明控件不透明
关于窗体透明的做法 来自:http://blog.csdn.net/shuaihj/article/details/8610343 关于窗体透明的做法 1.在Delphi中,设置窗体的AlphaBle ...
- unity自发光透明shader
unity自发光透明shader 这本来是一个glass的shader,但是我发现也可以用到自发光+透明,这两个脚本都是unity文档里面的.呵呵~~~ [html] view plaincopypr ...
- xp下编程实现窗体透明特效
本文主要介绍了Windows 2000下新增的API函数SetLayeredWindowAttributes()以及通过该函数实现窗体透明特效的一般方法 摘要:本文主要介绍了Windows 2000下 ...
- Unity3D下实现Linux平台RTMP推流(以采集Unity窗体和声音为例)
技术背景 随着物联网等行业的崛起,越来越多的传统行业如虚拟仿真.航天工业.工业仿真.城市规划等,对Linux下的生态构建,有了更大的期望,Linux平台下,可选的直播推拉流解决方案相对Windows和 ...
- au3 窗体透明及半透明
透明效果技术要点: A: _winapi_SetLayeredWindowAttributes ()这个函数+ $WS_EX_LAYERED +$LWA_COLORKEY 实现透明效果的效果 B:_w ...
- 【转载】Layered Window(分层窗体,透明窗体)
本文转载自花间醉卧<Layered Window(分层窗体,透明窗体)> // 为窗体添加 WS_EX_LAYERED 属性 , 该属性使窗体支持透明 ModifyStyleEx (0, ...
- Unity 设置窗体透明
设置窗口透明.窗口置顶.鼠标穿透 方法一. 缺点:边缘不平滑,有毛边 参考博客: 1.https://alastaira.wordpress.com/2015/06/15/creating-wi ...
- android 窗体透明的,黑暗度等的设置技巧
设置透明度(这是窗体本身的透明度,非背景) 1 WindowManager.LayoutParams lp=getWindow().getAttributes(); 2 lp.alpha=0.3f; ...
- Unity Shader透明效果
在实时渲染中要实现透明效果,通常会在渲染模型时控制他的透明通道.当开启透明混合后,当一个物体被渲染到屏幕上时,每个片元除了颜色值和深度值之外,它还有另一个属性--透明度.当透明度为1时表示该像素是完全 ...
最新文章
- 自制清理电脑里的垃圾软件
- Android之解析XML
- css3 自定义滚动条样式
- libevent -简单的异步IO介绍
- flask的ajax的csrf代码
- 计算机的前端总线又称为,《计算机组成原理》复习资料
- C++ multimap的插入
- python图像质量评价_OpenCV图像质量评价的SSIM算法(图像相似度)
- Spark-TaskSchedule和TaskScheduleImpl解释和过程
- 期末C语言45分能过的吗,C语言—期末小黄衫获奖感言
- 2017年英国机器人周:身体有问题 就找机器人
- Linux中vi的退出命令
- 升级ios13后,iPhone手机新增了截长屏功能,实用又方便
- 电脑未安装任何音频设备解决办法
- Power Designer创建概念数据模型
- 听说你的淘客群又做死了?来学学群维护这几招!
- 使用对比学习处理大规模多模态单细胞数据
- Cacti--cacti数据库详解
- canonical是什么意思
- CMS垃圾回收器详解