浏览代码

Merge pull request #550 from Unity-Technologies/Some-update-to-refraction

Some update to refraction
/Yibing-Project-2
GitHub 7 年前
当前提交
0df286e4
共有 4 个文件被更改,包括 21 次插入17 次删除
  1. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl
  2. 14
      ScriptableRenderPipeline/Core/ShaderLibrary/Refraction.hlsl
  3. 7
      ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl
  4. 15
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl

2
ScriptableRenderPipeline/Core/ShaderLibrary/CommonLighting.hlsl


}
// ior is a value between 1.0 and 2.5
float ConvertIORToFresnel0(float ior)
float IORToFresnel0(float ior)
{
return Sqr((ior - 1.0) / (ior + 1.0));
}

14
ScriptableRenderPipeline/Core/ShaderLibrary/Refraction.hlsl


struct RefractionModelResult
{
float opticalDepth;
float distance; // length of the transmission during refraction through the shape
float3 positionWS; // out ray position
float3 rayWS; // out ray direction
};

// Second refraction (tangent sphere out)
float NoR1 = dot(normalWS, R1);
// Optical depth within the sphere
float opticalDepth = -NoR1 * thickness;
float distance = -NoR1 * thickness;
float3 P1 = positionWS + R1 * opticalDepth;
float3 P1 = positionWS + R1 * distance;
// Out normal
float3 N1 = normalize(C - P1);
// Out refracted ray

RefractionModelResult result;
result.opticalDepth = opticalDepth;
result.distance = distance;
result.positionWS = P1;
result.rayWS = R2;

float3 R = refract(-V, normalWS, 1.0 / ior);
// Optical depth within the thin plane
float opticalDepth = thickness / dot(R, -normalWS);
float distance = thickness / dot(R, -normalWS);
result.opticalDepth = opticalDepth;
result.positionWS = positionWS + R * opticalDepth;
result.distance = distance;
result.positionWS = positionWS + R * distance;
result.rayWS = -V;
return result;

7
ScriptableRenderPipeline/Core/ShaderLibrary/VolumeRendering.hlsl


HenyeyGreensteinPhasePartVarying(asymmetry, LdotD);
}
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
float TransmittanceColorAtDistanceToAbsorption(float3 transmittanceColor, float atDistance)
{
return -log(transmittanceColor + 0.00001) / max(atDistance, 0.000001);
}
#endif // UNITY_VOLUME_RENDERING_INCLUDED

15
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


bsdfData.ior = ior;
// IOR define the fresnel0 value, so update it also for consistency (and even if not physical we still need to take into account any metal mask)
bsdfData.fresnel0 = lerp(ConvertIORToFresnel0(ior).xxx, baseColor, metallic);
bsdfData.fresnel0 = lerp(IORToFresnel0(ior).xxx, baseColor, metallic);
// Absorption coefficient from Disney: http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf
bsdfData.absorptionCoefficient = -log(transmittanceColor + 0.00001) / max(atDistance, 0.000001);
bsdfData.absorptionCoefficient = TransmittanceColorAtDistanceToAbsorption (transmittanceColor, atDistance);
bsdfData.transmittanceMask = transmittanceMask;
bsdfData.thickness = max(thickness, 0.0001);
}

// Refraction
float3 transmissionRefractV; // refracted view vector after exiting the shape
float3 transmissionPositionWS; // start of the refracted ray after exiting the shape
float transmissionOpticalDepth; // length of the transmission during refraction through the shape
float3 transmissionTransmittance; // transmittance due to absorption
float transmissionSSMipLevel; // mip level of the screen space gaussian pyramid for rough refraction

};
// This is a refract - TODO: do we call original refract or this one, original maybe slightly emore expensive, to check
// This is a refract - TODO: do we call original refract or this one, original maybe slightly more expensive, to check
float3 ClearCoatTransform(float3 X, float3 N, float ieta)
{
float XdotN = saturate(dot(N, X));

RefractionModelResult refraction = REFRACTION_MODEL(V, posInput, bsdfData);
preLightData.transmissionRefractV = refraction.rayWS;
preLightData.transmissionPositionWS = refraction.positionWS;
preLightData.transmissionOpticalDepth = refraction.opticalDepth;
preLightData.transmissionTransmittance = exp(-bsdfData.absorptionCoefficient * refraction.opticalDepth);
preLightData.transmissionSSMipLevel = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness, uint(_GaussianPyramidColorMipSize.z));
preLightData.transmissionTransmittance = exp(-bsdfData.absorptionCoefficient * refraction.distance);
// Empirical remap to try to match a bit the refractio probe blurring for the fallback
preLightData.transmissionSSMipLevel = sqrt(bsdfData.perceptualRoughness) * uint(_GaussianPyramidColorMipSize.z);
preLightData.transmissionOpticalDepth = 0;
preLightData.transmissionTransmittance = float3(1.0, 1.0, 1.0);
preLightData.transmissionSSMipLevel = 0;
#endif

正在加载...
取消
保存