浏览代码

Use texture Load() instead of sampling

/main
Evgenii Golubev 8 年前
当前提交
52100761
共有 2 个文件被更改,包括 16 次插入15 次删除
  1. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/BuildProbabilityTables.compute
  2. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl

30
Assets/ScriptableRenderLoop/HDRenderLoop/Sky/Resources/BuildProbabilityTables.compute


#define textureSize 128 // TODO: make this dynamic
uint cubeFaceId; // Cubemap face index
int cubeFaceId; // Cubemap face index
SAMPLER2D(sampler_EnvMap)
/* --- Output --- */

uint groupIndex : SV_GroupIndex)
{
// A single thread group processes a row of 'textureSize' texels.
const uint j = groupThreadId.y;
const float y = j / textureSize + (0.5 / textureSize);
int j = groupThreadId.y;
// TODO: reduce storage requirements.
// Suppress the D3D compiler warning.
int i;
for (uint i = 0; i < textureSize; i++)
for (i = 0; i < textureSize; i++)
float x = i / textureSize + (0.5 / textureSize);
float3 color = SAMPLE_TEXTURE2D_LOD(EnvMap, sampler_EnvMap, float2(x, y), 1).rgb;
float3 color = LOAD_TEXTURE2D_LOD(EnvMap, int2(i, j), 1).rgb;
float intensity = color.r + color.g + color.b;
rowIntegralValue += intensity / textureSize;

// Compute the CDF. Note: the value at (i = textureSize) is implicitly 1.
// TODO: run in parallel.
for (uint i = 0; i < textureSize; i++)
for (i = 0; i < textureSize; i++)
conditionalDensities[uint2(i, j)] = temp[i] / rowIntegralValue;
conditionalDensities[int2(i, j)] = temp[i] / rowIntegralValue;
}
// Store the value of the integral.

float imgIntegralValue = 0.0;
// TODO: run in parallel.
for (uint i = 0; i < textureSize; i++)
for (j = 0; j < textureSize; j++)
temp[i] = imgIntegralValue;
temp[j] = imgIntegralValue;
imgIntegralValue += rowIntegralValues[i] / textureSize;
imgIntegralValue += rowIntegralValues[j] / textureSize;
for (uint i = 0; i < textureSize; i++)
for (j = 0; j < textureSize; j++)
marginalRowDensities[uint2(i, cubeFaceId)] = temp[i] / imgIntegralValue;
marginalRowDensities[int2(cubeFaceId, j)] = temp[j] / imgIntegralValue;
}
}
}

1
Assets/ScriptableRenderLoop/ShaderLibrary/API/D3D11.hlsl


#define SAMPLER2D_FLOAT SAMPLER2D
#define LOAD_TEXTURE2D(textureName, unCoord2) textureName.Load(int3(unCoord2, 0))
#define LOAD_TEXTURE2D_LOD(textureName, unCoord2, lod) textureName.Load(int3(unCoord2, lod))
#define LOAD_TEXTURE2D_MSAA(textureName, unCoord2, sampleIndex) textureName.Load(unCoord2, sampleIndex)
#define GATHER_TEXTURE2D(textureName, samplerName, coord2) textureName.Gather(samplerName, coord2)

正在加载...
取消
保存