8
$\begingroup$

I'm rendering image textures on deformed meshes like in this question:

enter image description here

The parts of the rectangular image that are compressed into the small faces look the same as the do in the flat image, except they're simply smaller now. Conversely, the large faces look the same as before, except now they're simply larger.

One might say that the mean colour intensities over the face have been preserved. Is it possible to preserve the sum instead of the mean over each face? With this method of deformation, compressed areas would get brighter, and stretched areas would get dimmer.

An analogy would be stretching out a balloon, where its colour fades as the stretch gets more extreme.

EDIT: Here is an example .blend file and image

You'll have to change the path to the image in the texture menu (I couldn't figure out out to suck the image into the .blend file, or specify a relative path).

$\endgroup$
  • $\begingroup$ Perhaps there is a way to script texture values? I think what I need to a way to generate texture values based on face area, and somehow compare the area to its "native" size. $\endgroup$ – ajwood Sep 10 '13 at 12:28
  • 2
    $\begingroup$ Maybe if you provide a demo .blend with this texture and the mesh, saves us from setting it up. $\endgroup$ – zeffii Sep 12 '13 at 12:45
3
+50
$\begingroup$

It is possible to create an Image Texture from the Vertex Color layer. The process is a little convoluted (for the time being)

Method 1

  1. Establish the vertex color map
  2. Make a material from the vertex colors
  3. Bake Mode: Texture
  4. Make a material node tree to brighten the original texture with the baked one

Method 2 (cycles specific.. but can be done in BI too)

  1. Establish the Vertex color map
  2. Add Node Material to rgb Mix this:

    • Texture node
    • Attribute node referencing 'Col'

Establish the vertex color map. Here i'm remapping from average distance to the median of each polygon, I suspect you can modify it to behave the way you want. For this to work you need to be in vertex paint mode

import bpy
from mathutils import Vector

obj = bpy.data.objects["Plane.001"]
mesh = obj.data

mesh.vertex_colors.new()
color_layer = mesh.vertex_colors.active  
verts = mesh.vertices
polys = []

# first scan through to figure out min and max stretch
for poly in mesh.polygons:

    face_median = Vector()
    for idx in poly.vertices:
        face_median += verts[idx].co
    face_median /= poly.loop_total

    qdist = lambda idx: (verts[idx].co - face_median).length
    stretch = sum([qdist(idx) for idx in poly.vertices])
    polys.append( stretch / poly.loop_total )

# now colour them as a function of their relative stretch
min_val = min(polys)
max_dif = max(polys) - min(polys)
i = 0
for g, poly in enumerate(mesh.polygons):
    c = (polys[g] - min_val) / max_dif
    for idx in poly.loop_indices:
        color_layer.data[i].color = (c,c,c)
        i += 1

## set to vertex paint mode to see the result
bpy.ops.object.mode_set(mode='VERTEX_PAINT')

1 - c would give the inverse enter image description here

Node Tree

The two methods differ mostly in how the Node Tree is constructed:

  • mix(baked, original texture)
  • mix(vertex_color_layer, original_texture).

It may end up something like this, the setup is pretty similar for Cycles and Blender Internal
enter image description here

But really there are many ways to set up this node tree, probably deserving their own Question/Answer.

$\endgroup$
  • 1
    $\begingroup$ It's going to be a few days before I'll be able to test this in my case, but it looks like exactly what I'm after :) $\endgroup$ – ajwood Sep 13 '13 at 14:18
  • $\begingroup$ I'm stuck on 1.4.. Could you edit to explain how to make the node tree? $\endgroup$ – ajwood Sep 18 '13 at 19:46
  • $\begingroup$ BI, please and thanks (I've been trying to learn cycles, but I think I'd like to stick to what I'm more comfortable with, since I find this quite confusing) $\endgroup$ – ajwood Sep 18 '13 at 20:08
  • $\begingroup$ I actually don't understand the need for baking.. how does this differ from simply assigning it to a material with "vertex color light" enabled, and blend the materials without baking? $\endgroup$ – ajwood Sep 18 '13 at 20:26
  • $\begingroup$ yes, the second method works for Blender Internal too, no real need to bake -- it depends on your workflow $\endgroup$ – zeffii Sep 18 '13 at 21:04
3
$\begingroup$

A similar question was recently asked on the blender artists forum.

In looking into that one, I found that blender does still have a mapping mode for "stress" mapping in the texture coordinate drop down.
By baking out a texture generated from a ramp and mapped by stress, you can get a colour representation of the compression or expansion of each UV element, then map that to whatever other value you want to effect.
An example of the effect of this mapping can be seen here: enter image description here
And an animated version can be seen here

$\endgroup$
  • 1
    $\begingroup$ this is definitely the way to go. $\endgroup$ – zeffii Sep 23 '13 at 13:56
  • 1
    $\begingroup$ I still haven't been able to make this work.. $\endgroup$ – ajwood Oct 4 '13 at 21:06
  • $\begingroup$ I've put a blend file together with a video demo over here: daveleack.com/2013/10/22/stress-maps-interesting-stuff $\endgroup$ – DaveLeack Oct 22 '13 at 18:44
  • $\begingroup$ I just spotted you had uploaded a blend file. I tried modding your file to work with this method but something was going funky with the texturing (I did try loading in a file into the image datablock, something else was freaking out though, not sure what) so I've used the above technique to make a very simple example blend file which you'll find here tinyurl.com/og4hzz3. I keyed the lattice deformer strength to show the effect, but you only see it in rendered mode, not textured viewport. Not entirely sure why that is, but it should get you started on testing this method for your needs. $\endgroup$ – DaveLeack Oct 23 '13 at 22:56
1
$\begingroup$

Well, the closest I know of without creating a custom script is to enable the 'Stretch' display option in the UV image editor from the properties sidebar:

enter image description here

Which produces this:

enter image description here

However, extracting and using this data in a useful way (other than taking a screenshot) is another matter, I just thought I might as well put this out there just in case it's useful in some way.

$\endgroup$
  • $\begingroup$ What version of Blender is that? I can't find the panel. $\endgroup$ – ajwood Sep 12 '13 at 16:54
  • $\begingroup$ @ajwood press 'N' while the cursor is in the uv image editor area, this is the latest official release of blender. $\endgroup$ – Ray Mairlot Sep 12 '13 at 17:09
  • $\begingroup$ I don't see it. I'm using version 2.68a, which I understand to be the latest version. My properties sidebar doesn't have that option.. dropbox.com/s/ryjf7cdf52vu53i/… $\endgroup$ – ajwood Sep 12 '13 at 20:37
  • $\begingroup$ @ajwood you need to be viewing a UV map, not an image $\endgroup$ – gandalf3 Sep 12 '13 at 21:18
0
$\begingroup$

Addon Tension Map

(by pyroevil)

Download Addon (works in blender 2.79)

  • install and enable addon
  • activate Tension Map, located in Object Data properties panel
  • set two shape keys (rest and stretched position)
  • move on timeline so stretch / squeeze map is generated (new "tm_tension" appears in Vertex Color panel, and you can see directly result in 3D window - Vertex Paint mode)
  • add Attribute node to your material, into the "Name" field type "tm_tension"

(In your case use Attribute node as factor for mixing diffuse and transparent shader.)

There are many cases where this addon can be useful. In general, addon generates red vertex color for stretched and green vertex color for squeezed vertecies. Main purpose of this addon was for skin deformations like face expressions.

With ColorRamp node you can change default Red/Green colours what ever you need to. Or use greyscale "Fac" socket. Or separate Red / Green channel to control individually influence of stretched / squeezed parts of mesh. Or many other options ... :)

enter image description here

Links

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.