Unity Shader implements "Nitrogen Acceleration Special Effects"

1: Materials and shaders

Shader is a kind of code executed for GPU, the rendering pipeline of GPU, in order to facilitate developers to customize the effect, open the interface for programmers to write code to control, this kind of program is called shader, shader development language, cocos uses GLSL programming language. Developers can insert code in the vertex shader and shader shader of the following figure.

Material is a configuration file, choose a Shader (algorithm), and provide the necessary parameters for the Shader. When the game engine draws an object, it first reads the material, and configures the GPU with the parameters required by the shader and shader according to the material. In this way, the pipeline pipeline can complete the drawing of the object.

2: Preparations

Prepare a bullet head model (bullet train ^_^)

Prepare a texture with accelerated flame and transparent gradient:

3: The effect achieved:

4: Above code:

Shader "Custom/additiveTex_2" {
	Properties {
		_TintColor ("Tint Color", Color) = (0.5, 0.5, 0.5, 0.5)
		_Intensity ("Intensity", Float) = 1.0
		_MainTexture ("Base (RGB) Alpha(A)", 2D) = "white" {}
		_Mask    ("Mask (ARGB or Grayscale)", 2D) = "white" {}
		_speed("speed",Float)=5
	}
	
	Category {
		Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
			
	    Blend SrcAlpha One
	    AlphaTest Greater 0.01
	    ColorMask RGB
	    Cull Off
	    Lighting Off
	    ZWrite Off

	    // Fog { Color (0,0,0,0) }
		/*BindChannels {
	        Bind "Color", color
	        Bind "Vertex", vertex
	        Bind "TexCoord", texcoord
    	}*/

		SubShader {
			Pass {
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#pragma fragmentoption ARB_precision_hint_fastest

				#include "UnityCG.cginc"

				fixed4 _TintColor;
				float  _Intensity;
				sampler2D _MainTexture;
				sampler2D _Mask;

				float _speed;

				float4 _MainTexture_ST;
				float4 _Mask_ST;
				
				struct appdata_t {
					float4 vertex : POSITION;
					fixed4 color : COLOR;
					float2 texcoord : TEXCOORD0;
					float2 texcoord2 : TEXCOORD1;
				};

				struct v2f {
					float4 vertex : POSITION;
					fixed4 color : COLOR;
					float2 texcoord : TEXCOORD0;
					float2 texcoord2 : TEXCOORD1;
				};

				v2f vert (appdata_t v)
				{
					v2f o;
					o.vertex = UnityObjectToClipPos(v.vertex);
					o.color = v.color;
					o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTexture);
					o.texcoord2 = TRANSFORM_TEX(v.texcoord2,_Mask);
					return o;
				}
					
				fixed4 frag (v2f i) : COLOR
				{
					i.texcoord.x+=_Time*_speed;
					i.texcoord.y-=(_Time*_speed*16);
					
					half4 c = i.color * _TintColor * tex2D(_MainTexture, i.texcoord);
					half4 mask = tex2D(_Mask, i.texcoord2);
					c *= mask.a;
					return _Intensity * c;					
				}
				ENDCG 
			}
		}
	} 
	FallBack "Diffuse"
}

The detailed video explanation of the nitrogen acceleration effect, and the project engineering, can be added to the learning discussion group. Today's sharing is over here, thank you.

Guess you like

Origin blog.csdn.net/voidinit/article/details/126478394