光在brdf的区别


Dynamic shadow map Channel?
如果⽤了lumen,那么shadowmapMask就会在lumen的Directlighting阶段进⾏⽣成。这个是⽤来检测可⻅性的

在这里插入图片描述

他在这个阶段会去做⼀个这样的区分。
后续在真正进⾏光照渲染的时候,他会⽐如⾛RenderOnePassPointLightProjection 或者RenderProjection
第⼀个这⾥OnePassPointLightProjection:
这个pass主要是绘制真正的ShadowTexTure. 它是从ShadowDepthCubeTexture这个3D纹理采样。
下⼀步会有⼀个InjectTranslucentLightArraypass。针对半透的处理
它会第⼀步AddLightForInjection:如果应该注⼊到半透体积的灯光,就加⼊lightinjectiondata。
第⼆步InjectTranslucentLightArray:将lightinjectiondata⾥⾯所有的灯光都注⼊到透明光照体积纹理。
InjectMainPS:为所有收影响的体积光贴图计算直接光照。它这⾥会⾸先根据TranslucencyLightingVolumeMin计算出想要shading
的位置,然后计算再volume体积⾥的uvw。这⾥⾯消耗的不同是:
它⾥⾯会有ComputeVolumeShadowing,这个会去区分对应的bPointLight,如果是电光,那么就会直接采样阴影。然后⽤来判断
shadowfactor,否则的话还要去做⼀次1x1的pcf。
后⾯就是绘制光源:
point和rect都是进⾏StencilingGeometry::DrawSphere(RHICmdList);
DefferedLightVertexShaders:
这⾥就是绘制矩形然后转成屏幕向量输出
对于点光和⾯光⽽⾔:他是⽤近似边界⼏何体绘制点光源⾯光的vs。如果判断边缘⾯不是0,那么⾄少这个就是个cone的形状。
它是通过计算出圆锥定点shader,然后通过Cos(Theta) = Adjacent / Hypotenuse这个公式⽤来解决椎体末端的z轴的距离
然后⼏区⽣成圆锥形的顶点。使⽤Tan(Theta) = Opposite / Adjacent 来解决这个切⽚的半径
然后提⾼有效半径,使圆的边缘位于圆锥体上,从⽽避免顶点这么做。然后椎体内部创建⼀个点,⼀次为依据创造⼀个xy平⾯的
圆,并且沿着z轴偏移。将这个转换成世界坐标以及preview相关的处理,因为这些顶点会和已经删除preview相关的着⾊器进⾏使
⽤。
或者直接为球帽⽣成顶点。最后使⽤勾股定理
pixel就是获取Gbuffer后,获取动态光,衰减,最后得出灯光颜⾊。
GetDynamicLightingSplit:
这⾥区分了rectlight,主要是做矩形光照或者胶囊体光照。后⾯涉及到各种积分。
RectLight和PointLight区别:
1:DifferLightPixelShaders:计算辐亮度radiance的时候也就是在计算光衰之前,会去获取全局动态光照,这个过程会进⼊到
defferdlightingCommon⾥的GetDynamicLightingSplit:⾥⾯会有
在这里插入图片描述

矩形光:
在这里插入图片描述

这⾥⾯创建FAreaLightIntegrateContext⽤的函数是
1 FAreaLightIntegrateContext CreateRectIntegrateContext( float Roughness, half3 N, half3 V, FRect Rect, FRec
2 {
3 float NoL = 0;
4 float Falloff = 0;
5
6 FAreaLightIntegrateContext Out = InitAreaLightIntegrateContext();
7 #if 0 // Reference quality
8 float3 L = RectIrradianceRef( N, Rect, Falloff, NoL );
9 #elif !CHEAP_RECT // Optimized Lambert
10 float3 L = RectIrradianceLambert( N, Rect, Falloff, NoL );
11 #elif 1 // Karis
12 float3 L = RectIrradianceApproxKaris( N, Rect, Falloff, NoL );
13 #elif 1 // Lagarde
14 float3 L = RectIrradianceApproxLagarde( N, Rect, Falloff, NoL );
15 #else // Drobot
16 float3 L = RectIrradianceApproxDrobot( N, Rect, Falloff, NoL );
17 #endif
18 float3 FalloffColor = SampleSourceTexture( L, Rect, SourceTexture );
19 #if CHEAP_RECT
20 float3 R = reflect( -V, N );
21 #if 0
22 float NoV = saturate( dot( N, V ) );
23 L = lerp( L, R, saturate( -2dot( Rect.Axis[2], R ) ) );
24 L = normalize( L );
25 UNROLL
26 for( int k = 0; k < 2; k++ )
27 {
28 #if 1
29 float NoL = dot( N, L );
30 float NoV = dot( N, V );
31 float VoL = dot( V, L );
32 float NoHInvLenH = ( NoL + NoV ) / ( 2 + 2
VoL );
33 float3 Gradient = ( ( N - LNoL ) - ( V - LVoL ) * NoHInvLenH ) * (2NoHInvLenH);
34 #else
35 float RoL = dot( R, L );
36 float3 Gradient = 2 * RoL * ( R - L * RoL );
37 #endif
38 Gradient -= Rect.Axis[2] * dot( Rect.Axis[2], Gradient );
39 Gradient = lerp( Gradient, 0, (1 - NoV) * saturate( 2
dot( Rect.Axis[2], L ) ) );
40 L = ClampToRect( L + Gradient * ( 2.0 / ( 2.0 + k ) ), Rect );
41 }
42 #elif 1
43 float3 Ls = L;
44 float3 v[4];
45 v[0] = Rect.Origin - Rect.Axis[0] * Rect.Extent.x - Rect.Axis[1] * Rect.Extent.y;
46 v[1] = Rect.Origin + Rect.Axis[0] * Rect.Extent.x - Rect.Axis[1] * Rect.Extent.y;
47 v[2] = Rect.Origin + Rect.Axis[0] * Rect.Extent.x + Rect.Axis[1] * Rect.Extent.y;
48 v[3] = Rect.Origin - Rect.Axis[0] * Rect.Extent.x + Rect.Axis[1] * Rect.Extent.y;
49 float3 e0 = v[0];
50 float3 e1 = v[1];
51 float3 MinEdgeN = 0;
52 float MinEdgeCos = 1;
53 UNROLL
54 for( uint i = 0; i < 4; i++ )
55 {
56 float3 v0 = v[i];
57 float3 v1 = v[ (i+1) % 4 ];
58 float3 EdgeN = normalize( cross( v0, v1 ) );
59 float EdgeCos = dot( R, EdgeN );
60 if( EdgeCos < MinEdgeCos )
61 {
62 MinEdgeN = EdgeN;
63 MinEdgeCos = EdgeCos;
64 e0 = v0;
65 e1 = v1;
66 }
67 }
68 if( MinEdgeCos > 0 )
69 {
70 Ls = R;
71 }
72 else
73 {
74 #if 0
75 Ls = SmallestAnglePointOnLineToRay( e0, e1, length( e0 - e1 ), R );
76 #else
77 float3 Rp = R - MinEdgeCos * MinEdgeN;
78 if( dot( cross( Rp, e0 ), R ) < 0 ) Ls = e0;
79 else if(dot( cross( e1, Rp ), R ) < 0 ) Ls = e1;
80 else Ls = Rp;
81 #endif
82 Ls = normalize( Ls );
83 }
84 float a = Pow2( GBuffer.Roughness );
85 //L = lerp( Ls, L, a );
86 L = normalize( Ls );
87 #else
88 L = R;
89 if( !RayHitRect( R, Rect ) )
90 {
91 float3 MaxL = R;
92 float MaxNoH = -1;
93 uint NumSteps = 128;
94 for( uint i = 0; i < NumSteps; i++ )
95 {
96 float Theta = (2PI) * i / (float)NumSteps;
97 float2 p;
98 p.x = cos( Theta );
99 p.y = sin( Theta );
100 p.xy /= dot( 1, abs§ );
101 float2 PointInRect = float2( p.x + p.y, p.x - p.y ) * Rect.Extent;
102 //0.5 * sqrt( 2 + (2
sqrt(2.0)) *
103 float3 ToRect = Rect.Origin;
104 ToRect += PointInRect.x * Rect.Axis[0];
105 ToRect += PointInRect.y * Rect.Axis[1];
106 L = normalize( ToRect );
107
108 float RoL = dot( R, L );
109 BxDFContext Context;
110 Context.Init( N, V, L );
111 if( Context.NoH > MaxNoH )
112 {
113 MaxNoH = Context.NoH;
114 MaxL = L;
115 }
116 }
117 L = MaxL;
118 }
119 for( int k = 0; k < 0; k++ )
120 {
121 float NoL = dot( N, L );
122 float NoV = dot( N, V );
123 float VoL = dot( V, L );
124 float NoHInvLenH = ( NoL + NoV ) / ( 2 + 2VoL );
125 float3 Gradient = ( ( N - L
NoL ) - ( V - LVoL ) * NoHInvLenH ) * (2NoHInvLenH);
126 L = ClampToRect( L + Gradient * ( 2.0 / ( 2.0 + k ) ), Rect );
127 }
128 #endif
129
130 Out.AreaLight.SphereSinAlpha = sqrt( Falloff * (1.0 / PI) );
131 Out.AreaLight.SphereSinAlphaSoft = 0;
132 Out.AreaLight.LineCosSubtended = 1;
133 Out.AreaLight.FalloffColor = 1;
134 Out.AreaLight.Rect = Rect;
135 Out.AreaLight.Texture = SourceTexture;
136 Out.AreaLight.IsRectAndDiffuseMicroReflWeight = 0;
137 SetIsRectLight(Out.AreaLight, false);
138 SetAreaLightDiffuseMicroReflWeight(Out.AreaLight, 0.0);
139 Out.L = L;
140 Out.NoL = NoL;
141 Out.Falloff = Falloff;
142 #else
143 Out.AreaLight.SphereSinAlpha = 0;
144 Out.AreaLight.SphereSinAlphaSoft = 0;
145 Out.AreaLight.LineCosSubtended = 1;
146 Out.AreaLight.FalloffColor = FalloffColor;
147 Out.AreaLight.Rect = Rect;
148 Out.AreaLight.Texture = SourceTexture;
149 Out.AreaLight.IsRectAndDiffuseMicroReflWeight = 0;
150 SetIsRectLight(Out.AreaLight, true);
151 SetAreaLightDiffuseMicroReflWeight(Out.AreaLight, 0.0);
152 Out.L = L;
153 Out.NoL = NoL;
154 Out.Falloff = Falloff;
155 #endif
156 return Out;
157 }
点光胶囊体:
在这里插入图片描述

这⾥创建对应context的是:
1 CreateCapsuleIntegrateContext
1 FAreaLightIntegrateContext CreateCapsuleIntegrateContext(float Roughness, half3 N, half3 V, FCapsuleLight
2 {
3 FAreaLightIntegrateContext Out = InitAreaLightIntegrateContext();
4 float NoL;
5 float Falloff;
6 float LineCosSubtended = 1;
7 // Clip to horizon
8 //float NoP0 = dot( N, Capsule.LightPos[0] );
9 //float NoP1 = dot( N, Capsule.LightPos[1] );
10 //if( NoP0 < 0 ) Capsule.LightPos[0] = ( Capsule.LightPos[0] * NoP1 - Capsule.LightPos[1] * NoP0 ) / (
11 //if( NoP1 < 0 ) Capsule.LightPos[1] = ( -Capsule.LightPos[0] * NoP1 + Capsule.LightPos[1] * NoP0 ) / (
12 BRANCH
13 if( Capsule.Length > 0 )
14 {
15 LineIrradiance( N, Capsule.LightPos[0], Capsule.LightPos[1], Capsule.DistBiasSqr, LineCosSubtended,
16 }
17 else
18 {
19 float DistSqr = dot( Capsule.LightPos[0], Capsule.LightPos[0] );
20 Falloff = rcp( DistSqr + Capsule.DistBiasSqr );
21 float3 L = Capsule.LightPos[0] * rsqrt( DistSqr );
22 NoL = dot( N, L );
23 }
24 if( Capsule.Radius > 0 )
25 {
26 // TODO Use capsule area?
27 float SinAlphaSqr = saturate( Pow2( Capsule.Radius ) * Falloff );
28 NoL = SphereHorizonCosWrap( NoL, SinAlphaSqr );
29 }
30 NoL = saturate( NoL );
31 Falloff = bInverseSquared ? Falloff : 1;
32 float3 ToLight = Capsule.LightPos[0];
33 if( Capsule.Length > 0 )
34 {
35 float3 R = reflect( -V, N );
36 #if 0
37 // Fix hard edge when ray is nearly parallel to line
38 float3 PointOnLine = ClosestPointLineToPoint( Capsule.LightPos[0], Capsule.LightPos[1], Capsule.L
39 float3 DirToLine = normalize( PointOnLine );
40 R = lerp( DirToLine, R, saturate( dot( DirToLine, R ) ) );
41 R = normalize( R );
42 #endif
43 ToLight = ClosestPointLineToRay( Capsule.LightPos[0], Capsule.LightPos[1], Capsule.Length, R );
44 }
45 float DistSqr = dot( ToLight, ToLight );
46 float InvDist = rsqrt( DistSqr );
47 float3 L = ToLight * InvDist;
48
49 Roughness = max( Roughness, View.MinRoughness );
50 float a = Pow2( Roughness );
51
52 // Diffuse micro refelction contribution will softly fade out when th light become an area light.
53 // We only based this assumption based on the light size.
54 const float SizeFadesOutDiffuseMicroRefl = 20.0;
55 Out.AreaLight.SphereSinAlpha = saturate( Capsule.Radius * InvDist * (1 - a) );
56 Out.AreaLight.SphereSinAlphaSoft = saturate( Capsule.SoftRadius * InvDist );
57 Out.AreaLight.LineCosSubtended = LineCosSubtended;
58 Out.AreaLight.FalloffColor = 1;
59 Out.AreaLight.Rect = (FRect)0;
60 Out.AreaLight.Texture = InitRectTexture(DummyRectLightTextureForCapsuleCompilerWarning);
61 Out.AreaLight.IsRectAndDiffuseMicroReflWeight = 0;
62 SetIsRectLight(Out.AreaLight, false);
63 SetAreaLightDiffuseMicroReflWeight(Out.AreaLight, saturate(1.0f - max(Capsule.Length, Capsule.Radius) /
64 Out.NoL = NoL;
65 Out.Falloff = Falloff;
66 Out.L = L;
67 return Out;
68 }
其他⼀些区别都是基于体积雾,体积云,⽬前没找到更有意义的操作。
得看下brdf:
1 //N是表⾯法向量,V是视线⽅向,L是⼊射光⽅向,
2 struct BxDFContext
3 {
4 float NoV;
5 float NoL;
6 float VoL;
7 float NoH;
8 float VoH;
9 float XoV;
10 float XoL;
11 float XoH;
12 float YoV;
13 float YoL;
14 float YoH;
15 #if 1 // Shit code until we get member functions
16 };

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值