浏览代码

Pack normal on 1212bit in 888

/main
Sebastien Lagarde 7 年前
当前提交
3cdc6c4e
共有 3 个文件被更改,包括 33 次插入13 次删除
  1. 23
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs
  3. 21
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.hlsl

23
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/Packing.hlsl


return PackShort(cb);
}
// Pack float2 (each of 12 bit) in 888
real3 PackFloat2To888(real2 f)
{
uint2 i = (uint2)(f * 4095.0);
uint2 hi = i >> 8;
uint2 lo = i & 255;
// 8 bit in lo, 4 bit in hi
uint3 cb = uint3(lo, hi.x | (hi.y << 4));
return cb / 255.0;
}
// Unpack 2 float of 12bit packed into a 888
real2 Unpack888ToFloat2(real3 x)
{
uint3 i = (uint3)(x * 255.0);
// 8 bit in lo, 4 bit in hi
uint hi = i.z >> 4;
uint lo = i.z & 15;
uint2 cb = i.xy | uint2(lo << 8, hi << 8);
return cb / 4095.0;
}
#endif // SHADER_API_GLES
#endif // UNITY_PACKING_INCLUDED

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/Lit.cs


public override int GetMaterialGBufferCount() { return (int)GBufferMaterial.Count; }
RenderTextureFormat[] m_RTFormat4 = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB2101010, RenderTextureFormat.ARGB32, RenderTextureFormat.RGB111110Float };
RenderTextureFormat[] m_RTFormat4 = { RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.ARGB32, RenderTextureFormat.RGB111110Float };
RenderTextureReadWrite[] m_RTReadWrite4 = { RenderTextureReadWrite.sRGB, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear, RenderTextureReadWrite.Linear };
public override void GetMaterialGBufferDescription(out RenderTextureFormat[] RTFormat, out RenderTextureReadWrite[] RTReadWrite)

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


// Warning: the contents are later overwritten for Standard and SSS!
outGBuffer0 = float4(surfaceData.baseColor, surfaceData.specularOcclusion);
// RT1 - 10:10:10:2
// RT1 - 8:8:8:8
// Our tangent encoding is based on our normal.
// With octahedral quad packing we get an artifact for reconstructed tangent at the center of this quad. We use rect packing instead to avoid it.
// To have better precision encode the sign of XY separately.
uint octNormalSign = (octNormalWS.x < 0.0 ? 1 : 0) | (octNormalWS.y < 0.0 ? 2 : 0);
float3 packNormalWS = PackFloat2To888(saturate(octNormalWS * 0.5 + 0.5));
outGBuffer1 = float4(PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), abs(octNormalWS), PackInt(octNormalSign, 2));
outGBuffer1 = float4(packNormalWS, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness));
// RT2 - 8:8:8:8
uint materialFeatureId;

float3 baseColor = inGBuffer0.rgb;
bsdfData.specularOcclusion = inGBuffer0.a; // Later possibly overwritten by SSS
bsdfData.perceptualRoughness = inGBuffer1.r;
float2 octNormalWS = inGBuffer1.gb;
uint octNormalSign = UnpackInt(inGBuffer1.a, 2);
octNormalWS.x = (octNormalSign & 1) ? -octNormalWS.x : octNormalWS.x;
octNormalWS.y = (octNormalSign & 2) ? -octNormalWS.y : octNormalWS.y;
bsdfData.perceptualRoughness = inGBuffer1.a;
bsdfData.normalWS = UnpackNormalOctRectEncode(octNormalWS);
float3 packNormalWS = inGBuffer1.rgb;
float2 octNormalWS = Unpack888ToFloat2(packNormalWS);
bsdfData.normalWS = UnpackNormalOctRectEncode(octNormalWS * 2.0 - 1.0);
bakeDiffuseLighting = inGBuffer3.rgb;

正在加载...
取消
保存