浏览代码

Merge pull request #12 from EvgeniiG/master

Use a new impl. of FastACos for area lights and fix the reference IBL impl.
/main
GitHub 8 年前
当前提交
4bcb7368
共有 4 个文件被更改,包括 28 次插入36 次删除
  1. 34
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl
  2. 10
      Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl
  3. 8
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl
  4. 12
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl

34
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl


// Area light specific
// UVs for sampling the LUTs
// TODO: Test with fastAcos
float theta = acos(dot(bsdfData.normalWS, V));
float theta = FastACos(dot(bsdfData.normalWS, V));
// Scale and bias for the current precomputed table - the constant use here are the one that have been use when the table in LtcData.DisneyDiffuse.cs and LtcData.GGX.cs was use
float2 uv = 0.0078125 + 0.984375 * float2(bsdfData.perceptualRoughness, theta * INV_HALF_PI);

}
#ifndef DIFFUSE_LAMBERT_BRDF
// TODO: verify that we do not need to multiply by PI.
ltcValue *= preLightData.ltcDisneyDiffuseMagnitude;
#endif

ltcValue *= lightData.specularScale;
specularLighting = fresnelTerm * lightData.color * ltcValue;
}
// TODO: current area light code doesn't take into account artist attenuation radius!
#endif
}

uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;
float3 tangentX = bsdfData.tangentWS;
float3 tangentY = bsdfData.bitangentWS;
float3 tangentX, tangentY;
GetLocalFrame(N, tangentX, tangentY);
for (uint i = 0; i < sampleCount; ++i)
{
float2 u = Hammersley2d(i, sampleCount);

float3 V, EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;
float NdotV = dot(N, V);
float3 acc = float3(0.0, 0.0, 0.0);
float3 N = bsdfData.normalWS;
float3 tangentX = bsdfData.tangentWS;
float3 tangentY = bsdfData.bitangentWS;
float NdotV = saturate(dot(N, V));
float3 acc = float3(0.0, 0.0, 0.0);
float3 tangentX, tangentY;
GetLocalFrame(N, tangentX, tangentY);
for (uint i = 0; i < sampleCount; ++i)
{

uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;
float NdotV = saturate(dot(N, V));
float3 tangentX = bsdfData.tangentWS;
float3 tangentY = bsdfData.bitangentWS;
float NdotV = saturate(dot(N, V));
float3 tangentX, tangentY;
GetLocalFrame(N, tangentX, tangentY);
for (uint i = 0; i < sampleCount; ++i)
{

*/
diffuseLighting = float3(0.0, 0.0, 0.0);
weight = float2(0.0, 0.0);
weight = float2(0.0, 1.0);
#else
// TODO: factor this code in common, so other material authoring don't require to rewrite everything,

10
Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl


float IntegrateEdge(float3 v1, float3 v2)
{
float cosTheta = dot(v1, v2);
// TODO: Explain the 0.9999 <= precision is important!
cosTheta = Clamp(cosTheta, -0.9999, 0.9999);
// TODO: Experiment with fastAcos
float theta = acos(cosTheta);
float res = cross(v1, v2).z * theta / sin(theta);
// Clamp to avoid artifacts. This particular constant gives the best results.
cosTheta = Clamp(cosTheta, -0.9999, 0.9999);
float theta = FastACos(cosTheta);
float res = cross(v1, v2).z * theta / sin(theta);
return res;
}

8
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


#define MERGE_NAME(X, Y) X##Y
// Acos in 14 cycles.
float res = -0.156583 * x + HALF_PI;
res *= sqrt(1.0 - x);
return (inX >= 0) ? res : PI - res;
float res = (0.0468878 * x + -0.203471) * x + 1.570796; // p(x)
res *= sqrt(1.0f - x);
return (inX >= 0) ? res : PI - res; // Undo range reduction
}
// Same cost as Acos + 1 FR

12
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


return v * sqrt((float3)r2 - 0.5 * v2.yzx - 0.5 * v2.zxy + vr3.yxx * v2.zzy);
}
// Computes the squared magnitude of the vector 'v' after mapping it
// to a vector within the sphere of radius 'r', where r = sqrt(r2).
// The vector is originally defined within the cube of dimensions [-r, r]^3.
// The mapping is performed as per MapCubeToSphere().
// 'dotV' is dot(v, v) (often calculated when calling such a function)
float ComputeCubeToSphereMapSqMagnitude(float3 v, float dotV, float r2)
// Computes the squared magnitude of the vector computed by MapCubeToSphere().
float ComputeCubeToSphereMapSqMagnitude(float3 v, float r2)
return r2 * dotV - v2.x * v2.y - v2.y * v2.z - v2.z * v2.x + v2.x * v2.y * v2.z * rcp(r2);
// Note: dot(v, v) is often computed before this function is called,
// so the compiler should optimize and use the precomputed result here.
return r2 * dot(v, v) - v2.x * v2.y - v2.y * v2.z - v2.z * v2.x + v2.x * v2.y * v2.z * rcp(r2);
}
#endif // UNITY_COMMON_LIGHTING_INCLUDED
正在加载...
取消
保存