dokipen
(Dan 'dokipen' Elliott)
June 30, 2015, 4:32am
241
mentioned Ray Marching for Volume Rendering, and I figured I’d save him some time since I did a little while ago just after we got texture sampling from custom nodes.
http://i.imgur.com/Z5MoBGc.png
Here are the assets:
http://i.imgur.com/EdrLlmU.jpg
http://i.imgur.com/XcKUv2g.png
And the custom node (which is kind of messy, but it was my first custom node):
float totalValue = 0.0;
int steps;float3 p;
int slice;
float2 cornerpos;
float2 coord;
float4 value;
for (steps=0; steps < MaximumRaySteps; steps++)
{
p = (((from + (direction* StepLength*steps))-position));
slice = ((p.z/height)*(rows*columns))+(rows*columns/2);
cornerpos = float2(((slice%columns)/columns), floor(slice/columns)/rows);
coord = cornerpos + float2(((p.x/width)+0.5)/columns,((p.y/length)+0.5)/rows);
if((abs(p.x)>width/2)+(abs(p.y)>length/2)+(abs(p.z)>height/2)+(distance(p+position,CameraOrigin)>Depth) < 1) totalValue += Texture2DSample(Tex,TexSampler,coord).r*(Density);
}
return totalValue;
It’s pretty basic; I look forward to seeing how volume rendering evolves in UE4 ('s distance field ray marching materials look sweet)!
Heya, instead of using the world position for your start position of the ray, you can use the bounds0-1UVW node as an already normalized 3d texture coordinate. I haven’t tried your code but are you able to rotate the cube?