Message Passing
eharetea

Using a displacement shader to control a surface shader's parameters.

Message passing between surface and displacement .vfl files.

Date Created:Friday December 29th, 2006 03:41 AM
Date Modified:Saturday December 26th, 2009 10:57 AM

Message Passing - test.3daet.com


/*
*
* Displacement shader
*
* Author: Dan Lynch
*
*/


#pragma hint switcher toggle
#pragma label switcher "Turbulence/Brownian"
#pragma label amp "Amplitude"
#pragma label lacunarity "Lacunarity"
#pragma label recursions "Recursions"
#pragma label freq "Frequency"
#pragma group Displace freq offset recursions lacunarity amp
#pragma hint pass hidden

displace
d_dpass (
        int switcher 0;
        vector freq 1offset 0;
        int recursions 5;
        float lacunarity 2;
        float amp=5;
        export float pass=0;
        )
{
    vector Pnz wo_space(P+offset)*freq;
    vector Nn normalize(N);
    float Nz 0;
    float mlt 1;
    float iF;
    int i;   
    
    for(i=0;i<recursions;i++){
        iF = i*5.6789;

        if(switcher==0) {
                Nz += abs(noise(iF+Pnz*mlt)-.5)/mlt;
        } else {
                Nz += (noise(iF+Pnz*mlt)-.5)/mlt;
        }

        mlt *= lacunarity;
    }
    pass Nz;
    += Nn Nz amp;
    computenormal(P);
}




/*
*
* Surface shader
*
* Author: Dan Lynch
*
*/

#pragma hint Ca color
#pragma hint Cd color
#pragma hint Cs color
#pragma hint Ca1 color
#pragma hint Cd1 color
#pragma hint Cs1 color

#pragma hint uv hidden

#pragma hint lights toggle

#pragma label Ca "Ambient"
#pragma label Ca1 "Ambient 2"
#pragma label Cd "Diffuse"
#pragma label Cd1 "Diffuse 2"
#pragma label Cs "Specular"
#pragma label Cs1 "Specular 2"
#pragma label roughness "Roughness"
#pragma label roughness1 "Roughness"

surface
d_pass
        (
        vector Ca=0Cd={.2,1,.2}, Cs=0Ca1=0Cd1=0Cs1=0;
        float roughness .1roughness1=.1mlt=4;
        export vector uv 0;
        int lights=0;
        )
{
        float u 0;
        float V 0;

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

        vector Nn normalize(N);
        vector In normalize(I);

        dimport("pass",Nz);
        float Nz Nz*mlt;
        if (lights) {
                Cf ambient(Nn,In)*lspline(Nz,Ca,Ca1);
                Cf += diffuse(NnIn)*lspline(Nz,Cd,Cd1);
                Cf += lspline(Nz,specular(Nn,-In,roughness)*Cs,specular(Nn,-In,roughness1)*Cs1);
        } else {
                Cf lspline(Nz,Ca,Ca1);
                Cf += lspline(Nz,Cd,Cd1);
                Cf += lspline(Nz,Cs,Cs1);
        }
}



The downloadable HIP file contains the VOPs version of this code.



Downloads:
Download: messagepassing.hip 91 KB
Download: pass_displacement.vfl 1 KB
Download: pass_surface.vfl 1 KB

Please login or Click Here to register for downloads
Creative Commons License
Message Passing 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