Your thoughts on and comments to Volume Rendering in Unreal Engine 4.

I am seeing some artifacts that I am unable to understand.

First, have a look at the effect I am getting:
f8288e803d.jpg

This is the material nodes(Not all inputs are used in the shader. StepSize and End are not used):

The T0 is the entry point of the volume(black triangle in the picture below), T1 I used as the directional vector. I use that vector to iterate through the volume(The small gray triangle). The BoundingBoxMax happens to be the origin of our 3D textures UVW(The large gray triangle).

5a5d95d552.png

And this is the code that I have inside the node:


float4 OutColor = float4(0, 0, 0, 1);
float Phase = 0.0;
float3 particlePos = T0; //This is the particle we are tracking. XY = UV, but we have to add n*WidthOfTexture to U and m*HeightOfTexture to V so we use Z to calculate that.
for (int i = 0; i < NumIterations; i ++)
{
	Phase = particlePos.z;
	uint numSegmments = NumRowsCols*NumRowsCols;

	float fraction = frac(Phase);
	
	float2 offset = float2(floor(numSegmments*fraction)/NumRowsCols, floor(NumRowsCols*fraction)/NumRowsCols);

	//Shrink the space 0-1 that covers the entire texture to 1/NumRowsCols of that to only cover one segment.
	float2 MUV = float2(particlePos.x/NumRowsCols, particlePos.y/NumRowsCols);

	//Add the offset. The offset is moving the "current slide subsquare of interest" around.
	offset.x = MUV.x+offset.x;
	offset.y = MUV.y+offset.y;

	float4 voxel = Texture2DSample(Tex, TexSampler, offset);

	OutColor = Alpha*voxel + (1-Alpha)*OutColor;
	particlePos += DirVec;
}

return OutColor;

The reason I ask is because the code inside the loop is basically the same as my custom flipbook node, which works. The only difference is that I am using the particle vectors x and y coordinate as my U and V coordinate. This is only a problem in the Z axis that causes 4 of the 6 surfaces to have this weird effect.

Somewhere my application of the Z axis must be wrong because the surface up and down are identical, while the surface between them have that effect you see.

Thank you for your help.