当前位置:网站首页>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 :
边栏推荐
- Zero technology is deeply involved in the development of privacy computing financial scenario standards of the ICT Institute
- Useful websites
- Popular cow G
- Multi thread shopping
- Android interview question | how to write a good and fast log library?
- [flask introduction series] installation and configuration of flask Sqlalchemy
- Day 014 2D array exercise
- flutter只要是数据,都会判空的
- Strongly connected component
- Sqlmap (SQL injection automation tool)
猜你喜欢
Jiamusi Market Supervision Bureau carried out special food safety network training on epidemic and insect prevention
[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M
What are the common error types and solutions of black box testing?
The software package is set to - > Yum source
Useful websites
佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
[experience] relevant configuration of remote connection to intranet server through springboard machine
What are the principles and methods of implementing functional automation testing?
Jianmu continuous integration platform v2.5.2 release
Amaze UI 图标查询
随机推荐
Sqlmap(SQL注入自动化工具)
你学习·我奖励,21天学习挑战赛 | 等你来战
Write some DP
Keyboard processing in jetpack compose
What are the common error types and solutions of black box testing?
佳木斯市场监管局开展防疫防虫害专题食品安全网络培训
State machine DP (simple version)
"Swiss Army Knife" -nc in network tools
Jianmu continuous integration platform v2.5.2 release
[dry goods memo] 50 kinds of Matplotlib scientific research paper drawing collection, including code implementation
Research on autojs wechat: the final product of wechat automatic information sending robot (effective demonstration)
Matlab simulation of LDPC minimum sum decoding based on high-order six ring free
How to get to the deep-water area when the industrial Internet goes?
Day 014 二维数组练习
Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
20 hacker artifacts
State machine DP 3D
As long as flutter is data, it will be judged null
Operator overloading
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)