Thursday, November 22, 2012

Look Dev- Expression Editor Code

Within Maya, I needed a stable way to play with the falloff curves for the opacity and radius values.  I decided to use the expression editor to "jerry-rig" some ramp behaviors as the actual ramps weren't behaving properly.  Also, these equations should be easy to transfer to the shader code in the C renderer.  Anyway, here's the code:

// Inverting and scaling initial opacity from texture map to get a base transparency
particleShape1.userScalar1PP = 1 - (0.01 * particleShape1.opacityPP);

//Transparency Ramp Values (linear interpolation)

//Distance where slope changes
float $minDist = 0.0;
float $fallOff1 = 0.05;
float $fallOff2 = 0.35;
float $fallOff3 = .9;

//Transparency targets where slope changes
float $transStart = .7;
float $transMid1 = .85;
float $transMid2 = 0.95;
float $transEnd = 1.0;

//Calculates rates of change for linear interpolation
float $slope1 = ($transMid1 - $transStart) / ($fallOff1 - $minDist);
float $slope2 = ($transMid2 - $transMid1) / ($fallOff2 - $fallOff1);
float $slope3 = ($transEnd - $transMid2) / ($fallOff3 - $fallOff2);
float $yInter2 = $transMid2 - ($slope2 * $fallOff2);
float $yInter3 = $transEnd - ($slope3 * $fallOff3);

//Radius Ramp Values (linear interpolation)

//Max/Min Randomization of radius
float $minRadRand = 1.0;
float $maxRadRand = 1.5;

//Radius targets where slope changes
float $minRad = .1;
float $midRad1 = .13;
float $midRad2 = .15;
float $maxRad = .18;

//Calculates rates of change for linear interpolation
float $slope4 = ($midRad1 - $minRad) / ($fallOff1 - $minDist);
float $slope5 = ($midRad2 - $midRad1) / ($fallOff2 - $fallOff1);
float $slope6 = ($maxRad - $midRad2) / ($fallOff3 - $fallOff2);
float $yInter5 = $midRad2 - ($slope5 * $fallOff2);
float $yInter6 = $maxRad - ($slope6 * $fallOff3);

// Sets the transparencyPP values
if(particleShape1.DistanceFromSurfacePP < $fallOff1)
    particleShape1.userScalar2PP = particleShape1.userScalar1PP * ($slope1 * particleShape1.DistanceFromSurfacePP + $transStart);   
else if(particleShape1.DistanceFromSurfacePP >= $fallOff1 && particleShape1.DistanceFromSurfacePP < $fallOff2)
    particleShape1.userScalar2PP = particleShape1.userScalar1PP * ($slope2 * particleShape1.DistanceFromSurfacePP + $yInter2);
else if(particleShape1.DistanceFromSurfacePP >= $fallOff2 && particleShape1.DistanceFromSurfacePP < $fallOff3)
    particleShape1.userScalar2PP = particleShape1.userScalar1PP * ($slope3 * particleShape1.DistanceFromSurfacePP + $yInter3);
else
    particleShape1.userScalar2PP = 1;   

// Resets the radiusPP
particleShape1.radiusPP = particleShape1.radius;

// Sets the radiusPP values
if(particleShape1.DistanceFromSurfacePP < $fallOff1)
    particleShape1.radiusPP = $slope4 * particleShape1.DistanceFromSurfacePP + $minRad;
else if(particleShape1.DistanceFromSurfacePP >= $fallOff1 && particleShape1.DistanceFromSurfacePP < $fallOff2)
    particleShape1.radiusPP = $slope5 * particleShape1.DistanceFromSurfacePP + $yInter5;
else if(particleShape1.DistanceFromSurfacePP >= $fallOff2 && particleShape1.DistanceFromSurfacePP < $fallOff3)
    particleShape1.radiusPP = $slope6 * particleShape1.DistanceFromSurfacePP + $yInter6;
else
    particleShape1.radiusPP = $maxRad;

// Adds in a random extra value to create texture in size
particleShape1.radiusPP = particleShape1.radiusPP * rand($minRadRand, $maxRadRand);

No comments:

Post a Comment