Displacement Map
eharetea

Using an image to displace geometry.

Creating a displacement map in VEX.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Wednesday July 30th, 2008 12:04 AM

Displacement Map - test.3daet.com


/*
* Author: Dan Lynch
* This code sets the uv's based on s & t values 
* if there are no uv coordinates
*/

#pragma hint path image
#pragma hint uv hidden
#pragma range h 0 10 
#pragma label h "Height"

displace
d_disp 
        (
        float h=1;
        string path "Mandril.pic";
        export vector uv 0;
        )
{

        wo_space(P);
        wo_nspace(N);

        float u;
        float V;
        if (!isbound("uv")) {
            s;
            t;
        } else {
            uv.x;
            uv.y;
        }

        vector var =  vector(texture(path,u,V));

        P+=normalize(N)*var*h;

        P=ow_space(P);
        N=normalize(computenormal(P,N,Ng));
}





/*
* Author: Dan Lynch
*/

#pragma hint path image
#pragma hint uv hidden
#pragma range h 0 10 
#pragma label h "Height"

displace
d_disp 
        (
        float h=1;
        string path "Mandril.pic";
        export vector uv 0;
        )
{

        wo_space(P);
        wo_nspace(N);

        float u uv.x;
        float V uv.y;
        vector var =  vector(texture(path,u,V));

        P+=normalize(N)*var*h;

        P=ow_space(P);
        N=normalize(computenormal(P,N,Ng));
}




Downloads:
Download: displacement_map.vfl 749 B
Download: displacement_map2.vfl 529 B

Please login or Click Here to register for downloads
Creative Commons License
Displacement Map by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com