Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected format for textures? #13

Closed
jcjohnson opened this issue Aug 15, 2018 · 5 comments
Closed

Expected format for textures? #13

jcjohnson opened this issue Aug 15, 2018 · 5 comments

Comments

@jcjohnson
Copy link

I'm having a hard time understanding the way that textures are represented inside the renderer.

It seems internally (e.g. from the texture optimization example) that textures are stored in Tensors of shape

(batch_size, num_faces, texture_size, texture_size, texture_size, 3)

which I understand as representing a 3D grid of size texture_size^3 of RGB value for each face. How does this relate to the per-vertex UV texture coordinates that are stored in .obj files?

The CUDA kernel for loading textures appears to be bilinearly sampling the RGB values from the texture images, but I am having a hard time understanding exactly what is happening inside this kernel and exactly what it returns. Can you give a brief explanation?

@nkolot
Copy link
Collaborator

nkolot commented Aug 15, 2018

Hi Justin, my CUDA kernel is the same as the original CUDA code in the Chainer inplementation by the authors. I am not an expert in Computer Graphics and I don't to give you an incorrect answer, so I think it will be better to ask the original authors. Please let me know if you have any additional questions.

@jcjohnson
Copy link
Author

Thanks! I'll ask over at the original repo.

@jbohnslav
Copy link

Did you ever figure this out? I looked on the issues page of the original implementation, and didn't find your question.

@jcjohnson
Copy link
Author

@jbohnslav Yes, after looking at the code again I figured it out.

For each face, the texture tensor contains a discretized set of samples (in barycentric coordinates) of linear combinations of the colors for each vertex; during rasterization these sampled colors are re-sampled to generate the actual colors of faces. The texture_size controls the number of color pre-samples per face.

More concretely, suppose texture_size = T. Then textures has shape (N, F, T, T, T, 3), with the following semantics (up to a possible permutation of vertices):

textures[n, f, T - 1, 0, 0] is the RGB color of vertex 0 for face f
textures[n, f, 0, T - 1, 0] is the RGB color of vertex 1 for face f
textures[n, f, 0, 0, T - 1] is the RGB color of vertex 2 for face f

Other elements of the textures matrix give linear combinations of the colors at vertices, so for example:

textures[n, f, 0, 0, 0] is 0
textures[n, f, T - 1, T - 1, T - 1] is the sum of the colors at the three vertices for f
textures[n, f, T / 3, T / 3, T / 3] is equal to color1 / 3 + color2 / 3 + color3 / 3 (with T % 3 == 0)
textures[n, f, T / 2, T / 2, 0] is equal to color1 / 2 + color2 / 2 (with T % 2 == 0)

@jbohnslav
Copy link

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants