|
|
|
|
|
|
{ |
|
|
|
public class BC6H |
|
|
|
{ |
|
|
|
public static BC6H DefaultInstance; |
|
|
|
|
|
|
|
static readonly int _Source = Shader.PropertyToID("_Source"); |
|
|
|
static readonly int _Target = Shader.PropertyToID("_Target"); |
|
|
|
|
|
|
|
|
|
|
m_KernelEncodeFastGroupSize = new[] { (int)x, (int)y, (int)z }; |
|
|
|
} |
|
|
|
|
|
|
|
public RenderTexture InstantiateTarget(int sourceWidth, int sourceHeight) |
|
|
|
{ |
|
|
|
int targetWidth, targetHeight; |
|
|
|
CalculateOutputSize(sourceWidth, sourceHeight, out targetWidth, out targetHeight); |
|
|
|
|
|
|
|
var t = new RenderTexture(targetWidth, targetHeight, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); |
|
|
|
t.Release(); |
|
|
|
t.enableRandomWrite = true; |
|
|
|
t.Create(); |
|
|
|
return t; |
|
|
|
} |
|
|
|
|
|
|
|
// Only use mode11 of BC6H encoding
|
|
|
|
public void EncodeFast(CommandBuffer cmb, RenderTargetIdentifier source, int sourceWidth, int sourceHeight, RenderTargetIdentifier target) |
|
|
|
{ |
|
|
|
|
|
|
cmb.SetComputeTextureParam(m_Shader, m_KernelEncodeFast, _Source, source); |
|
|
|
cmb.SetComputeTextureParam(m_Shader, m_KernelEncodeFast, _Target, target); |
|
|
|
cmb.DispatchCompute(m_Shader, m_KernelEncodeFast, targetWidth / m_KernelEncodeFastGroupSize[0], targetHeight / m_KernelEncodeFastGroupSize[1], 1); |
|
|
|
cmb.DispatchCompute(m_Shader, m_KernelEncodeFast, targetWidth, targetHeight, 1); |
|
|
|
} |
|
|
|
|
|
|
|
static void CalculateOutputSize(int swidth, int sheight, out int twidth, out int theight) |
|
|
|
|
|
|
theight = sheight >> 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static class BC6HExtensions |
|
|
|
{ |
|
|
|
public static void BC6HEncodeFast(this CommandBuffer cmb, RenderTargetIdentifier source, int sourceWidth, int sourceHeight, RenderTargetIdentifier target) |
|
|
|
{ |
|
|
|
BC6H.DefaultInstance.EncodeFast(cmb, source, sourceWidth, sourceHeight, target); |
|
|
|
} |
|
|
|
} |
|
|
|
} |