Forum

Sample texture and apply color to object

Hallo vvvvriends,
say i have some flat objects laying in the same plane, orthographic camera, they come form blender with the proper UV mapping from view. Now I want to sample a texture and paint each object with the average colour that corresponds to its “piece” of uv mapping. Getting the color on the centroid may work as well, but getting the average colour of the object is the goal.
I attach a patch with a .dae with some objects.
tx

vvvvtest.zip (90.6 kB)

Here with vertex colouring, still missing face/object colouring.

vvvvtest.zip (226.0 kB)

you have to do that per subset
since shader won’t know how you would like to subdivide geometry
so how this will work, is to calculate the center of your subset in uv coords and sample texture from that coords.
then you can use “tex.0SampleLevel(s0,uv,mipLevel)” mipLevel 0 is basically one pixel size so if you put there mipLevel higher then 0 u will get approximate of neighbors, so you can calculate mipLevel from overall size of your subset…

hope that helps…

Hi, yes it makes sense althogh not sure that my hlsl skills will take me anywhere near a working shader… also in the real geometry there are a few concave topologies. Maybe I could manually fix the origin in Blender and then use the origin as point of interest.
I have to say that I ve already tried using the Centroid node but that would work just for faces.
I have no idea how subsets are treated within a geometry… need to look further on that direction.
tx
Simone

try look on to this

vvvvtest.rar (220.1 kB)

How about scaling the tex coords of each object to 0 in blender (so it samples a point) and positioning where you want the sample centre to be. if theres not too many objects and you don’t do hells, it will be the simplest method?

@catweasel that may work but I have a hundred objects and it may be a pita …

@antokhio I repost a working patch with your shader (tx !!!), I set the origin of each object to its geometry and get its position in vvvv, the resizing of the texture must be manually applied althouhg I guess one can calculate it depending on the overall size of the mesh

  • Mips level does not seem to work

object color by texture.zip (229.2 kB)

Mips work but they not gonna give you any obvious result in this case.
You can test them out by putting SampLelevel in the normal constant shader and play with level.