当前位置:网站首页>UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
UnityShader——MaterialCapture材质捕捉效果 (翡翠斧头)
2022-07-03 15:22:00 【ۓ明哲ڪ】
声明:本文为个人笔记,用于学习研究使用非商用,内容为个人研究及综合整理所得,若有违规,请联系,违规必改。
UnityShader学习目录
前言
Unity2019.3.6
AmplifyShaderEditor
一、实现原理
贴图跟随摄像机移动
二、效果及源码展示
1.光球效果
效果描述:
通过相机空间,把贴图uv跟随相机移动.
效果图如下:
AmplifyShaderEditor节点图如下:
2.翡翠斧头效果
效果描述
在效果一的基础上叠加了渐变贴图,又叠加了一次matcap贴图
效果图如下:
AmplifyShaderEditor节点图如下:
参数设置如下图:
代码如下:
Shader "Unlit/MatCap_Code"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {
}
_MatcapTex("MatcapTex",2D)="white"{
}//渐变贴图
_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//模型数据
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal:NORMAL;
};
struct v2f//自定义数据 顶点的输出,片元的输入
{
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);//可适用非等比缩放而不出错.
//float3 worldNormal=UnityObjectToWorldNormal(v.normal);//通用,多数时候可替换上行代码
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; //相机空间下法相向量
half2 matcapUV=(viewSpaceNormal.xy+float2(1.0,1.0))*0.5;
half4 matcapColor=tex2D(_MatcapTex,matcapUV) *_MatcapIntensity;
half4 diffuseColor = tex2D(_MainTex, i.uv);
//fresnel 渐变映射
// 计算世界空间视图方向
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
}
}
}
后处理:
相机上添加色调映射,让颜色更鲜艳一些.
注意:相机上也要添加上对应层级,不然不显示
总结
保持饥饿,保持愚蠢.
这世界唯一能够相信的就是你付出的努力和你走过的路.
边栏推荐
- Solve the problem that pushgateway data will be overwritten by multiple push
- Popular understanding of ovo and ovr
- Tensorflow realizes verification code recognition (II)
- 阿特拉斯atlas扭矩枪 USB通讯教程基于MTCOM
- The method of parameter estimation of user-defined function in MATLAB
- 视觉上位系统设计开发(halcon-winform)-4.通信管理
- Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
- Leetcode sword offer find the number I (nine) in the sorted array
- Functional modules and application scenarios covered by the productization of user portraits
- 在MapReduce中利用MultipleOutputs输出多个文件
猜你喜欢

Visual host system design and development (Halcon WinForm)

第04章_逻辑架构

Jvm-06-execution engine

Popular understanding of random forest

mysql innodb 存储引擎的特性—行锁剖析
![[probably the most complete in Chinese] pushgateway entry notes](/img/5a/6dcb75f5d713ff513ad6842ff53cc3.png)
[probably the most complete in Chinese] pushgateway entry notes
![[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University](/img/83/922efb4f88843f1b7feaccf2b515b9.jpg)
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University

Popular understanding of linear regression (II)

Detailed pointer advanced 2

Creation and destruction of function stack frames
随机推荐
Matplotlib drawing label cannot display Chinese problems
socket. IO build distributed web push server
Leetcode the smallest number of the rotation array of the offer of the sword (11)
视觉上位系统设计开发(halcon-winform)-5.相机
Concurrency-01-create thread, sleep, yield, wait, join, interrupt, thread state, synchronized, park, reentrantlock
官网MapReduce实例代码详细批注
Redis single thread problem forced sorting layman literacy
Kubernetes带你从头到尾捋一遍
Halcon与Winform学习第二节
Halcon and WinForm study section 2
What is label encoding? How to distinguish and use one hot encoding and label encoding?
Using multipleoutputs to output multiple files in MapReduce
How to use annotations such as @notnull to verify and handle global exceptions
Search in the two-dimensional array of leetcode sword offer (10)
Custom annotation
Digital image processing -- popular Canny edge detection
PyTorch crop images differentiablly
【pytorch学习笔记】Transforms
Can‘t connect to MySQL server on ‘localhost‘
Kubernetes vous emmène du début à la fin