我最近一直在为一个名为Urho3D的小型开源游戏引擎开发区域灯,但是在渲染管灯时遇到了一个问题,尽管长度值被改变了,但是这些灯看起来和球状灯一样。
我在Epic关于PBR的论文工作,由Brian撰写。我试着寻找其他来源,看看我是否能找到任何东西,但没有一个结果解决了我的问题。
我使用的管道照明方法如下:
float3 TubeLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, out float ndl)
{
float3 pos = (cLightPosPS.xyz - worldPos);
float3 reflectVec = reflect(-toCamera, normal);
float3 L01 = lightVec * LightLengh;
float3 L0 = pos - 0.5 * L01;
float3 L1 = pos + 0.5 * L01;
float3 ld = L1 - L0;
float distL0 = length( L0 );
float distL1 = length( L1 );
float NoL0 = dot( L0, normal ) / ( 2.0 * distL0 );
float NoL1 = dot( L1, normal ) / ( 2.0 * distL1 );
ndl = ( 2.0 * clamp( NoL0 + NoL1, 0.0, 1.0 ) )
/ ( distL0 * distL1 + dot( L0, L1 ) + 2.0 );
float RoL0 = dot( reflectVec, L0 );
float RoLd = dot( reflectVec, ld );
float L0oLd = dot( L0, ld );
float distLd = length( ld );
float t = ( RoL0 * RoLd - L0oLd )
/ ( distLd * distLd - RoLd * RoLd );
float3 closestPoint = L0 + ld * saturate( t);
float3 centreToRay = dot( closestPoint, reflectVec ) * reflectVec - closestPoint;
closestPoint = closestPoint + centreToRay * saturate(LightRad / length(centreToRay));
float3 l = normalize(closestPoint);
float3 h = normalize(toCamera + l);
ndl = saturate(dot(normal, l));
float hdn = saturate(dot(h, normal));
float hdv = dot(h, toCamera);
float ndv = saturate(dot(normal, toCamera));
float distL = length(closestPoint);
float alpha = roughness * roughness;
float alphaPrime = saturate(LightRad / (distL * 2.0) + alpha);
const float3 fresnelTerm = Fresnel(specColor, hdv) ;
const float distTerm = Distribution(hdn, alphaPrime);
const float visTerm = Visibility(ndl, ndv, roughness);
return distTerm * visTerm * fresnelTerm ;
}如果代码片段不足以帮助解决这个问题,您可以从全区域照明分局下载GitHub。构建说明可以在Urho3D网站上找到(由于声誉原因无法链接),注意目前区域照明仅在DX11中进行测试。Shader源文件可在
[build location]/bin/CoreData/Shaders/HLSL
您可以看到,这两种图像看起来都是相同的这里。
如果将pos相乘到第40行,那么它会产生更多的管效应,但仍然远远没有得到正确的结果,正如你在这里看到的。
发布于 2016-09-19 10:19:05
找到了解决方案,结果表明lightVec不是来自管的光的矢量,而是管将指向的方向。因此,我需要传递给它一个轻旋转值,以便在那里使用。
结果:

https://computergraphics.stackexchange.com/questions/4016
复制相似问题