Howdy,
There are some great resources for HLSL and materials out there BUT for volume textures things seem pretty sparse (except for sparse volume textures which seem to have some more popularity due to VDB ).
Question:
How can I sample a volume texture to do ray marching in the Materials editor?
Notes:
- Using UE 5.5
- Open to Volumetrics plugin if there is something in there.
- I currently generate my volume textures from c++ similar to the great TBRaymarch Plugin
- Is that plugin now part of the Volumetrics plugin…?
Tried:
I followed this awesome tutorial and got it working just find for a 2D texture (PseudoVolumeTexture). However, tried to switch a volume texture causes the Sampler to never be found.
Example custom hlsl code. Neither sampling mode below worked.
float accumdens = 0;LocalCamVec = normalize(mul(Parameters.CameraVector, (float3x3)LWCToFloat(GetPrimitiveData(Parameters).WorldToLocal)));
for (int i = 0; i < MaxSteps; i++) {// Use Texture3DSample or VolumeTexture.Sample instead of PseudoVolumeTexture
//float cursample = Texture3DSample (VolumeTexture, VolumeTextureSampler, saturate(CurPos)).r;float cursample = VolumeTexture.Sample(VolumeTextureSampler, saturate(CurPos)).r;accumdens += cursample * StepSize;CurPos += -LocalCamVec * StepSize;}
CurPos -= -LocalCamVec * StepSize;CurPos += -LocalCamVec * StepSize * FinalStepSize;
// Final sample with adjusted step size
//float cursample = Texture3DSample (VolumeTexture, VolumeTextureSampler, saturate(CurPos)).r;float cursample = VolumeTexture.Sample(VolumeTextureSampler, saturate(CurPos)).r;accumdens += cursample * StepSize * FinalStepSize;
return accumdens;
Here is an image using a VolumeTexture but manually sweeping through the Z axis (no HLSL just a time + sine node on the Texture UV)…