浏览代码

[Cubemap] Added BC6H support for ReflectionProbeCache

/Add-support-for-light-specular-color-tint
Frédéric Vauchelles 7 年前
当前提交
b3297fb6
共有 11 个文件被更改,包括 34 次插入55 次删除
  1. 4
      SampleScenes/Common/Scripts/CompressBC6HAndDisplay.cs
  2. 2
      ScriptableRenderPipeline/Core/EncodeBC6H.cs
  3. 2
      ScriptableRenderPipeline/Core/ShaderLibrary/BC6H.hlsl
  4. 8
      ScriptableRenderPipeline/Core/TextureCache.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDAssetFactory.cs
  6. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  7. 18
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/ReflectionProbeCache.cs
  8. 1
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs
  10. 10
      ScriptableRenderPipeline/Core/Resources/BC6H.compute.meta
  11. 38
      ScriptableRenderPipeline/Core/Resources/BC6H.compute

4
SampleScenes/Common/Scripts/CompressBC6HAndDisplay.cs


m_EncodeBC6H = new EncodeBC6H(m_BC6HShader);
}
void OnPreRender(CommandBuffer cmb)
void EncodeBC6HTest(CommandBuffer cmb)
{
if (m_SourceTexture == null
|| m_SourceMaterial == null

void Update()
{
var cmd = new CommandBuffer { name = "EncodeBC6H Compress" };
OnPreRender(cmd);
EncodeBC6HTest(cmd);
Graphics.ExecuteCommandBuffer(cmd);
}

2
ScriptableRenderPipeline/Core/EncodeBC6H.cs


}
var startSlice = 6 * targetArrayIndex;
for (var mip = fromMip; mip <= toMip; ++mip)
for (var mip = actualFromMip; mip <= actualToMip; ++mip)
{
var rtMip = Mathf.Clamp(mip, actualFromMip, actualToMip);
for (var faceId = 0; faceId < 6; ++faceId)

2
ScriptableRenderPipeline/Core/ShaderLibrary/BC6H.hlsl


// Ref: https://github.com/knarkowicz/GPURealTimeBC6H/blob/master/bin/compress.hlsl
// Doc: https://msdn.microsoft.com/en-us/library/windows/desktop/hh308952(v=vs.85).aspx
#include "Common.hlsl"
// Measure compression error
float CalcMSLE(float3 a, float3 b)
{

8
ScriptableRenderPipeline/Core/TextureCache.cs


public void UpdateSlice(CommandBuffer cmd, int sliceIndex, Texture content, uint updateCount)
{
// transfer new slice to sliceIndex from source texture
m_SliceArray[sliceIndex].updateCount = updateCount;
SetSliceHash(sliceIndex, updateCount);
}
public void SetSliceHash(int sliceIndex, uint updateCount)
{
// transfer new slice to sliceIndex from source texture
m_SliceArray[sliceIndex].updateCount = updateCount;
}
public void UpdateSlice(CommandBuffer cmd, int sliceIndex, Texture content)

2
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDAssetFactory.cs


newAsset.GGXConvolve = Load<Shader>(HDRenderPipelinePath + "Sky/GGXConvolve.shader");
newAsset.opaqueAtmosphericScattering = Load<Shader>(HDRenderPipelinePath + "Sky/OpaqueAtmosphericScattering.shader");
newAsset.encodeBC6HCS = Load<ComputeShader>(CorePath + "Resources/EncodeBC6H.compute");
// Skybox/Cubemap is a builtin shader, must use Sahder.Find to access it. It is fine because we are in the editor
newAsset.skyboxCubemap = Shader.Find("Skybox/Cubemap");

1
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


{
m_Asset = asset;
m_GPUCopy = new GPUCopy(asset.renderPipelineResources.copyChannelCS);
EncodeBC6H.DefaultInstance = EncodeBC6H.DefaultInstance ?? new EncodeBC6H(asset.renderPipelineResources.encodeBC6HCS);
// Scan material list and assign it
m_MaterialList = HDUtils.GetRenderPipelineMaterialList();

18
ScriptableRenderPipeline/HDRenderPipeline/Lighting/ReflectionProbeCache.cs


ProbeFilteringState[] m_ProbeBakingState;
Material m_ConvertTextureMaterial;
MaterialPropertyBlock m_ConvertTextureMPB;
bool m_PerformBC6HCompression;
// BC6H requires CPP feature not yet available
probeFormat = TextureFormat.RGBAHalf;
Debug.Assert(probeFormat == TextureFormat.BC6H || probeFormat == TextureFormat.RGBAHalf, "Reflection Probe Cache format for HDRP can only be BC6H or FP16.");
m_ProbeSize = probeSize;

m_IBLFilterGGX = iblFilter;
m_PerformBC6HCompression = probeFormat == TextureFormat.BC6H;
InitializeProbeBakingStates();
}

if (result == null)
return -1;
m_TextureCache.UpdateSlice(cmd, sliceIndex, result, m_TextureCache.GetTextureUpdateCount(texture)); // Be careful to provide the update count from the input texture, not the temporary one used for convolving.
if (m_PerformBC6HCompression)
{
cmd.BC6HEncodeFastCubemap(
result, m_ProbeSize, m_TextureCache.GetTexCache(),
0, int.MaxValue, sliceIndex);
m_TextureCache.SetSliceHash(sliceIndex, m_TextureCache.GetTextureUpdateCount(texture));
}
else
{
m_TextureCache.UpdateSlice(cmd, sliceIndex, result, m_TextureCache.GetTextureUpdateCount(texture)); // Be careful to provide the update count from the input texture, not the temporary one used for convolving.
}
m_ProbeBakingState[sliceIndex] = ProbeFilteringState.Ready;
}

1
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/HDRenderPipelineResources.asset


opaqueAtmosphericScattering: {fileID: 4800000, guid: 326059e48e5735e46a98047eff4f0295,
type: 3}
skyboxCubemap: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0}
encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3}

3
ScriptableRenderPipeline/HDRenderPipeline/RenderPipelineResources/RenderPipelineResources.cs


public Shader opaqueAtmosphericScattering;
public Shader skyboxCubemap;
// Utilities
public ComputeShader encodeBC6HCS;
}
}

10
ScriptableRenderPipeline/Core/Resources/BC6H.compute.meta


fileFormatVersion: 2
guid: b69b95b3420fd904e8530b79f665a1f8
timeCreated: 1507123133
licenseType: Pro
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 4
userData:
assetBundleName:
assetBundleVariant:

38
ScriptableRenderPipeline/Core/Resources/BC6H.compute


#include "../ShaderLibrary/BC6H.hlsl"
Texture2D<float4> _Source;
RWTexture2D<uint4> _Target;
#pragma kernel KEncodeFast
[numthreads(4, 4, 1)]
void KEncodeFast(uint2 groupId : SV_GroupID, uint2 groupThreadId : SV_GroupThreadID, uint2 dispatchThreadId : SV_DispatchThreadID)
{
// Load 4x4 pixel block
float3 texels[16];
uint2 topLeftSourceID = dispatchThreadId << 2;
texels[0] = _Source.Load(uint3(topLeftSourceID , 0)).rgb;
texels[1] = _Source.Load(uint3(topLeftSourceID + uint2(1, 0), 0)).rgb;
texels[2] = _Source.Load(uint3(topLeftSourceID + uint2(2, 0), 0)).rgb;
texels[3] = _Source.Load(uint3(topLeftSourceID + uint2(3, 0), 0)).rgb;
texels[4] = _Source.Load(uint3(topLeftSourceID + uint2(0, 1), 0)).rgb;
texels[5] = _Source.Load(uint3(topLeftSourceID + uint2(1, 1), 0)).rgb;
texels[6] = _Source.Load(uint3(topLeftSourceID + uint2(2, 1), 0)).rgb;
texels[7] = _Source.Load(uint3(topLeftSourceID + uint2(3, 1), 0)).rgb;
texels[8] = _Source.Load(uint3(topLeftSourceID + uint2(0, 2), 0)).rgb;
texels[9] = _Source.Load(uint3(topLeftSourceID + uint2(1, 2), 0)).rgb;
texels[10] = _Source.Load(uint3(topLeftSourceID + uint2(2, 2), 0)).rgb;
texels[11] = _Source.Load(uint3(topLeftSourceID + uint2(3, 2), 0)).rgb;
texels[12] = _Source.Load(uint3(topLeftSourceID + uint2(0, 3), 0)).rgb;
texels[13] = _Source.Load(uint3(topLeftSourceID + uint2(1, 3), 0)).rgb;
texels[14] = _Source.Load(uint3(topLeftSourceID + uint2(2, 3), 0)).rgb;
texels[15] = _Source.Load(uint3(topLeftSourceID + uint2(3, 3), 0)).rgb;
uint4 block = uint4(0, 0, 0, 0);
float blockMSLE = 0;
EncodeMode11(block, blockMSLE, texels);
_Target[dispatchThreadId] = block;
}
正在加载...
取消
保存