UV map?

Hi!
Is there a way to generate a Texture representing the UV map of a SOP (that might have been generated with the texure SOP for example)?
So I am not looking for a way to generate a UV map for some piece of geometry, but I’d like to look at a SOP’s UV map and maybe process it in order to texture the SOP.
Any hints?
Thanks a lot!

A neat trick that can be done to unwrap a SOP into UV space can be done in a GLSL MAT. Instead of using the SOPs positions for its output, you instead rerange the UVs to be between -1 and 1 in X and Y and just use -1 for the Z value. Write this to gl_Position and output the UV coordinate as the color in the pixel shader.
This will make the SOPs geometry take up the entire viewport as if it’s been unwrapped. This assumes your geometry has texture coordinates between 0 and 1 only

Hi Malcolm!
Thanks a lot, that really sounds like a neat trick, I’ll give it a try!

Hi!
So… I’m afraid my non-existent GLSL skills come into play here.
I Used a phong Mat and output the shader to have something working. I see where gl_Position is assigned in the vertex shader, but I don’t know how to access UV values :slight_smile:
another hint?
Excuse my bad glsl :confused:

Hi!
So that’s where I arrived… I get something that looks like a UV map, but it doesn’t quite fill the texture, I guess I’m missing something.
Here is what I think is relevant, below is the complete vertex shader. I didn’t change anything about the pixel shader.

[code]float U = (uv[0].x2)-1;
float V = (uv[0].y
2)-1;
float W = -1;
vec4 pos = vec4(U,V,W, 1);
vec4 worldSpaceVert =TDDeform(P);
vec4 camSpaceVert = uTDMat.cam * worldSpaceVert;

//gl_Position = TDCamToProj(camSpaceVert);
gl_Position = pos;

[/code]

Complete vertex shader

[code]uniform vec4 uAmbientColor;
uniform vec4 uDiffuseColor;
uniform vec3 uSpecularColor;
uniform float uShininess;
uniform float uShadowStrength;
uniform vec3 uShadowColor;

out Vertex {
vec4 color;
vec3 camSpaceVert;
vec3 camVector;
vec3 norm;
}vVert;
void main()
{
// First deform the vertex and normal
// TDDeform always returns values in world space
float U = (uv[0].x2)-1;
float V = (uv[0].y
2)-1;
float W = -1;
vec4 pos = vec4(U,V,W, 1);
vec4 worldSpaceVert =TDDeform(P);
vec4 camSpaceVert = uTDMat.cam * worldSpaceVert;

//gl_Position = TDCamToProj(camSpaceVert);
gl_Position = pos;
// This is here to ensure we only execute lighting etc. code
// when we need it. If picking is active we don't need this, so
// this entire block of code will be ommited from the compile.
// The TD_PICKING_ACTIVE define will be set automatically when
// picking is active.

#ifndef TD_PICKING_ACTIVE

vec3 camSpaceNorm = uTDMat.camForNormals * TDDeformNorm(N).xyz;
vVert.norm.stp = camSpaceNorm.stp;
vVert.camSpaceVert.xyz = camSpaceVert.xyz;
vVert.color = TDInstanceColor(vec4(P, 1.));
vec3 camVec = -camSpaceVert.xyz;
vVert.camVector.stp = camVec.stp;

#else // TD_PICKING_ACTIVE

// This will automatically write out the nessesarily values
// for this shader to work with picking.
// See the documentation if you want to write custom values for picking.
TDWritePickingValues();

#endif // TD_PICKING_ACTIVE
}
[/code]

Thanks again!

You don’t want to run it through any of the deformation/transformations. Just output the rescaled UVs directly into gl_Position. The reason this works is because gl_Position is in post-projection space which is defined as -1 on the left side of the image and +1 on the right side of the image (and similar for bottom/top).

Hi again,
sorry, I don’t get it. 've been trying out things, but it doesn’t seem to me that my vector ‘pos’ is processed/transformed/deformed in any way in the code above. I mean I basically did assign the UVs directly to gl_Position, didn’t I? hm… hope you can help me out here. I couldn’t get anything substantially better than the code above.

Another question: his should work in conjunction with the texture SOP and, e.g. a sphere SOP(polygon), right?

Sorry you are correct, I misread your shader. The code looks right. If it’s not filling the output is it possible your UVs don’t actually go all the way from 0->1?

hm, I was afraid you would say that :slight_smile:
Well, my texture coordinates do not go from 0 to 1, yes. But actually, they are:

  1. created by the texture SOP automatically without any obscure settings, for a standard sphere SOP input,
  2. and if I put the rendered image onto the sphere with these texture coordinates it should still work(colour the whole sphere), if I don’t exceed 0-1, right? That is, if I’m doing things right there…
    hm… still a bit puzzled. I’m surprised this is so hard, am I the only one who wants to have a look at texture sops mapping to process it?
    cheers!

Maybe I’m unclear on what you are trying to do. Can you post your example file?

Hi!
Posting an example, sorry, it’s a bit messy.
I guess I didn’t explain well. What I want is this:
The sphere SOP generates UV coordinates, as well as the texture SOP. In order to procedurally generate a texture for a procedurally generated geometry, I’d like to have something like this
i214.photobucket.com/albums/cc23 … 3_wire.png
as a texture. So, the UV mapping, as a texture. In order to look at it, or to process it, and to apply textures on the geometry, according to the automatically generated UV layout.
(I realize that the texture SOP doe not generate such clean layouts as in the screenshot. I just want to look at ‘its output’) I hope it makes sense what I’m saying.
Thanks again!
UVtests.toe (10.5 KB)

Are you looking to visualize the actual UV values for the sphere? In that case you just need to pass the uv[0] values through to the pixel shader and output them to the fragColor[0]. You can delete 90% of the shaders since you don’t care about any of the lighting.
The overall shape you are seeing is correct in this since your sphere is so low polygon. If you increase the frequency of the polygons you’ll see it now takes up most of the image.
If you are looking to see the unwrapped color texture (say, of a texture of the earth), then instead of outputting the UV you should just sample the texture in the pixel shader and output that as your color instead.

In case someone else falls into this 5 years old thread, here is a short video I put together explaining how to get the unwrapped UVs - based on malcolm’s answer above: TouchDesigner Tips _01 UV Unwrapping - YouTube