Since it is being generated by a shader, I am failing at using this:
void OnCollisionEnter(Collision other)
{
Debug.Log(other.gameObject.GetComponent<Renderer>().material.color); // this line will tell you the object's color which collide to the gameObject you attached this script to
}
Here is a video of my attempt:
I have attached the shader that is generating the volume rendering I would like to probe.
random ideas:
could pass probe position into shader, and then sample that position from 3d texture,
and get values back with appendbuffer or something similar.
or if can somehow calculate local position for probe (in that “3d chunk”) and do getpixel (x,y,z) there…maybe from bounds can interpolate it.
Thank you! Do you think that I should do it with CollisionEnter or CollisionStay? I would like to probe it as often as possible as it’s for haptics, which should run at 1kHz, but I guess FixedUpdate wouldn’t have the position info, right?
could add box collider on that cube area, to get overall collision on the bounds,
but it won’t give per voxel hit position, need to calculate the position and get value manually,
so at that point could just do it inside FixedUpdate().
i’m thinking something like this,
if you know that volumetric gameobject bounds, and if its aligned bounding box then easier, then interpolate to get probe position in X,Y,Z 3d texture coordinates
I thought about declaring another property to hold the voxel color, but I don’t understand the shader lifecycle and how to make it update the property’s value so that I can access it with my script, so these didn’t work:
compute shaders can also access those values in shader, but i dont know much about them
also need to check if that passed position is correct, local space vs worldspace. (you could debug it by setting some vertex or pixel colors based on distance to that passed position)
i’d also explore the other way around, reading directly from 3d texture, by mapping the probe position into local coordinates inside bounds. (no need shader work there)