当前位置:网站首页>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
}
}
}
后处理:
相机上添加色调映射,让颜色更鲜艳一些.
注意:相机上也要添加上对应层级,不然不显示
总结
保持饥饿,保持愚蠢.
这世界唯一能够相信的就是你付出的努力和你走过的路.
边栏推荐
- 详解指针进阶2
- Kubernetes vous emmène du début à la fin
- Kubernetes带你从头到尾捋一遍
- 视觉上位系统设计开发(halcon-winform)-1.流程节点设计
- 函数栈帧的创建和销毁
- Visual upper system design and development (Halcon WinForm) -5 camera
- Baidu AI Cloud helps Shizuishan upgrade the smart health care model of "Internet + elderly care services"
- What is machine reading comprehension? What are the applications? Finally someone made it clear
- What is label encoding? How to distinguish and use one hot encoding and label encoding?
- Kubernetes - YAML文件解读
猜你喜欢

Construction of operation and maintenance system
![[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

Concurrency-02-visibility, atomicity, orderliness, volatile, CAS, atomic class, unsafe

Redis lock Optimization Practice issued by gaobingfa

Matplotlib drawing label cannot display Chinese problems

Creation and destruction of function stack frames

Seckill system 3- product list and product details

redis缓存穿透,缓存击穿,缓存雪崩解决方案

Leasing cases of the implementation of the new regulations on the rental of jointly owned houses in Beijing

Introduction, use and principle of synchronized
随机推荐
详解指针进阶1
Basic SQL tutorial
String functions that you need to know
Kubernetes will show you from beginning to end
【日常训练】395. 至少有 K 个重复字符的最长子串
Summary of concurrent full knowledge points
Detailed pointer advanced 2
Tensorflow realizes verification code recognition (III)
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
Explanation of time complexity and space complexity
自定义注解
[daily training] 395 Longest substring with at least k repeated characters
SQL server installation location cannot be changed
SQL server安装位置改不了
Apache ant extension tutorial
整形和浮点型是如何在内存中的存储
Introduction, use and principle of synchronized
The markdown file obtains the pictures of the network and stores them locally and modifies the URL
[attention mechanism] [first vit] Detr, end to end object detection with transformers the main components of the network are CNN and transformer
Puppet自动化运维排错案例