当前位置:网站首页>Implementation of simple cubecap+fresnel shader in unity
Implementation of simple cubecap+fresnel shader in unity
2022-07-29 07:57:00 【TingQiaoQiao】
Shader "Unlit/cubecap"
{
//cubecap
Properties{
_NormalMap(" Normal map ", 2D) = "bump" {}
_Cubemap(" Environment mapping ", Cube) = "_Skybox" {}
_MidMapLevel(" Map blur ", Range(0, 7)) = 1.227742
_fresnelpow(" Fresnel intensity ", Range(0, 1)) = 1
_env("env", Range(0, 5)) = 1.93491
}
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 samplerCUBE _Cubemap;
uniform sampler2D _NormalMap;
uniform float _MidMapLevel;
uniform float _fresnelpow;
uniform float _env;
// 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;
};
// The vertices shader
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 vDirWS = normalize(_WorldSpaceCameraPos.xyz - i.posWS.xyz);
float3 vrDirWS = reflect(-vDirWS, nDirWS);
// Intermediate quantity preparation
float ndotv = dot(nDirWS,vDirWS);
// Illumination model
float3 cubemap = texCUBElod(_Cubemap,float4(vrDirWS, _MidMapLevel) );
float fresnel = pow(1.0 - ndotv, _fresnelpow);
float3 envSpcLighting = cubemap * fresnel * _env;
// Return value
return fixed4(envSpcLighting,1);
}
ENDCG
}
}
FallBack "Diffuse"
}Effect of implementation :

边栏推荐
- Detailed explanation of the find command (the most common operation of operation and maintenance at the end of the article)
- Day 014 二维数组练习
- Zip gzip tar compression Advanced Edition
- 20 hacker artifacts
- [cryoelectron microscope] relation4.0 - subtomogram tutorial
- The smallest positive number that a subset of an array cannot accumulate
- You study, I reward, 21 day learning challenge | waiting for you to fight
- [cryoelectron microscope] relion4.0 pipeline command summary (self use)
- [skill accumulation] presentation practical skill accumulation, common sentence patterns
- [paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching
猜你喜欢

Excellent urban design ~ good! Design # visualization radio station will be broadcast soon

The new colleague wrote a few pieces of code, broke the system, and was blasted by the boss!
![[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
![[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)](/img/fe/0efdd151f9661d5cd06a79b7266754.png)
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)

Mqtt server setup and mqtt.fx testing

Matrix decomposition and gradient descent

What is the use of chat robots? What type? After reading these, you will understand!

Jump from mapper interface to mapping file XML in idea

Multi thread shopping

【无标题】格式保存
随机推荐
QT connects two qslite databases and reports an error qsqlquery:: exec: database not open
MySQL 45 | 08 is the transaction isolated or not?
Resize2fs: bad magic number in super block
[WPF] realize language switching through dynamic / static resources
Dynamic Thresholds Buffer Management in a Shared Buffer Packet Switch论文总结
MapReduce steps of each stage
207.课程表
Useful websites
在js中,0表示false,非0表示true
[experience] relevant configuration of remote connection to intranet server through springboard machine
Record of problems caused by PIP upgrade damage
10 practical uses of NFT
Sqlmap(SQL注入自动化工具)
Solving linear programming problems based on MATLAB
Amaze UI icon query
[密码学实验] 0x00 安装NTL库
As long as flutter is data, it will be judged null
[cryoelectron microscope | paper reading] emclarity: software for high-resolution cryoelectron tomography and sub fault averaging
Popular cow G
[freeze electron microscope] analysis of the source code of the subtomogram alignment function of relion4.0 (for self use)