浏览代码

HDRenderPipeline: Fix issue with specular color and packing precision

/RenderPassXR_Sandbox
Sebastien Lagarde 7 年前
当前提交
cd023e6c
共有 3 个文件被更改,包括 10 次插入7 次删除
  1. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  2. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  3. 8
      Assets/ScriptableRenderPipeline/ShaderLibrary/Packing.hlsl

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


[GenerateHLSL]
public enum SpecularValue
{
// Value are defined in the tab name convertSpecularToValue in lit.hlsl
Water = 0, // 0.02 Water or ice
Regular = 1, // 0.04 regular dieletric
Gemstone = 2, // 0.20

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#endif
}
static const float3 arraySpecularValue = float3(SPECULARVALUE_WATER, SPECULARVALUE_REGULAR, SPECULARVALUE_GEMSTONE);
static const float3 convertSpecularToValue = float3(0.02, 0.04, 0.20);
float val = arraySpecularValue[specular];
float val = convertSpecularToValue[specular];
bsdfData.fresnel0 = lerp(val.xxx, baseColor, metallic);
}

{
outGBuffer1.a = PackMaterialId(MATERIALID_LIT_STANDARD); // We save 1bit in gbuffer1 to store it in gbuffer2 instead
// Encode specular on two bit for the enum, must match encoding of MATERIALID_LIT_STANDARD
// TODO: encoding here could be optimize as we know what is the value of surfaceData.specular
// TODO: encoding here could be optimize as we know what is the value of surfaceData.specular => (0.75294)
outGBuffer2 = float4(surfaceData.specularColor, PackFloatInt8bit(0.0, surfaceData.specular, 4.0));
}
else if (surfaceData.materialId == MATERIALID_LIT_ANISO)

|| anisotropy > 0)
{
bsdfData.materialId = MATERIALID_LIT_ANISO;
FillMaterialIdStandardData(baseColor, specular, metallic, bsdfData);
float3 tangentWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
FillMaterialIdAnisoData(bsdfData.roughness, bsdfData.normalWS, tangentWS, anisotropy, bsdfData);
}

}
}
else // if (supportsSSS && bsdfData.materialId == MATERIALID_LIT_SSS)
{

8
Assets/ScriptableRenderPipeline/ShaderLibrary/Packing.hlsl


float t2 = (precision / maxi) / precisionMinusOne;
// extract integer part
i = int(val / t2);
i = int((val / t2) + rcp(precisionMinusOne)); // + rcp(precisionMinusOne) to deal with precision issue (can't use round() as val contain the floating number
f = (-t2 * float(i) + val) / t1;
f = saturate((-t2 * float(i) + val) / t1); // Saturate in case of precision issue
return PackFloatInt(f, i, maxi, 255.0);
return PackFloatInt(f, i, maxi, 256.0);
UnpackFloatInt(val, maxi, 255.0, f, i);
UnpackFloatInt(val, maxi, 256.0, f, i);
}
float PackFloatInt10bit(float f, int i, float maxi)

正在加载...
取消
保存