当前位置:网站首页>Implementation of simple matcap+fresnel shader in unity
Implementation of simple matcap+fresnel shader in unity
2022-07-29 07:57:00 【TingQiaoQiao】
Shader "Unlit/matcap"{
//matcap
Properties{
_NormalMap(" Normal map ", 2D) = "bump" {}
_Matcap("matcap", 2D) = "white" {}
_FresnelPow(" Fresnel intensity ",Range(0,5)) = 1
_EnvSpeInt(" Environmental reflection intensity ",Range(0,5)) = 1
}
SubShader{
Tags {
"RenderType" = "Opaque"
}
Pass {
Name "FORWARD"
Tags {
"LightMode" = "ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma target 3.0
// Input parameters
uniform sampler2D _NormalMap;
uniform sampler2D _Matcap;
uniform float _FresnelPow;
uniform float _EnvSpeInt;
// Input structure
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 uv0 : TEXCOORD0;
};
// Output structure
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float3 nDirWS : TEXCOORD1;
float3 tDirWS : TEXCOORD2;
float3 bDirWS : TEXCOORD3;
float3 posWS : TEXCOORD4;
};
VertexOutput vert(VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.uv0;
o.nDirWS = UnityObjectToWorldNormal(v.normal);
o.tDirWS = normalize(mul(unity_ObjectToWorld, float4(v.tangent.xyz, 0.0)).xyz);
o.bDirWS = normalize(cross(o.nDirWS, o.tDirWS) * v.tangent.w);
o.pos = UnityObjectToClipPos(v.vertex);
o.posWS = mul(unity_ObjectToWorld,v.vertex);
return o;
}
// Pixels shader
float4 frag(VertexOutput i) : COLOR{
// Vector preparation
float3 nDirTS = UnpackNormal(tex2D(_NormalMap, i.uv0)).rgb;
float3x3 tbn = float3x3(i.tDirWS, i.bDirWS, i.nDirWS);
float3 nDirWS = normalize(mul(nDirTS, tbn));
float3 nDirVS = mul(UNITY_MATRIX_V,float4(nDirWS,0.0));
float3 vDirWS = normalize(_WorldSpaceCameraPos.xyz - i.posWS.xyz);
// Intermediate quantity preparation
float2 mapUV = nDirVS.rg * 0.5 + 0.5;
float ndotv = dot(nDirWS,vDirWS);
// Illumination model
float3 matcap = tex2D(_Matcap, mapUV);
float fresnel = pow(1.0-ndotv, _FresnelPow);
float3 envSpcLighting = matcap * fresnel * _EnvSpeInt;
// Return value
return fixed4(envSpcLighting,1);
}
ENDCG
}
}
FallBack "Diffuse"
}Realization effect :

边栏推荐
- [note] the art of research (understand the importance of the problem)
- [cryoelectron microscope] relation4.0 - subtomogram tutorial
- CentOS deploy PostgreSQL 13
- As long as flutter is data, it will be judged null
- [freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
- Sqlmap (SQL injection automation tool)
- Do you want to meet all the needs of customers
- Cfdiv1+2-bash and a high math puzzle- (gcd+ summary of segment tree single point interval maintenance)
- After the access database introduces DataGridView data, an error is displayed
- Better performance and simpler lazy loading of intersectionobserverentry (observer)
猜你喜欢
![[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging](/img/50/594dfc9affbcca97166d475fe09ad3.png)
[cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging

《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》

The software package is set to - > Yum source

QT connects two qslite databases and reports an error qsqlquery:: exec: database not open

Joseph Ring problem

Sort out the two NFT pricing paradigms and four solutions on the market

监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
![[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching](/img/dc/255bf122d5243f2a08ca0e03b53137.png)
[paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching

IonIcons图标大全

10 common software architecture modes
随机推荐
Operator overloading
Greenplus enterprise deployment
Access数据库引入datagridview数据后,显示错误
[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
Joseph Ring problem
Detailed explanation of two modes of FTP
EF core reading text type is slow_ EF core is slow to read large string fields
Why don't you like it? It's easy to send email in cicd
Solve the problem that the disk is full due to large files
[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M
Measured waveform of boot capacitor short circuit and open circuit of buck circuit
Excellent urban design ~ good! Design # visualization radio station will be broadcast soon
How to get to the deep-water area when the industrial Internet goes?
Write some DP
MySQL 45 | 08 is the transaction isolated or not?
Cfdiv1+2-bash and a high math puzzle- (gcd+ summary of segment tree single point interval maintenance)
Multi thread shopping
【深度学习】数据准备-pytorch自定义图像分割类数据集加载
Sort out the two NFT pricing paradigms and four solutions on the market
Vmstat memory consumption query