[deleted] Why does the mi.TextureXf.eval() (X=1,2,3) return a 'list' of Floats, and how to convert it to tensor? #511
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @Mephisto405 This is just a design choice with some performance considerations. I believe casting the output to a Here's an example of a conversion: res = 32
texture = mi.Texture2f(dr.full(mi.TensorXf, 0.01, shape=(res, res, 3)))
x = mi.Float([1, 2])
y = mi.Float([3, 4])
points = mi.Point2f(x, y)
r, g, b = texture.eval(points)
tensor = dr.empty(mi.TensorXf, shape=(3, 2))
tensor[0, :] = r
tensor[1, :] = g
tensor[2, :] = b If your number of channels is defined at runtime, you can obviously replace the last 3 lines by a simple |
Beta Was this translation helpful? Give feedback.
Hi @Mephisto405
This is just a design choice with some performance considerations. I believe casting the output to a
TensorXf
would require an extra memory copy/shuffle which is not always needed, hence it is not the default behaviour.Also, the typical use case is a 2D RGB texture lookup, in which case you would want a
mi.Color3f
which is literally just 3 separate arrays. So the list representation makes more sense here.Here's an example of a conversion: