POV-Ray : Newsgroups : povray.general : deforming a texture on a mesh Server Time
2 Nov 2024 11:24:07 EDT (-0400)
  deforming a texture on a mesh (Message 1 to 7 of 7)  
From: esterichia
Subject: deforming a texture on a mesh
Date: 31 Aug 2010 10:05:00
Message: <web.4c7d0bd525779aa249aa3f520@news.povray.org>
I want to apply a texture to a disc (or a square or any plane object), applying
some deformation to the image I'm using. The deformation is incremental and
depends on the clock.

So I define a mesh of triangles to draw the disc and use the uv_vectors in each
point of the mesh to give the texture (uv_mapping).
Then, I apply the deformation to the uv_vectors and I leave fixed the
correspondence between the vertices of the triangles in the mesh and the
uv_vectors.

The grid made by uv_vectors always works properly, but when I apply some heavy
deformations, the mapped image does not follow the movement of the grid. More
precisely, the uv_vectors are being deformed as I want to (only in some area),
but the textured image undergoes other deformations, even outside the area in
which the uv-grid is changing.

Did anyone had a similar problem? I can post a piece of code if needed.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: deforming a texture on a mesh
Date: 31 Aug 2010 13:35:32
Message: <4c7d3d64@news.povray.org>
esterichia wrote:

> I want to apply a texture to a disc (or a square or any plane object), applying
> some deformation to the image I'm using. The deformation is incremental and
> depends on the clock.

I can't help you with the mesh uv mapping, but it sounds
like you might be better off deforming the texture itself.
There are two ways of doing this: Using a warp {} block
in the texture, which is limited to certain types of
supported deformations, or pigment functions.

For the latter option, the idea is to convert you image
pigment into a pigment function, and define a new function
which represents a deformed pigment. As user-defined vector
functions are currently not supported this requires defining
separate R,G,B functions and average them together later.

Assuming P is your existing image map pigment, and
(fx(x,y),fy(x,y)) is some 2D deformation function
to be applied to the image with coordinates ranging
from 0 to 1, it should be similar to (untested):

#macro FROM_BLACK(COLOR)
color_map
{
   [0 color rgb 0]
   [1 color COLOR]
}
#end

#declare F = function { pigment {P} }

#declare R = pigment
{
   function {F(fx(x,y),fy(x,y),z).red} FROM_BLACK(Red)
}
#declare G = pigment
{
   function {F(fx(x,y),fy(x,y),z).green} FROM_BLACK(Green)
}
#declare B = pigment
{
   function {F(fx(x,y),fy(x,y),z).blue} FROM_BLACK(Blue)
}
#declare Q = pigment {average pigment_map {[R] [G] [B]} }


Hope this helps,

   Christian


Post a reply to this message

From: esterichia
Subject: Re: deforming a texture on a mesh
Date: 3 Sep 2010 05:55:00
Message: <web.4c80c5d59ce242be49aa3f520@news.povray.org>
Thank you for the reply, I tried to use the second method you suggested and it
works but I still have two problems:

> Assuming P is your existing image map pigment, and
> (fx(x,y),fy(x,y)) is some 2D deformation function
> to be applied to the image with coordinates ranging
> from 0 to 1,

Is it possible to use define fx, fy as macros? The transformation I want to
apply depends on some parameters I have defined and parameters can not be passed
to functions.

> #macro FROM_BLACK(COLOR)
> color_map
> {
>    [0 color rgb 0]
>    [1 color COLOR]
> }
> #end

This works but the colors are very dark. I thought I should use some other
color_map, like
[0 color rgb 0]
[0.5 color COLOR]
[1 color rgb 1]
but this is not the case. Do I have to change the color_map?

Thank you for your help!


Post a reply to this message

From: clipka
Subject: Re: deforming a texture on a mesh
Date: 3 Sep 2010 07:08:50
Message: <4c80d742$1@news.povray.org>
Am 03.09.2010 11:54, schrieb esterichia:

>> #macro FROM_BLACK(COLOR)
>> color_map
>> {
>>     [0 color rgb 0]
>>     [1 color COLOR]
>> }
>> #end
>
> This works but the colors are very dark. I thought I should use some other
> color_map, like
> [0 color rgb 0]
> [0.5 color COLOR]
> [1 color rgb 1]
> but this is not the case. Do I have to change the color_map?

The problem is that they are averaged instead of added; you'll need to 
multiply the colour by a factor of 3:

  [0 color rgb 0]
  [1 color COLOR * 3]


Post a reply to this message

From: esterichia
Subject: Re: deforming a texture on a mesh
Date: 6 Sep 2010 10:30:00
Message: <web.4c84fa5d9ce242be617817920@news.povray.org>
Thank you clipka, you are right.


Post a reply to this message

From: Christian Froeschlin
Subject: Re: deforming a texture on a mesh
Date: 6 Sep 2010 18:12:52
Message: <4C856763.3040507@chrfr.de>
esterichia wrote:

> Is it possible to use define fx, fy as macros? The transformation I want to
> apply depends on some parameters I have defined and parameters can not be passed
> to functions.

Not quite sure what you mean. This works for me:

#local PARAM = 5;
#local f_param = function {2*x*PARAM}
#debug str(f_param(1,0,0),3,0)
#debug "\n"


Post a reply to this message

From: clipka
Subject: Re: deforming a texture on a mesh
Date: 6 Sep 2010 22:31:57
Message: <4c85a41d$1@news.povray.org>
Am 07.09.2010 00:12, schrieb Christian Froeschlin:
> esterichia wrote:
>
>> Is it possible to use define fx, fy as macros? The transformation I
>> want to
>> apply depends on some parameters I have defined and parameters can not
>> be passed
>> to functions.
>
> Not quite sure what you mean. This works for me:
>
> #local PARAM = 5;
> #local f_param = function {2*x*PARAM}
> #debug str(f_param(1,0,0),3,0)
> #debug "\n"

Note that strictly speaking, from the function's perspective this is a 
constant, not a parameter, i.e.:

   #local PARAM = 5;
   #local f_param = function {2*x*PARAM}
   #local PARAM = 6; // this will have no effect on the function result
   #debug str(f_param(1,0,0),3,0)
   #debug "\n"


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.