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

边栏推荐
- Jump from mapper interface to mapping file XML in idea
- Blue Bridge Cup group a selection XOR
- MySQL 45 talk | 07 line lock merits and demerits: how to reduce the impact of line lock on performance?
- Convert source package to RPM package
- [paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching
- Joseph Ring problem
- [cryoEM] Introduction to FSC, Fourier shell correlation
- Amaze UI 图标查询
- Space shooting Lesson 17: game over (end)
- Pytest set (7) - parameterization
猜你喜欢

Technology sharing | quick intercom integrated dispatching system

MySQL 45 | 08 is the transaction isolated or not?
![[cryptography experiment] 0x00 install NTL Library](/img/2a/03d95082a2a63238b475b3f7f3e13d.png)
[cryptography experiment] 0x00 install NTL Library

Sqlmap (SQL injection automation tool)

LANDSCAPE

MySQL uses date_ FORMAT(date,'%Y-%m')

CDM - code division multiplexing (easy to understand)

Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
![[cryoelectron microscope] relation4.0 - subtomogram tutorial](/img/5b/5364fbe68c495b67d9db5ed9bec2ac.png)
[cryoelectron microscope] relation4.0 - subtomogram tutorial

207. Curriculum
随机推荐
207. Curriculum
What are the common error types and solutions of black box testing?
[cryoEM] Introduction to FSC, Fourier shell correlation
Shell script - global variables, local variables, environment variables
String class
LANDSCAPE
IonIcons图标大全
[deep learning] data preparation -pytorch custom image segmentation data set loading
Analyze the roadmap of 25 major DFI protocols and predict the seven major trends in the future of DFI
[memo] summary of the reasons why SSH failed? Remember to come next time.
输出1234无重复的三位数
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
Autojs微信研究:微信自动发送信息机器人最终成品(有效果演示)
UPC little C's King Canyon
Joseph Ring problem
MapReduce steps of each stage
准备esp32环境
[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
【无标题】格式保存
Dynamic thresholds buffer management in a shared buffer packet switch paper summary