粒子特效"/>
unity使用RenderTexture可以渲染粒子特效
一,使用UIRawImage,创建材质球,把Shader给材质球,放到RawImage的Material上,
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "UI/Default No-Alpha"
{Properties{[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}_Color("Tint", Color) = (1,1,1,1)_StencilComp("Stencil Comparison", Float) = 8_Stencil("Stencil ID", Float) = 0_StencilOp("Stencil Operation", Float) = 0_StencilWriteMask("Stencil Write Mask", Float) = 255_StencilReadMask("Stencil Read Mask", Float) = 255_ColorMask("Color Mask", Float) = 15}SubShader{Tags{"Queue" = "Transparent""IgnoreProjector" = "True""RenderType" = "Transparent""PreviewType" = "Plane""CanUseSpriteAtlas" = "True"}Stencil{Ref[_Stencil]Comp[_StencilComp]Pass[_StencilOp]ReadMask[_StencilReadMask]WriteMask[_StencilWriteMask]}Cull OffLighting OffZWrite OffZTest[unity_GUIZTestMode]Fog { Mode Off }Blend One ZeroColorMask[_ColorMask]Blend One OneMinusSrcAlpha // 源rgba*1 + 背景rgba*(1-源A值) Pass{CGPROGRAM#pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata_t{float4 vertex : POSITION;float4 color : COLOR;float2 texcoord : TEXCOORD0;};struct v2f{float4 vertex : SV_POSITION;fixed4 color : COLOR;half2 texcoord : TEXCOORD0;};fixed4 _Color;v2f vert(appdata_t IN){v2f OUT;OUT.vertex = UnityObjectToClipPos(IN.vertex);OUT.texcoord = IN.texcoord;#ifdef UNITY_HALF_TEXEL_OFFSET OUT.vertex.xy -= (_ScreenParams.zw - 1.0);#endif OUT.color = IN.color * _Color;return OUT;}sampler2D _MainTex;fixed4 frag(v2f IN) : SV_Target{half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;//clip (color.a - 0.01); return color;}ENDCG}}
}
最后设置摄像机ClearFlags:Solid Color,
BackGround为黑色
更多推荐
unity使用RenderTexture可以渲染粒子特效
发布评论