Since I keep forgetting, here’s the basic steps.
Bring in your model with UV coords. This seems to be trivial with an FBX, I presume works with other types. The UV map represents how the pixels need to be laid out - baked.
Pass your model through a Script SOP with the following script. This ‘stores’ the UV map away as a vertex attributes, for use later:
[code]def cook(scriptOP):
scriptOP.clear()
# copy the input
a = scriptOP.inputs[0]
scriptOP.copy(a)
a = scriptOP.vertexAttribs['uv']
n = scriptOP.vertexAttribs.create ('uvMap', (0.0, 0.0))
for p in scriptOP.prims:
for v in p:
v.uvMap[0] = v.uv[0];
v.uvMap[1] = v.uv[1];
return[/code]
Now you can process as normal, including changing texture co-ordinates as needed to make the images you need.
Now - in your final render, you will need to use your uv map as the pixel position. Make a phong Mat with what you need, and use it to generate a GLSL Mat. In your vertex shader, edit:
// Use the custom attribute we added to save orig coords
in vec3 uvMap;
at the top, and then at the very end: // Leave the vVert stuff, but change position!
gl_Position = vec4 ((uvMap.st * 2.0) - 1.0, 0.0, 1.0);
Now the vertex will be outputted at the UV map position, not at the rasterized position. The trick is that all the other information your pixel shader needs, to light the pixel etc. is in the vVert structure, so you get a correctly shaded model baked out to a map.
Voila! I will still try to make a tutorial, with the whole process. Hope this is better than nothing. I was very pleased with myself when I worked it out