Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

UV Unwrapped Rendering

Helpful techniques for working with TouchDesigner. Answers only, no questions.

UV Unwrapped Rendering

Postby bwheaton » Fri Feb 10, 2017 2:55 pm

Please post on my RFE if you'd like this to be added as an official feature:
http://www.derivative.ca/Forum/viewtopi ... =17&t=9582


So - many systems either use unwrapped UVs to render, or allow you to 'bake' your feeds into a flat movie. The common way is to use UV coordinates and unwrap.

Advantages:
- a single viewpoint render is restricted by its angle in what parts of a geometry is visible, and what the pixel density is at that point. This method allows you to define the rendering resolution by UV mapping,
- If some of your content was produced by another artist or method, you can render to a map and perform simple video operations to transition or mix between your content and theirs,
- In projection mapping depth illusions (trompe l'oeil), you can make the best quality intermediate render from a specific viewpoint, then map onto an object for projection,
- Some systems like pixel based LEDs are inherently a pixel map, and you can render to that map from a physical representation of the LED structure/object.
- You can use TouchDesigner as production software, delivering baked renders for use in Touch or other software.

Method:
The key is to 'stash' the UV coordinates you need in a vertex attribute. Now you can re-texture as needed to draw in any way you need, as normal (the Texture SOP sets UV coordinates).
When you render, you need to make a custom Vertex Shader. A starting point can be generated from a Phong mat or PBR mat. Make the render look as close to your final product as you can - adding some render features require a change in shader, so try to get close enough to just need to tweak parameters and light position/angle etc.
Once you have a GLSL mat, apply textures and everything you need to make the render using that instead of the donor phong or PBR mat.
Now add near the top of your custom vertex shader:
Code: Select all
// Use the custom attribute we added to save orig coords
in vec3 uvMap;

And at the very end of your shader, right before the closing squiggle } :
Code: Select all
   // Leave the vVert stuff, but change position!
   gl_Position = vec4 ((uvMap.st * 2.0) - 1.0, 0.0, 1.0);

How it works:
TouchDesigner Fragment Shaders use the vVert structures to calculate all lighting and shading, effectively ignoring the built-in gl_position, but: the final output position of your vertex is based on that position.
It's a hack (which is why I'd like it built into TouchDesigner) that gets the best of both worlds at the cost of some simple GLSL code (not that it was that simple to work it out!).

Check it out.

Bruce
Attachments
UV unwrapped rendering.zip
(11.04 MiB) Downloaded 359 times
Last edited by bwheaton on Fri Feb 10, 2017 7:15 pm, edited 1 time in total.
bwheaton
 
Posts: 331
Joined: Mon Mar 19, 2012 1:33 am

Re: UV Unwrapped Rendering

Postby dogboy23 » Fri Feb 10, 2017 6:56 pm

can't wait to try this +1 for official feature
dogboy23
 
Posts: 89
Joined: Tue Mar 29, 2016 11:10 am
Location: Bristol, UK

Re: UV Unwrapped Rendering

Postby tiger_ad50 » Mon Sep 24, 2018 4:55 pm

Hi Bruce, I've been looking for a way to bake textures in TouchDesigner. I was happy to find your script.

Specifically, I'm using a light as a projector (using the Projector Map Attribute) to cast a render TOP onto a Geo. I want to then integrate that casted projection into the texture of my Geo (bake it) so that I can use it in a projection mapped project Im working on. What's tricky is I'd like to do all this in real time, as well. Your script is the only solution that seems to come close to letting me be able to do this, but I can't wrap my head around it.

I'm having trouble getting your script to work on my models. I have no idea why, but when I export my models with their UV sets as .FBX from Maya, and import them into TD and plug the mesh into your example program, the mesh doesn't unfold and the "unwrap" container is blank. I took your boxes included into the example into Maya to see why they work, and I tried distorting them in every way and changing names and your mesh still works fine when I export as .FBX and reimport into TouchDesigner. So I don't know why mine don't work. Is it something in the scripts? Nothing jumped out at me.

Thanks a lot for any advice you can throw my way!
tiger_ad50
 
Posts: 3
Joined: Fri Jul 06, 2018 10:52 pm

Re: UV Unwrapped Rendering

Postby bwheaton » Mon Sep 24, 2018 5:22 pm

Glad it’s helpful (assuming it works!).

The key to everything is UV coords in the mesh. I don’t know Maya, but possibly your mesh doesn’t have them? In Cinema4d, the object would have a texture tag.

Try importing your model in touch and in a geo, look at the viewer display options to turn on visible UV coordinates.

You should also be able to texture it in Touch (texture SOP) and then stash those coordinates, but you need them in the model really.

Bruce
bwheaton
 
Posts: 331
Joined: Mon Mar 19, 2012 1:33 am

Re: UV Unwrapped Rendering

Postby tiger_ad50 » Mon Sep 24, 2018 7:54 pm

Thanks for your quick reply Bruce!

I ended up trying with Cinema 4D, and sure enough, my models are working now. The same model that works when exported as .FBX with Cinema 4D does not work when exported with Maya. The vertices are listed and the model indeed shows correct UVs when applying a texture, and yet my Maya exports just don't want to work with the unwrap container. I'll use Cinema 4D for now.

If any Maya users find out what the reason for this is I'd love to know!

And thanks again Bruce for your reply, I'm breathing a sigh of relief to see a way forward :)
tiger_ad50
 
Posts: 3
Joined: Fri Jul 06, 2018 10:52 pm

Re: UV Unwrapped Rendering

Postby sl0throp » Mon Dec 31, 2018 1:20 pm

Sounds mostly like user error in Maya. Make sure on your FBX export options that you have UV Write selected. I never had any issue bringing in UV'd geo to Touch.
User avatar
sl0throp
 
Posts: 5
Joined: Mon Apr 05, 2010 10:39 am

Re: UV Unwrapped Rendering

Postby Gallo » Wed Mar 27, 2019 3:49 pm

tiger_ad50 wrote:Specifically, I'm using a light as a projector (using the Projector Map Attribute) to cast a render TOP onto a Geo. I want to then integrate that casted projection into the texture of my Geo (bake it) so that I can use it in a projection mapped project Im working on.


Hi,

Just jumping in the bandwagon...
So the idea would be to render the scene as seen by the projector ? meaning converting a projector to a camera and project it back through the real projector ?
Video Mapping / Digital art / Interactive installations / Creative coding
http://www.luxanima.io
User avatar
Gallo
 
Posts: 181
Joined: Fri Mar 24, 2017 5:46 am
Location: Paris

Re: UV Unwrapped Rendering

Postby bwheaton » Wed Mar 27, 2019 5:24 pm

Rendering the scene as seen by the projector is a different issue, and there are threads about that. Look for camschnappr. The question here is to render 'unwrapped' so that you can manipulate then rewrap onto your shape and use that for a projector setup.

This feature is going to be built in soon, I believe.

Bruce
bwheaton
 
Posts: 331
Joined: Mon Mar 19, 2012 1:33 am

Re: UV Unwrapped Rendering

Postby malcolm » Fri Apr 05, 2019 11:29 am

Yep it's in the 2019.10000 series of builds
User avatar
malcolm
Staff
 
Posts: 4371
Joined: Tue Nov 13, 2007 1:11 am

Re: UV Unwrapped Rendering

Postby JiveJive » Wed May 01, 2019 3:53 am

Is it an official feature?
Where I can find this?
Palette?

Thanks
JiveJive
 
Posts: 3
Joined: Fri May 25, 2018 8:38 am

Next

Return to Techniques

Who is online

Users browsing this forum: No registered users and 2 guests