当前位置:网站首页>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 :

边栏推荐
猜你喜欢

Joseph Ring problem

cs61abc分享会(六)程序的输入输出详解 - 标准输入输出,文件,设备,EOF,命令行参数

Sqlmap (SQL injection automation tool)

Amaze UI 图标查询

Jianmu continuous integration platform v2.5.2 release

Dynamic thresholds buffer management in a shared buffer packet switch paper summary
![[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M](/img/5e/69987afcd1e50ba37bc49441dd3a50.png)
[cryoelectron microscope | paper reading] interpretation of sub fault average m software: multi particle cryo EM refining with M

CentOS deploy PostgreSQL 13
![[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging](/img/1e/9f05862288261e16a6b04508b9b292.png)
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging

How to draw an excellent architecture diagram
随机推荐
What are the common error types and solutions of black box testing?
Greenplus enterprise deployment
Mqtt server setup and mqtt.fx testing
Pytorch's skill record
监听页面滚动位置定位底部按钮(包含页面初始化定位不对鼠标滑动生效的解决方案)
207.课程表
330. Complete the array as required
MySQL 45 | 08 is the transaction isolated or not?
[skill accumulation] common expressions when writing emails
Embroidery of little D
在一个sql文件中,上面定义一个测试表及数据,下面可以select* from 测试表
Vmstat memory consumption query
你学习·我奖励,21天学习挑战赛 | 等你来战
Prepare esp32 environment
Zero technology is deeply involved in the development of privacy computing financial scenario standards of the ICT Institute
JVM garbage collection mechanism (GC)
[note] the art of research - (tell a good story and argument)
After the access database introduces DataGridView data, an error is displayed
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)
Effective learning of medical image segmentation annotation based on noise pseudo tags and adversarial learning