笔 笔 笔 1 1: tree -shaped DP

2022-12-26   ES  

first effect map
2D version:
在这里插入图片描述
3D version:
在这里插入图片描述
Xiaolan made a fatal blow in Xiaohong’s dying state. The characters turned into black silhouette effects. The scene coordination became yellow and white alternate and flickered. It is the combination scene and the characters to make an overall combination of performance killing effects, so take the name for the time being ~)

At the moment of killing, call the setreplacementshader method, and temporarily replace the character’s shadeer into the rendering method of the black silhouette effect. What we have to prepare is to achieve the rendering effect we want.official addressteleportation, the official examples are as follows:

Shader "EffectShader" {
    
     SubShader {
    
         Tags {
     "RenderType"="Opaque" }
         Pass {
    
             ...
         }
     }
     SubShader {
    
         Tags {
     "RenderType"="SomethingElse" }
         Pass {
    
             ...
         }
     }
 ...
 }

Calling method:

The official example of

void Start() {
    
    camera.SetReplacementShader (EffectShader, "RenderType");
}

is simple and clear, and it is the first time I use the TAG label with the TAG tag. Since this API wants to replace the shadeer from the operation, of course, it must be notified of the corresponding relationship of replacement in order to meet our expectations. The keyword of rendertype is used. The effect of this API is to find the value of the TAG of the RENDERTYPE in the object rendered by this camera (calling the API camera). The subshader replaced the shadeer that matches it, and the part that is not matched is not visible. Therefore, the EffectShader here should also do special processing, guessing that the main execution is mainly performed, not normal execution. After all, a shadeer has only one subshader to participate in execution.

The second parameter here is the key that the user passed in. Of course, it can also be defined by themselves. Maybe it is easier to understand the understanding of Setreplacementshader.

Prepare to replace the Shader, there are two subshader, one rendering black silhouette, and a flicker of the rendering scene:

Shader "Hidden/KillEffect_2D"
{
    
	Properties
	{
    
		_MainTex("Texture", 2D) = "white" {
    }
	}

	SubShader
	{
    
		Tags {
     "BattleType" = "Scene" }
		Pass
		{
    
			CGPROGRAM
			#pragma vertex vert_2d
			#pragma fragment frag_2d_flash
			#include "UnityCG.cginc"
			#include "BattleKillSceneInclude.cginc"
			ENDCG
		}
	}

	SubShader
	{
    
		Tags {
     "BattleType" = "Army" }
		Pass
		{
    
			CGPROGRAM
			#pragma vertex vert_2d
			#pragma fragment frag_2d_black_army
			#include "UnityCG.cginc"
			#include "BattleKillSceneInclude.cginc"
			ENDCG
		}
	}
}

Here I use the TAG keyword is BattleType to create a corresponding relationship. My character renders the tag of Shader:

Tags {
     "BattleType" = "Army" "LightMode" = "ForwardBase"}

Scene object tag:

Tags {
     "BattleType" = "Scene" "LightMode" = "ForwardBase"}

The next time is at the time of killing. C# calls Camera.setRePlacementShader for replacement operation:

 Shader killEffect = Shader.Find("Hidden/KillEffect");
 Time.timeScale = 0.15f;// Slow action
 Camera.main.SetReplacementShader(killEffect, "BattleType");
 yield return new WaitForSecondsRealtime(3);
 Time.timeScale = 1;
 // Restore operation, restore normal rendering
 Camera.main.ResetReplacementShader();

black silhouette, simply set color to pure black, and yellow and white flickering can be returned directly with simple color values. There is no need to go through the steps of texture sampling (my scene has no texture…) ,code show as below

fixed4 frag_2d_flash(v2f i) : SV_Target
{
    
	half2 time = PerFun010(FLASH_COLOR_YELLOE_DURATION, FLASH_COLOR_WHITE_DURATION);
	if (time.y == 0)
	{
    
		return fixed4(FLASH_COLOR_YELLOE, 1);
	}
	else {
    
		return fixed4(FLASH_COLOR_WHITE, 1);
	}
}

The time control of the yellow and white alternate here is in the Perfun010 method, simply simulation a periodic linear change:

Y means at which stage, the T1 phase is 0 and the T2 stage is 1. The effect here is because you only need to know the stage, so the judgment condition is written

// linear change 0 -> 1 -> 0...
inline half2 PerFun010(half T1, half T2)
{
    
	half T = T1 + T2;
	half x = fmod(_Time.y, T);
	int stepValue = step(T1, x);

	return half2((1 - stepValue) * x / T1 + stepValue * (1 - (x - T1) / T2), stepValue);
}

if (time.y == 0)

It must have a 3D feeling, and the law line is the key. Diffuse and Specular in the light model are inseparable from the normal line. Here is also the calculation of the direction of the legal line and light, which reflects a 3D feeling in the superimposed color. In the Vert, DOT operations are performed through the light direction and the method line, and then POW is taken, similar to the processing of highlight SPECular:

v2f_3d vert_3d(appdata v)
{
    
	v2f_3d o;
	o.vertex = UnityObjectToClipPos(v.vertex);
	o.uv = TRANSFORM_TEX(v.uv, _MainTex);

	fixed3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
	fixed3 worldNormal = normalize(UnityObjectToWorldNormal(v.normal));
	fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);
	o.specular = pow(abs(dot(worldLightDir, worldNormal)), 0.3h);
	return o;
}

source

Related Posts

qt (5.10.0) for Android

Install VS2010 Chinese flagship version of Deepwater

POJ 2185 Milking Grid

java thread pool?

笔 笔 笔 1 1: tree -shaped DP

Random Posts

MAC system Install XGBOOST

linux virtual network device tun/tap

Sword refers to OFFER-flip word sequence sequence Hanani

Announcement on closing the credit card recharge channel to the Alipay account

HF-NET (2) Global feature positioning and local feature matching based on HF-Net