Volumetric Lightmap access in materials

for anyone looking to do this, there’s a solution which doesn’t involve modifying the engine source code by a user called @Char_ly on this thread.

just add a custom node with a world position input:

#if PRECOMPUTED_IRRADIANCE_VOLUME_LIGHTING

// Compute indirection UVs from world position

float3 IndirectionVolumeUVs = clamp(WorldPosition * View.VolumetricLightmapWorldToUVScale + View.VolumetricLightmapWorldToUVAdd, 0.0f, .99f);

float3 IndirectionTextureTexelCoordinate = IndirectionVolumeUVs * View.VolumetricLightmapIndirectionTextureSize;

// Get the Brick we need to use

float4 BrickOffsetAndSize = View.VolumetricLightmapIndirectionTexture.Load(int4(IndirectionTextureTexelCoordinate, 0));

float PaddedBrickSize = View.VolumetricLightmapBrickSize + 1;

// Compute the UVs of the texture

// We first offset to the correct Brick and then calculate the UVs inside the brick

float3 BrickTextureUVs = (BrickOffsetAndSize.xyz * PaddedBrickSize + frac(IndirectionTextureTexelCoordinate / BrickOffsetAndSize.w) * View.VolumetricLightmapBrickSize + .5f) * View.VolumetricLightmapBrickTexelSize;

// Compute the Ambient value at the given BrickTextureUVs

return Texture3DSampleLevel(View.VolumetricLightmapBrickAmbientVector, View.VolumetricLightmapBrickAmbientVectorSampler, BrickTextureUVs, 0).xyz;

#else

return float3(1, 1, 1);

#endif

it seems to work perfectly! all credits go to them, of course.

1 Like