Unity shaderGraph example-scanning effect

Show results

Please add image description

the whole frame

Insert image description here

Content of each region

Area 1

Insert image description here
Subtract the depth of view (Z value) of the vertex's View space from the scene depth. The Z value needs to be multiplied by -1 because the depth of view of the object vertex seen from the camera is -1, and the scene depth is a positive value, so it needs to be multiplied by -1. -1 makes both positive.

The meaning of this step is to subtract the depth of field of view of the sphere from the depth in the scene. When the sphere is close to the object in the scene, the difference will be very close to 0, as shown below
Insert image description here

View space is similar to screen coordinates. It is always (0,0,0) in the center of the screen, positive X is to the left, positive Y is positive upward, and positive Z is to the inside of the camera lens.

Area 2

Can be used to expand or reduce scope
Insert image description here

Area 3

Insert image description here
Clamp the value to 0-1 and round it, so you can get a very sharp scanning edge. If you don't round it, you will get a gradient effect.

Area 4

Insert image description here
Subtract the previous value from 1 to invert black and white, as follows
Insert image description here

Area 5

Insert image description here
Give the white line a color

Area 6

Insert image description here
Output color, use black area as transparent channel

GraphSetttings

Insert image description here
Change to transparent

Precautions

Need to make sure the camera has depth texture turned on
Insert image description here

Instructions

We can adjust the scan by scaling the shpere

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScannerController : MonoBehaviour
{
    
    
    public float speed = 10;
    public float delay_destory_time=5;
    private void Start()
    {
    
    
        Destory_Object();
    }
    void Update()
    {
    
    
        Vector3 vectorMesh = transform.localScale;
        float growing = this.speed * Time.deltaTime;
        transform.localScale = new Vector3(vectorMesh.x+growing,vectorMesh.y+growing,vectorMesh.z+growing);
    }
    private void Destory_Object()
    {
    
    
        Destroy(gameObject,delay_destory_time);
    }
}

Guess you like

Origin blog.csdn.net/weixin_44568736/article/details/134450373