Hi, is there any way to take a 2D slice from a Texture3D from any angle (not just the x, y, and z planes) in real time? For example, in the image below the plane would take on the Texture3D values at the intersection (the cube being the texture 3D and the plane being the slice).
You need to have the matrix to transform the plane into the Texture3D’s space. Something like:
struct v2f {
float4 pos : SV_Position;
// texcoord for 3d texture
float3 uvw : TEXCOORD0;
// any other stuff
};
// transform matrix calculated in c# and pass to the material via SetMatrix()
float4x4 _WorldToVolume;
// in vertex shader
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
o.uvw = mul(_WorldToVolume, float4(worldPos.xyz, 1.0)).xyz;
// in fragment shader
fixed4 color = tex3D(_VolumeTex, i.uvw);
In c# you’ll need to calculate a matrix that would be for the back bottom left corner of the volume you want.
2 Likes