Texture Map and UVs
eharetea

Applying a texture map and uv coordinates.

Using VEX to generate a texture map and uv coordinates.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Tuesday July 29th, 2008 11:23 PM


/*
*
* Author: Dan Lynch
*
*/

#pragma hint Ka color
#pragma hint Kd color
#pragma hint Ks color
#pragma hint map file
#pragma hint uv hidden

#pragma label map "Texture Map"
#pragma label Ka "Ambient"
#pragma label Kd "Diffuse"
#pragma label Ks "Specular"
#pragma label roughness "Roughness"

#include <math.h>
#include <shading.h>


vector
d_amb(vector PNn)
{
        vector amb=0;
        illuminance(P,Nn,PI*2,LIGHT_AMBIENT) {
                amb += Cl;
                }
        amb += .1;
        return amb;
}

vector
d_diff(vector PNn)
{
        vector diffuse 0;
        illuminance(P,Nn,PI/2,LIGHT_DIFFUSE) {
                shadow(Cl);
                diffuse += Cl dot(Nn,normalize(L));
                }
        return diffuse;
}

vector
d_spec(vector PNnInfloat rough)
{
        vector spec 0;
        vector IandL;
        illuminance(P,Nn,PI/2,LIGHT_DIFFUSE)
                {
                shadow(Cl);
                IandL normalize(In normalize(L));
                spec += Cl pow(max(0,dot(Nn,IandL)),1/(rough*.1));
                }
        return spec;
}

surface
d_map
        (
        vector Ka=1Kd=1Ks=1;
        float roughness .1;
        export vector uv 0;
        string map "Mandril.pic";
        )
{
        float u 0;
        float V 0;
        if (!isbound("uv")) {
                s;
                t;
        }
        else {
                getcomp(uv,0);
                getcomp(uv,1);
        }

        vector Nn normalize(N);
        vector In normalize(I);
        vector tmap vector (colormap(map,u,V"mode""clamp"));
        Cf d_amb(P,Nn)*Ka;
        Cf += d_diff(P,Nn)*Kd;
        Cf += d_spec(P,Nn,-In,roughness)*Ks;
        Cf *= tmap;
}




Downloads:
Download: texture_map_and_uvs.vfl 2 KB

Please login or Click Here to register for downloads
Creative Commons License
Texture Map and UVs 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