Julien Ignace 8 年前
当前提交
3e457cb8
共有 4 个文件被更改,包括 27 次插入20 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl
  2. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSurfaceData.hlsl
  3. 36
      Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl
  4. 5
      Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl

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


P2 = mul(P2, transpose(basis));
// Compute the binormal.
float3 B = normalize(cross(P2 - P1, P1));
float3 B = normalize(cross(P1, P2));
float ltcValue;

4
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitSurfaceData.hlsl


#endif
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
float3 vertexNormalWS = normalize(input.tangentToWorld[2].xyz);
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE

surfaceData.tangentWS = SAMPLE_LAYER_TEXTURE2D(ADD_IDX(_TangentMap), ADD_ZERO_IDX(sampler_TangentMap), ADD_IDX(layerTexCoord.base)).rgb;
#endif
#else
surfaceData.tangentWS = input.tangentToWorld[0].xyz;
surfaceData.tangentWS = normalize(input.tangentToWorld[0].xyz);
#endif
// TODO: Is there anything todo regarding flip normal but for the tangent ?

36
Assets/ScriptableRenderLoop/ShaderLibrary/AreaLighting.hlsl


// 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);
float res = cross(v1, v2).z * theta * rsqrt(1.0f - cosTheta * cosTheta); // optimization from * 1 / sin(theta)
return res;
}

float LineFpo(float tLDDL, float lrcpD, float rcpD)
{
// Compute: ((l / d) / (d * d + l * l)) + (1.0 / (d * d)) * atan(l / d).
return tLDDL + Square(rcpD) * atan(lrcpD);
return tLDDL + (rcpD * rcpD) * FastATan(lrcpD);
}
float LineFwt(float tLDDL, float l)

float d = length(normal);
float l1rcpD = l1 * rcp(d);
float l2rcpD = l2 * rcp(d);
float tLDDL1 = l1rcpD * rcp(Square(d) + Square(l1));
float tLDDL2 = l2rcpD * rcp(Square(d) + Square(l2));
float tLDDL1 = l1rcpD / (d * d + l1 * l1);
float tLDDL2 = l2rcpD / (d * d + l2 * l2);
return intP0 * normal.z + intWt * tangent.z;
// Guard against numerical precision issues.
return max(intP0 * normal.z + intWt * tangent.z, 0.0);
}
// Computes 1.0 / length(mul(ortho, transpose(inverse(invM)))).
float ComputeLineWidthFactor(float3x3 invM, float3 ortho)
{
// transpose(inverse(M)) = (1.0 / determinant(M)) * cofactor(M).
// Take into account that m12 = m21 = m23 = m32 = 0 and m33 = 1.
float det = invM._11 * invM._22 - invM._22 * invM._31 * invM._13;
float3x3 cof = {invM._22, 0.0, -invM._22 * invM._31,
0.0, invM._11 - invM._13 * invM._31, 0.0,
-invM._13 * invM._22, 0.0, invM._11 * invM._22};
// 1.0 / length(mul(V, (1.0 / s * M))) = abs(s) / length(mul(V, M)).
return abs(det) / length(mul(ortho, cof));
// Inverse-transform the endpoints and the binormal.
// Inverse-transform the endpoints.
B = mul(B, invM);
float width = ComputeLineWidthFactor(invM, B);
if (P2.z <= 0.0)
{

// Integrate the clamped cosine over the line segment.
float irradiance = LineIrradiance(l1, l2, P0, T);
// Compute the width factor. We take the absolute value because the points may be swapped.
float width = abs(dot(B, normalize(cross(T, P1))));
// Guard against numerical precision issues.
return max(INV_PI * width * irradiance, 0.0);
return INV_PI * width * irradiance;
}
#endif // UNITY_AREA_LIGHTING_INCLUDED

5
Assets/ScriptableRenderLoop/ShaderLibrary/Common.hlsl


}
#endif // INTRINSIC_MINMAX3
float Square(float x)
{
return x * x;
}
void Swap(inout float a, inout float b)
{
float t = a; a = b; b = t;

正在加载...
取消
保存