标签:图形学 游戏开发 shader unity3d physically based
在实时渲染中Physically-Based Rendering(PBR)中文为基于物理的渲染
#define PIE 3.1415926535 float4 frag(v2f i) :COLOR { float3 viewDir = normalize(i.viewDir); float3 lightDir = normalize(i.lightDir); float3 H = normalize(lightDir + viewDir); float3 N = normalize(i.normal); float d = (_SP + 2) / 8 * pow(dot(N, H), _SP) / 4 * PIE; float f = _SC + (1 - _SC)*pow((1 - dot(H, lightDir)), 5); float k = 2 / sqrt(PIE * (_SP + 2)); float v = 1 / ((dot(N, lightDir)*(1 - k) + k)*(dot(N, viewDir)*(1 - k) + k)); float all = d*f*v; float3 c = tex2D(_MainTex, i.uv_MainTex); float3 diff = dot(lightDir, N); diff = (1 - all)*diff; return float4(c *(diff+all), 1) * _LightColor0; }
float d = (_SP + 2) / 8 * pow(dot(N, H), _SP)/(2*PIE);
secθ为1/cosθ;
曲线如下这是Beckmann和phong的对比(粉色为Beckmann,蓝色为phong)
float cosT = dot(N, H); float secT = 1 / cosT; float d = pow(E, -((1 - pow(cosT, 2))*pow(secT, 4) / _AB))*pow(secT, 4) / (PIE*pow(_AB, 2));
为实现方程
曲线如下:这是与phong的比较
效果如下:
核心代码如下:
float cosT = dot(N, H); float d = pow(_SP, 2) / (PIE *pow((1 + (-1 + pow(_SP, 2))*pow(cosT, 2)), 2));
#define E 2.71828 float4 frag(v2f i) :COLOR { float3 viewDir = normalize(i.viewDir); float3 lightDir = normalize(i.lightDir); float3 H = normalize(lightDir + viewDir); float3 N = normalize(i.normal); float cosT = dot(H, N); float secT = 1 / cosT; float d = (pow(E, -(_SP*_SP + (1 - cosT * cosT)*secT *secT) / _SP))* pow(_SP, -1 + _TP)*pow(secT, 4) *pow(_SP*_SP + (1 - cosT *cosT)*secT *secT, -_TP) / (PIE * _GM); float f = _SC + (1 - _SC)*pow((1 - dot(H, lightDir)), 5); float k = 2 / sqrt(PIE * (_SP + 2)); float v = 1 / ((dot(N, lightDir)*(1 - k) + k)*(dot(N, viewDir)*(1 - k) + k)); float all = d*f*v; float3 c = tex2D(_MainTex, i.uv_MainTex); float3 diff = dot(lightDir, N); diff = (1 - all)*diff; return float4(c *(diff + all), 1) * _LightColor0; }
参考:
1. Mathematica Notebook for the SIGGRAPH 2013 talk “ Background: Physics and Math of Shading”
2. PhysicallyBased Lighting in Call of Duty: Black Ops
----- by wolf96 http://blog.csdn.net/wolf96
Unity3d 基于物理渲染Physically-Based Rendering之specular BRDF
标签:图形学 游戏开发 shader unity3d physically based
原文地址:http://blog.csdn.net/wolf96/article/details/44172243