Sign in to follow this  
Followers 0
TechnoRobbo

TRs Displacement Map 3D Version 2.0

28 posts in this topic

The grayscale of an image copied to the Clipboard modifies your image's pixel locations in 3D space. Endless varieties of can be achieved. 

 

Effect->Distort->TRs Displacement Map 3D

 

Version 2.0 has a bunch of fun creative features.

 

  • Highligth and Shadow
  • Light Source Positioning
  • Color Adjustment
  • Alpha Transparency.

Menu.PNG?raw=1

 

Here's the Quick Demo on Youtube: http://youtu.be/VfLRw4wsE2Q

TR.png?raw=1

 

 

Here's the Demo on how to create the 3 Skulls on Youtube:  http://youtu.be/aXQeIOBKabk

 

3skulls.png?raw=1

 

Here's the code:

Hidden Content:
// Submenu: Distort
// Name: TRs Displacement Map 3D
// Title: Displacement Map 3D PlugIn - v2.0
// Author: TechnoRobbo
// URL: http://www.technorobbo.com


#region UICode
double Amount1 = 0.5; // [0,1.5] Control
Pair<double, double> Amount2 = Pair.Create( 0.0 , 0.0 ); // Light Source
double Amount3 = 15; // [0,32] Intensity
double Amount4 = 1; // [0,1] Red Channel
double Amount5 = 1; // [0,1] Green Channel
double Amount6 = 1; // [0,1] Blue Channel
bool Amount7 = false; // [0,1] Alpha Transparency
#endregion


protected Surface img
{
    get { if (_img != null)
            return _img; 
          else
          {
            System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(GetImageFromClipboard));
            t.SetApartmentState(System.Threading.ApartmentState.STA); 
            t.Start();
            t.Join();
            return _img;
          }
        }
}
private Surface _img = null;
private void GetImageFromClipboard()
{
    Bitmap aimg = null;
    IDataObject clippy;
    try
    {
        clippy = Clipboard.GetDataObject();
        if (clippy != null)
        {
            aimg = (Bitmap)clippy.GetData(typeof(System.Drawing.Bitmap));
        }
    }
    catch (Exception )
    {
    }
    if (aimg != null)
    {
        _img = Surface.CopyFromBitmap(aimg);
    }
    else
    {
        _img = null;
    }
}


private void getNormal(double[] v0, double[]  v1, double[] v2,double[] normal)
    {
    double[] A = new double[3], B= new double[3], product= new double[3];
    double  length;
    A[0] = v2[0] - v1[0];
    A[1] = v2[1] - v1[1];
    A[2] = v2[2] - v1[2];
    B[0] = v0[0] - v1[0];
    B[1] = v0[1] - v1[1];
    B[2] = v0[2] - v1[2];
    product[0] = A[1] * B[2] - A[2] * B[1];
    product[1] = A[2] * B[0] - A[0] * B[2];
    product[2] = A[0] * B[1] - A[1] * B[0];
    length = Math.Sqrt(product[0]*product[0] + product[1]*product[1] + product[2]*product[2]);
    if (length == 0)    
        {               
        normal[0] = 0;
        normal[1] = 1;
        normal[2] = 0;
    }else{
        normal[0] = product[0] / length;
        normal[1] = product[1] / length;
        normal[2] = product[2] / length;
        }
    }






void Render(Surface dst, Surface src, Rectangle rect)
{
  
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    double CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    double CenterY= ((selection.Bottom - selection.Top) / 2)+selection.Top;
    double offx =0;
    double offy =0;
    double z=0;
    double tmp =0, tmp2 =0;
    int nx =0, ny =0;
    double zp=255;
    double SunX = Amount2.First * -1;
    double SunY = Amount2.Second * -1;
    double SunZ = 1;
    
    ColorBgra CP;
    double[] shade1  = new double[3];
    double[] shade2 = new double[3];
    double[] shade3 = new double[3];
    double shade = 0;
    double[] norms = new double[3];
    double[] RGB={0,0,0};
    
    //test variables=======
    //
    //SunX=-1;
    //SunY=-1;
    //Amount1=1;
    //Amount3=.7;
    //=======================
    
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        shade=0;
        for (int x = rect.Left; x < rect.Right; x++)
        {
            
            
            if (img == null){
              dst[x,y] = src[x,y];
            }else {
                
                //===============================
                //Plot Reflections and shading
                nx= x - (x % 2);
                ny= y - (y % 2);
                
             
                CP= img.GetBilinearSampleClamped(nx,ny);
                tmp =((double) CP.R + (double) CP.B + (double) CP.G)/3;
                shade1[0]=nx;
                shade1[1]=ny;
                shade1[2]=tmp;
                


                CP= img.GetBilinearSampleClamped(nx+1,ny);
                tmp =((double) CP.R + (double) CP.B + (double) CP.G)/3;                
                shade2[0]=nx+1;
                shade2[1]=ny;
                shade2[2]=tmp;
                
                CP= img.GetBilinearSampleClamped(nx,ny+1);
                tmp =((double) CP.R + (double) CP.B + (double) CP.G)/3;                  
                shade3[0]=nx;
                shade3[1]=ny+1;
                shade3[2]=tmp;
                
                getNormal(shade1,shade2,shade3,norms);
                
                shade = Math.Sqrt(Math.Pow(norms[0] - SunX , 2) + Math.Pow(norms[1] - SunY , 2) + Math.Pow(norms[2] - SunZ , 2));
                shade = (shade * 2 - 1) * Amount3;
                //================================
                //Get Real Pixels
                CP= img.GetBilinearSampleClamped(x,y);
                tmp =((double) CP.R + (double) CP.B + (double) CP.G)/3;


                z=255 + tmp * Amount1;
                   
                // 3D Projection
                tmp2=tmp;
                tmp=(double)x-CenterX;
                
                offx = tmp *  zp / z + CenterX;
                
                tmp=(double)y-CenterY;
                
                offy= tmp *  zp / z + CenterY;
                
                
                CP = src.GetBilinearSample((int)offx,(int)offy);
                if (tmp2 >0){
                    
                    CP.R = Int32Util.ClampToByte((int)(shade +  (double) CP.R * Amount4 ));
                    CP.G = Int32Util.ClampToByte((int)(shade +  (double) CP.G * Amount5 ));
                    CP.B = Int32Util.ClampToByte((int)(shade +  (double) CP.B * Amount6 ));
                }else if (Amount7){
                    CP.A=0;
                }
                dst[x,y]=CP;  
            }
        }
    }
}
 

 

DispMap.zip

Edited by TechnoRobbo
3

Share this post


Link to post
Share on other sites

This seems vastly different to the other bump map plugins.  Are you sure you wish to call it that?  That said - it's an interesting distortion!  Thanks for sharing it.

 

Edit:  Seems incredibly slow??

0

Share this post


Link to post
Share on other sites

It's only slow when the size of the image doesn't match the size of the map. When it does match the transformation is instant. I wasn't sure whether to call it a bump map or a displacement map. Since both refer to 3D shaders. Perhaps Displacement would be better.

 

Update: I've changed the name and included the recommendation to use same size image and map , I also modified the Youtube tutorial to reflect the changes.

 

 

Thanks for your help Ego.

Edited by TechnoRobbo
0

Share this post


Link to post
Share on other sites

Using a filled shape ellipse can produce some cool selective bulge type effect. Nice work TechnoRobbo B)

displace.png

Edited by DrewDale
0

Share this post


Link to post
Share on other sites

Nice...I like that it uses copy to clipboard.

 

The name change doesn't show in the menu options.  :( 

0

Share this post


Link to post
Share on other sites

Doughty,

 

Thanks - I must have not uploaded the changes - just the source code. Will do

 

Thanks Again

0

Share this post


Link to post
Share on other sites

Sorry I meant the name change doesn't show in the effects menu. I deleted, redownloaded and reinstalled, but please tell me if I'm not doing something right.

 

dispmap.png

 

Edit: Just noticed I have multiples of a few things.

Edited by doughty
0

Share this post


Link to post
Share on other sites

Doughty 

 

That's it, the Displacement Map without an icon. The others are different plugins probably from different plugin packs.

 

Maybe I should change the name to TR's Displacement Map to avoid confusion. 

 

Ok - done reinstall 

Edited by TechnoRobbo
0

Share this post


Link to post
Share on other sites

Sorry for my confusion. :bertie:

 

I used your Line Tracer plugin on the photo of my cat to create a map. The frame from another project worked just as I hoped.

 

Zoedisp.png

1

Share this post


Link to post
Share on other sites

Version 2.0 Displacement Map 3D - Original post refreshed

1

Share this post


Link to post
Share on other sites

Cool new update, works good with symbols too B)

3Ddisplacement.png

0

Share this post


Link to post
Share on other sites

DrewDale, I too find nature inspiring.

 

upton.png?raw=13

 

Image Created with TRs Displacement Map 3D v2.0 and Kate Upton.

Edited by TechnoRobbo
0

Share this post


Link to post
Share on other sites

New Reflecting pond instruction at http://youtu.be/1zIqTkgiIbw. guaranteed to be less boring than the last Reflecting pond Demo.

 

One more for the road -

 

The All Seeing Eye

AllSeeingEye.png?raw=1

Edited by TechnoRobbo
0

Share this post


Link to post
Share on other sites

Now I've actually watched the full video I 'get it' (and yep I always have stuff left over when assembling flatpack stuff ...)

 

icetr.jpg

 

... neat plugin

2

Share this post


Link to post
Share on other sites

That's why he is the King!

0

Share this post


Link to post
Share on other sites

Very nice plug-in TechnoRobbo. Nice image example Welshblue :)

 

I found it works just as effective on non-Gaussian blurred text too.

TRdisplacement_zpsc7a1f102.png

 

What I did extra was copy the background, tick the alpha transparency box then added drop shadow to the text.

0

Share this post


Link to post
Share on other sites

Thank youuuuuuu!!!!

I love this effect. It was the first , will train . Do not kill me . Did the Paint Net. :PaintBrushTool:

3htp.jpgUploaded with ImageShack.com

Edited by Lana
0

Share this post


Link to post
Share on other sites

Hello,

 

I'm having more than one problem today:

First I tried pasting my crash log right into this post but it wouldn't let me so I had to make an attachment of the crash log.

Second when I tried to use this TR's Displacement I had PDN crash on me twice.

Can anyone please read the crash log and tell me what I need to do to fix this?

0

Share this post


Link to post
Share on other sites

Update:

 

For some reason I cannot paste or insert an  image of the crash log: but when inserting the image link from Photobucket  this website froze on me and it also won't let me do an attachment.....Paint.net doesn't like me :(. Anyone else having problems with posting?

 

I also e-mailed the crash log to the professionals at this website hopefully they will get back to me soon.   

0

Share this post


Link to post
Share on other sites

Hi Kelly - I tried it too and it's incompatible with the new version. I have added it to the Incompatible Thread for you.

FYI - if you want to add the crash log next time to your post, here is a way. C&P the text then, when you are in your post, click on the little light switch (upper left corner of the tool bar) and add your text between this code: [hide}C&P your text here[/hide} Replace the 2 }'s with ]and[ then it will appear like this


Hidden Content:
text here


Bye :D .
0

Share this post


Link to post
Share on other sites

Thanks for the heads up, I will look into it when I get home.

 

By the way the Pixey that crash log posted was for Curtis Black's Displacement.

Edited by TechnoRobbo
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0