浏览代码

More work

/feature-ReflectionProbeFit
Sebastien Lagarde 7 年前
当前提交
a2cc84e0
共有 2 个文件被更改,包括 22 次插入21 次删除
  1. 21
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonMaterial.hlsl
  2. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

21
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/CommonMaterial.hlsl


// Use with stack BRDF (clear coat / coat)
real roughnessToVariance(real roughness)
{
float roughnessPow = PositivePow(roughness, 1.1);
return roughnessPow / (1.0 - roughnessPow);
return 2.0 / Sq(roughness) - 2.0;
return PositivePow(variance / (1.0 + variance), 1.0 / 1.1);
return sqrt(2.0 / (variance + 2.0));
}
// ior is a value between 1.0 and 2.5

return (1.0 + sqrtF0) / (1.0 - sqrtF0);
}
// This function is a coarse approximation of computing fresnel0 for a different top than air (here clear coat of IOR 1.5) when we only have fresnel0 with air interface
// This is a coarse approximation of computing fresnel0 for a different top than air (here clear coat of IOR 1.5) when we only have fresnel0 with air interface
real Fresnel0ReajustFor15(real fresnel0)
{
//real sqrtF0 = sqrt(fresnel0);
//return Sq(1.0 - 5.0 * sqrtF0) / Sq(5.0 - sqrtF0);
// Optimization: Fit of the function (3 mad) for range 0.04 (should return 0), 1 (should return 1)
return saturate(-0.0256868 + fresnel0 * (0.326846 + (0.978946 - 0.283835 * fresnel0) * fresnel0));
}
// mean
// real sqrtF0 = sqrt(fresnel0);
// return Sq(1.0 - 5.0 * sqrtF0) / Sq(5.0 - sqrtF0);
// Optimization: Fit of the function (3 mad) for range 0.04 (should return 0), 1 (should return 1)
// return saturate(-0.0256868 + fresnel0 * (0.326846 + (0.978946 - 0.283835 * fresnel0) * fresnel0));
TEMPLATE_1_REAL(Fresnel0ReajustFor15, fresnel0, return saturate(-0.0256868 + fresnel0 * (0.326846 + (0.978946 - 0.283835 * fresnel0) * fresnel0)) )
// same as regular refract except there is not the test for total internal reflection + the vector is flipped for processing
real3 CoatRefract(real3 X, real3 N, real ieta)

22
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl


preLightData.coatPartLambdaV = GetSmithJointGGXPartLambdaV(NdotV, CLEAR_COAT_ROUGHNESS); // This will not take into account the modification by minRoughness but we are ok with this
// Scale roughness from base layer to take into account the clear coat, use the outgoing ray
float coatRoughnessScale = Sq(preLightData.coatIEta) * (NdotV / dot(N, preLightData.coatRefractV));
float NdotRefractV = dot(N, preLightData.coatRefractV);
float coatRoughnessScale = Sq(preLightData.coatIEta) * (NdotV / NdotRefractV);
// Modify roughness for base layer (so it is taken into account for precomputing of PartLambdaV).
// Note that roughnessT and roughnessB are only use with punctual light (not with IBL)

float sigmaPR = roughnessToVariance(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
preLightData.iblPerceptualRoughness = RoughnessToPerceptualRoughness(varianceToRoughness(sigmaPR * coatRoughnessScale));
V = preLightData.coatRefractV;
NdotV = saturate(dot(N, V));
preLightData.baseFresnel0.x = Fresnel0ReajustFor15(bsdfData.fresnel0.x);
preLightData.baseFresnel0.y = Fresnel0ReajustFor15(bsdfData.fresnel0.y);
preLightData.baseFresnel0.z = Fresnel0ReajustFor15(bsdfData.fresnel0.z);
preLightData.baseFresnel0 = Fresnel0ReajustFor15(bsdfData.fresnel0);
V = preLightData.coatRefractV;
NdotV = NdotRefractV;
}
else
{

float3 F = 1.0;
float3 N = bsdfData.normalWS;
specularLighting = float3(0.0, 0.0, 0.0);
diffuseLighting = float3(0.0, 0.0, 0.0);
float NdotV = preLightData.clampNdotV;

// Optimized math. Ref: PBR Diffuse Lighting for GGX + Smith Microsurfaces (slide 114).
float NdotL = saturate(dot(N, L)); // Must have the same value without the clamp
if (NdotL <= 0.0)
return;
float LdotV = dot(L, V);
float invLenLV = rsqrt(max(2 * LdotV + 2, FLT_EPS)); // invLenLV = rcp(length(L + V)) - caution about the case where V and L are opposite, it can happen, use max to avoid this
float NdotH = saturate((NdotL + NdotV) * invLenLV);

EvaluateLight_Directional(lightLoopContext, posInput, lightData, bakeLightingData, N, L, color, attenuation);
// Note: We use NdotL here to early out, but in case of clear coat this is not correct. But we are ok with this
[branch] if (attenuation * NdotL > 0.0)
[branch] if (attenuation > 0.0)
{
BSDF(V, L, posInput.positionWS, preLightData, bsdfData, lighting.diffuse, lighting.specular);

EvaluateLight_Punctual(lightLoopContext, posInput, lightData, bakeLightingData, N, L, dist, distSq, color, attenuation);
// Note: We use NdotL here to early out, but in case of clear coat this is not correct. But we are ok with this
[branch] if (attenuation * NdotL > 0.0)
[branch] if (attenuation > 0.0)
{
// Simulate a sphere light with this hack
// Note that it is not correct with our pre-computation of PartLambdaV (mean if we disable the optimization we will not have the

正在加载...
取消
保存