当前位置:网站首页>Unityshader - materialcapture material capture effect (Emerald axe)
Unityshader - materialcapture material capture effect (Emerald axe)
2022-07-03 15:25:00 【ۓ Mingzhe ڪ】
Statement : This article is a personal note , For study and research, use non-commercial , The content is obtained from personal research and comprehensive arrangement , If there is a violation , Please contact the , Violations must be corrected .
UnityShader Study Directory
List of articles
Preface
Unity2019.3.6
AmplifyShaderEditor
One 、 Realization principle
The map follows the camera
Two 、 Effect and source code display
1. Photosphere effect
Effect description :
Through camera space , Put the map uv Follow the camera .
The renderings are as follows :
AmplifyShaderEditor The node diagram is as follows :
2. Emerald axe effect
Effect description
A gradient map is superimposed on effect one , Superimposed again matcap Mapping
The renderings are as follows :
AmplifyShaderEditor The node diagram is as follows :
The parameter setting is shown in the figure below :
The code is as follows :
Shader "Unlit/MatCap_Code"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {
}
_MatcapTex("MatcapTex",2D)="white"{
}// Gradient maps
_RampTex("RampTex",2D)="white"{
}
_MatcapAddTex("MatcapAddTex",2D)="white"{
}
_MatcapIntensity("Matcap Intensity",Float) = 1.0
_MatcapAddIntensity("MatcapAdd Intensity",Float)=1.0
}
SubShader
{
Tags {
"RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata// model data
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal:NORMAL;
};
struct v2f// Custom data The output of the vertex , Slice input
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldNormal : TEXCOORD1;
float3 worldPos:TEXCOORD2;
};
sampler2D _MainTex;
sampler2D _MatcapTex;
sampler2D _RampTex;
sampler2D _MatcapAddTex;
float4 _MainTex_ST;
float _MatcapIntensity;
float _MatcapAddIntensity;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
float3 worldNormal=mul(float4(v.normal,0.0),unity_WorldToObject);// It can be used for non proportional scaling without error .
//float3 worldNormal=UnityObjectToWorldNormal(v.normal);// Universal , Most of the time, the uplink code can be replaced
o.worldNormal=worldNormal;
o.worldPos=mul(unity_ObjectToWorld,v.vertex).xyz;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
half3 worldNormal= i.worldNormal;
//material capture MainTex
half3 viewSpaceNormal=mul(UNITY_MATRIX_V,float4(worldNormal,0.0)).xyz; // Normal phasor in camera space
half2 matcapUV=(viewSpaceNormal.xy+float2(1.0,1.0))*0.5;
half4 matcapColor=tex2D(_MatcapTex,matcapUV) *_MatcapIntensity;
half4 diffuseColor = tex2D(_MainTex, i.uv);
//fresnel Gradient mapping
// Calculate the world space view direction
half3 worldViewDir=normalize(UnityWorldSpaceViewDir(i.worldPos));
half ndotv=saturate(dot(i.worldNormal,worldViewDir));
half fresnel=1.0-ndotv;
half2 rampUV=half2(fresnel,0.5);
half4 rampColor=tex2D(_RampTex,rampUV);
half4 matcapAddColor=tex2D(_MatcapAddTex,matcapUV)*_MatcapAddIntensity;
half4 combined_color= diffuseColor*matcapColor * rampColor+matcapAddColor;
return combined_color;
}
ENDCG
}
}
}
post-processing :
Add tone mapping to the camera , Make the color brighter .
Be careful : The corresponding level should also be added to the camera , Otherwise, it will not show
summary
Keep hungry , Stay foolish .
The only thing the world can believe is your efforts and the road you have traveled .
边栏推荐
- What is machine reading comprehension? What are the applications? Finally someone made it clear
- Redis lock Optimization Practice issued by gaobingfa
- Introduction to redis master-slave, sentinel and cluster mode
- Kubernetes - yaml file interpretation
- Popular understanding of gradient descent
- What is embedding (encoding an object into a low dimensional dense vector), NN in pytorch Principle and application of embedding
- Unity功能——Unity离线文档下载及使用
- qt使用QZxing生成二维码
- Custom annotation
- Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
猜你喜欢

Kubernetes带你从头到尾捋一遍

视觉上位系统设计开发(halcon-winform)-4.通信管理

Jvm-04-runtime data area heap, method area

Can‘t connect to MySQL server on ‘localhost‘
![Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)](/img/cd/2e4f5884d034ff704809f476bda288.png)
Mysql报错:[ERROR] mysqld: File ‘./mysql-bin.010228‘ not found (Errcode: 2 “No such file or directory“)

Visual upper system design and development (Halcon WinForm) -3 Image control

Kubernetes will show you from beginning to end

秒杀系统1-登录功能

【可能是全中文网最全】pushgateway入门笔记

秒杀系统3-商品列表和商品详情
随机推荐
do{}while()的妙用
Visual upper system design and development (Halcon WinForm) -6 Nodes and grids
Using TCL (tool command language) to manage Tornado (for VxWorks) can start the project
What is label encoding? How to distinguish and use one hot encoding and label encoding?
北京共有产权房出租新规实施的租赁案例
Redis single thread problem forced sorting layman literacy
Unity功能——Unity离线文档下载及使用
自定义注解
Reentrantlock usage and source code analysis
函数栈帧的创建和销毁
mysql innodb 存储引擎的特性—行锁剖析
Search in the two-dimensional array of leetcode sword offer (10)
【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
CString中使用百分号
如何使用 @NotNull等注解校验 并全局异常处理
详解指针进阶1
使用JMeter对WebService进行压力测试
使用Tengine解决负载均衡的Session问题
PyTorch crop images differentiablly
[transform] [practice] use pytoch's torch nn. Multiheadattention to realize self attention