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

边栏推荐
- The new colleague wrote a few pieces of code, broke the system, and was blasted by the boss!
- [WPF] realize language switching through dynamic / static resources
- UPC little C's King Canyon
- 黑盒测试常见错误类型说明及解决方法有哪些?
- Popular cow G
- MapReduce steps of each stage
- Actual measurement of boot and pH pins of buck circuit
- Data warehouse modeling, what is wide table? How to design? Advantages and disadvantages
- 207. Curriculum
- Very practical shell and shellcheck
猜你喜欢

@Use of jsonserialize annotation
What are the principles and methods of implementing functional automation testing?

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

MySQL 45 | 08 is the transaction isolated or not?

An Optimal Buffer Management Scheme with Dynamic Thresholds论文总结

Why don't you like it? It's easy to send email in cicd

Actual measurement of boot and pH pins of buck circuit

Solve the problem that CSDN cannot publish blog due to unknown copyright

【深度学习】数据准备-pytorch自定义图像分割类数据集加载

Dynamic thresholds buffer management in a shared buffer packet switch paper summary
随机推荐
Dynamic Thresholds Buffer Management in a Shared Buffer Packet Switch论文总结
Jianmu continuous integration platform v2.5.2 release
Data warehouse modeling, what is wide table? How to design? Advantages and disadvantages
Blue Bridge Cup group a selection XOR
Database persistence +jdbc database connection
Greenplus enterprise deployment
Ansible (automation software)
Effective learning of medical image segmentation annotation based on noise pseudo tags and adversarial learning
20 hacker artifacts
After the access database introduces DataGridView data, an error is displayed
Popular cow G
Convert source package to RPM package
准备esp32环境
Limitations of push down analysis
Amaze UI icon query
Mqtt server setup and mqtt.fx testing
Multi thread shopping
My entrepreneurial neighbors
【深度学习】数据准备-pytorch自定义图像分割类数据集加载
What is the use of chat robots? What type? After reading these, you will understand!