Skip to content

Commit 52db141

Browse files
committed
Get rid of the separate occupancy texture, use irradiance alpha channel.
1 parent adc0d1b commit 52db141

File tree

5 files changed

+3
-63
lines changed

5 files changed

+3
-63
lines changed

src/apps/ch11_voxel/ch11_voxel/FrameGraph.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ void FrameGraph::renderFinalScene(const scenic::SceneTree & aSceneTree,
215215

216216
glBindTextureUnit(6, mShadowMap);
217217
graphics::setUniform(program, "u_ShadowMap", 6);
218-
glBindTextureUnit(10, aVoxelizer.mOccupancy);
219-
graphics::setUniform(program, "u_VoxelsAlbedoTexture", 10);
220218
glBindTextureUnit(11, aVoxelizer.mIrradiance);
221219
graphics::setUniform(program, "u_VoxelsIrradianceTexture", 11);
222220

@@ -239,8 +237,6 @@ void FrameGraph::renderConeTrace(const scenic::SceneTree & aSceneTree,
239237
Voxelizer & aVoxelizer, GLuint aMode)
240238
{
241239
const auto & program = mPrograms.mConeTrace;
242-
glBindTextureUnit(10, aVoxelizer.mOccupancy);
243-
graphics::setUniform(program, "u_VoxelsAlbedoTexture", 10);
244240
glBindTextureUnit(11, aVoxelizer.mIrradiance);
245241
graphics::setUniform(program, "u_VoxelsIrradianceTexture", 11);
246242
graphics::setUniform(program, "u_VoxelSize", aVoxelizer.mVoxelSize);

src/apps/ch11_voxel/ch11_voxel/Voxelization.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -347,60 +347,6 @@ void Voxelizer::voxelizeView(const scenic::SceneTree & aScene, GLuint aGridDimen
347347

348348
void Voxelizer::prepareMipmap(GLuint aGridDimension, const FrameGraph & aGraph)
349349
{
350-
mOccupancy = {GL_TEXTURE_3D};
351-
// For creation
352-
graphics::bind(mOccupancy);
353-
354-
if (mControl.mLinearFiltering)
355-
{
356-
glTextureParameteri(mOccupancy, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
357-
glTextureParameteri(mOccupancy, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
358-
}
359-
360-
GLsizei levels = GLsizei(std::log2(aGridDimension)) + 1;
361-
glTextureStorage3D(mOccupancy, levels, GL_RGBA8, aGridDimension, aGridDimension, aGridDimension);
362-
363-
std::uint8_t * buffer =
364-
(std::uint8_t *)glMapNamedBufferRange(mVoxelStore,
365-
offsetof(VoxelsSsbo_glsl, mVoxels),
366-
mVoxelsByteSize,
367-
GL_MAP_READ_BIT);
368-
std::vector<math::sdr::Rgba> textureData;
369-
textureData.reserve(mVoxelsByteSize);
370-
// Need to reorder: the buffer is stored Z-first
371-
//for (std::size_t idx = 0; idx != mVoxelsByteSize; ++idx)
372-
//{
373-
// textureData.push_back({0, 0, 0,
374-
// (std::uint8_t)((buffer[idx] == 1) ? 255 : 0)});
375-
//}
376-
377-
unsigned int zStride = 1;
378-
unsigned int xStride = aGridDimension * zStride;
379-
unsigned int yStride = aGridDimension * xStride;
380-
381-
// The buffer is stored Z-first, whereas the 3D textures are Z-last
382-
// We could either sample Z-first in the shader, or fix it here
383-
for (unsigned int z = 0; z != aGridDimension; ++z)
384-
{
385-
for (unsigned int y = 0; y != aGridDimension; ++y)
386-
{
387-
for (unsigned int x = 0; x != aGridDimension; ++x)
388-
{
389-
std::size_t idx = z * zStride + y * yStride + x * xStride;
390-
textureData.push_back({0, 0, 0,
391-
(std::uint8_t)((buffer[idx] == 1) ? 255 : 0)});
392-
}
393-
}
394-
}
395-
396-
glUnmapNamedBuffer(mVoxelStore);
397-
398-
glTextureSubImage3D(mOccupancy, 0,
399-
0, 0, 0, aGridDimension, aGridDimension, aGridDimension,
400-
GL_RGBA, GL_UNSIGNED_BYTE, textureData.data());
401-
402-
glGenerateTextureMipmap(mOccupancy);
403-
404350
if (mControl.mComputeIrradianceMipmapping)
405351
{
406352
mipmapIrradiance(aGridDimension, aGraph);

src/apps/ch11_voxel/ch11_voxel/Voxelization.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct Voxelizer
8080
GLsizeiptr mVoxelsByteSize;
8181
math::Box<float> mSceneAabb; // Note: we could only keep min corner
8282
float mVoxelSize{0.f}; // World units
83-
graphics::Texture mOccupancy{GL_TEXTURE_3D};
8483
graphics::Texture mAlbedo{GL_TEXTURE_3D};
8584
graphics::Texture mNormals{GL_TEXTURE_3D};
8685
graphics::Texture mIrradiance{GL_TEXTURE_3D};

src/apps/ch11_voxel/ch11_voxel/resources/shaders/ch11_InjectIrradiance.comp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void main()
159159
// Apply the voxel albedo to accumulated irradiance from all light sources
160160
irradiance *= albedo.rgb;
161161

162-
// TODO: store correct occupancy (1 might be correct)
162+
// Note: At the level 0 (i.e. this level of the irradiance 3D texture)
163+
// the occupancy (in alpha) is set to 1: the voxel is considered entirely occupied.
163164
imageStore(u_IrradianceImage, voxelCoord, vec4(irradiance, 1));
164165
}

src/apps/ch11_voxel/ch11_voxel/resources/shaders/ch11_VoxelConeTracing.glsl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
uniform float u_TanHalfAperture = M_PI / 6;
1414
uniform bool u_GridAlign;
1515

16-
uniform sampler3D u_VoxelsAlbedoTexture;
1716
uniform sampler3D u_VoxelsIrradianceTexture;
1817

1918

@@ -110,7 +109,6 @@ vec4 traceCone(vec3 position_aabb, vec3 normal_aabb,
110109

111110
vec3 position_uvw = samplePosition_aabb / (aVoxelSize * ub_GridDimension);
112111
// TODO: rename, this is not albedo but occupancy atm
113-
vec4 albedo = textureLod(u_VoxelsAlbedoTexture, position_uvw, mipLevel);
114112
vec4 irradianceSample = textureLod(u_VoxelsIrradianceTexture, position_uvw, mipLevel);
115113

116114
// irradiance marching, front to back compositing
@@ -127,7 +125,7 @@ vec4 traceCone(vec3 position_aabb, vec3 normal_aabb,
127125
marchedIrradiance.a += (1 - marchedIrradiance.a) * irradianceSample.a;
128126
#endif
129127

130-
occlusion += ((1.0f - occlusion) * albedo.a) / (1.0f + falloff * coneDiameter);
128+
occlusion += ((1.0f - occlusion) * marchedIrradiance.a) / (1.0f + falloff * coneDiameter);
131129
// march the cone
132130
t += coneDiameter * samplingFactor;
133131
}

0 commit comments

Comments
 (0)