Home>
Let's look at the effect first.
I use the post-processing effect of the screen,First go to photoshop to make a picture as follows,Just use the paintbrush to make a point,Use it to process images captured by the camera.
Add a script file to the camera
using system.collections;
using system.collections.generic;
using unityengine;
public class testscript:monobehaviour
{
[range (0,3)]
public float lerp=0;//Use it to adjust the size of the viewable area
public texture2d masktex;
public shader screanshader;
public material getmaterial
{
get
{
if (_material == null) _material=new material (screanshader);
return _material;
}
}
private material _material=null;
//src is the photo captured by the camera,dest is the processed picture
void onrenderimage (rendertexture src, rendertexture dest)
{
getmaterial.settexture ("_ maintex", src);
getmaterial.settexture ("_ masktex", masktex);
getmaterial.setfloat ("_ lerp", lerp);
graphics.blit (src, dest, getmaterial);
}
}
The corresponding shader, the idea is to flip the color of masktex and then multiply it directly.The decimal is multiplied the smaller,The smaller the color, the darker the color.
shader "wzhhh/myshader2" {
properties {
_maintex ("maintex", 2d)="white" {}
_masktex ("masktex", 2d)="white" {}
_lerp ("lerp", range (0,3))=1
}
subshader {
pass {
tags {"lightmode"="forwardbase"}
cgprogram
#include "lighting.cginc"
#pragma vertex vert
#pragma fragment frag
sampler2d _masktex;
sampler2d _maintex;
float4 _maintex_st;
float _alphabase;
float _lerp;
struct a2v {
float4 vertex:position;
float2 texcoord:texcoord0;
};
struct v2f {
float4 pos:sv_position;
fixed2 uv:texcoord0;
};
v2f vert (a2v i) {
v2f o;
o.pos=unityobjecttoclippos (i.vertex);
o.uv=transform_tex (i.texcoord, _maintex);
return o;
}
fixed4 frag (v2f o):sv_target {
fixed4 color=tex2d (_masktex, o.uv);
color.r=1-color.r;
color.g=1-color.g;
color.b=1-color.b;
fixed4 color2=tex2d (_maintex, o.uv);
color2.r *=color.r * _lerp;
color2.g *=color.g * _lerp;
color2.b *=color.b * _lerp;
return color2;
}
endcg
}
}
}
Related questions
- Unity Shader achieves cutting effect
- Unity Shader realizes the sketch effect
- Unity Shader implements sketch-style rendering
- Unity Shader achieves graphics drawing (blue sky, white clouds and sea)
- Unity shader realizes the effect of vertex animation wave
- Unity shader to achieve glass refraction effect
- Unity Shader achieves dynamic fog effect
- Unity Shader achieves glass material effect
- Unity Shader intersection algorithm realizes simple anti-energy shield