VIZA 616 Rendering and Shading Grape

VIZA 616 Rendering and Shading, Spring2020 
Recreate the pattern of grapes,  Jiaqi Cui
__________________________________________________________________________________________

Render Image just use PxrConstant(BaseColor)


Render us PxrSurface
Added ClearCoat,SubSurface,RoughReflection, and Glass refrection/reflection
__________________________________________________________________________________________
Analysis before starting


__________________________________________________________________________________________

Step1. Setting Base Color

//2020-03-010//
// VIZA 616 Rendering and Shading, 2020 Spring //
// by Jiaqi Cui//

shader grape(float minDistance = 0.0,
float maxDistance = 0.0,
color dark_baseColor = color(0,0,0),
color pale_baseColor = color(0,0,0),
string space = "world",
output float blend = 0.0,
output float dist = 0.0,
output color resultRGB = 0)

{
point PP = transform(space,P);
dist = distance(PP,point(0,0,0));

blend = smoothstep(minDistance,maxDistance,dist);
resultRGB = mix(pale_baseColor,dark_baseColor,blend);

}

__________________________________________________________________________________________
Step 1.1 Setting gradient color from center to ends

shader gradient(float  minheight = 1.25,
                 float  maxheight = 2.5,
                 color  mincolor = color(1,0,0),
                 color  maxcolor = color(0,1,0),
                output color resultRGB = 0)
{
point localOrigin = transform("object",P);

float width = abs(localOrigin[0]);
float height = abs(localOrigin[1]);
float depth = abs(localOrigin[2]);

float blend = smoothstep(minheight, maxheight, height);
resultRGB = mix(mincolor, maxcolor, blend);
}
__________________________________________________________________________________________
Step1.2 Adding small stripes

shader stripe(float  minheight = 1.25,
                 float  maxheight = 2.5,
                 color  minBaseColor = color(1,0,0),
                 color  maxBaseColor = color(0,1,0),
color stripeColor = color(0,1,1),
                 output color resultRGB = 0,
float freq = 10,
float s = 0 [[int lockgeom = 0]]
)

{
point localOrigin = transform("object",P);
float x = localOrigin[0];
float y = localOrigin[1];
float z = localOrigin[2];
float width = abs(x);
float height = abs(y);
float depth = abs(z);

float blend = smoothstep(minheight, maxheight, height);
color baseColor = mix(minBaseColor, maxBaseColor, blend);

float stripeSwitch = sin(s*2*M_PI*freq);
resultRGB = mix(baseColor,stripeColor*0.2,stripeSwitch*blend);

}

__________________________________________________________________________________________
Step1.3 Adding Small white voronoi Noise

float dist2cell(point p, string spacename, float freq, float jitter) {
    point pp = transform(spacename, p) * freq;
    point thiscell = point(floor(pp[0]) + 0.5,
                           floor(pp[1]) + 0.5,
                           floor(pp[2]) + 0.5);
    float dist2nearest = 1000;
    int i,j,k;
    for(i = -1; i <= 1; i += 1)
       for(j = -1; j <= 1; j += 1)
           for(k = -1; k <= 1; k += 1) {
              point testcell = thiscell + vector(i,j,k);
              point pos = testcell + (noise("cell", testcell) * jitter) - 0.5;
              float dist = distance(pos, pp);
              if(dist < dist2nearest)
                 dist2nearest = dist;
              }
    return dist2nearest;
    }
//-------------------------------------------------------


shader cell(float  minheight = 1.25,
                 float  maxheight = 2.5,
                 color  minBaseColor = color(1,0,0),
                 color  maxBaseColor = color(0,1,0),
             color  stripeColor = color(0,1,1),
                 output color resultRGB = 0,
float freq = 10,
             float s = 0 [[int lockgeom = 0]],
string spacename = "object",
float cellfreq = 5,
float radius = 0.15,
float blur = 0.1,
float jitter = 1,
output float resultMask = 0,
color patcolor = color(1,0,1),

)

{
point localOrigin = transform("object",P);
float x = localOrigin[0];
float y = localOrigin[1];
float z = localOrigin[2];
float width = abs(x);
float height = abs(y);
float depth = abs(z);

float blend = smoothstep(minheight, maxheight, height);
color baseRGB = mix(minBaseColor, maxBaseColor, blend);

float stripeSwitch = sin(s*2*M_PI*freq);
color stripeRGB = mix(baseRGB,stripeColor*0.2,stripeSwitch*blend);

//cecullar
float d = dist2cell(P, spacename, cellfreq, jitter);
float resultF = 1 - smoothstep(radius, radius + blur, d);
resultRGB = mix(stripeRGB, patcolor, 0.2*resultF);


}



__________________________________________________________________________________________
Step 1.4 Adding vfbm Noise to simulate color variant and specualr color

///////////////////////////

vector vfBm (point p, float filtwidth, float octaves, float lacunarity, float gain)
{
float amp = 1;
point pp = p;
vector sum = 0;
float fw = filtwidth;
float i;

for (i = 0;  i < octaves;  i += 1)
                {
      sum += amp * snoise (pp, fw);
      amp *= gain;
                  pp *= lacunarity;
                  fw *= lacunarity;
                }

               return sum;
}


float voronoi(point p, string spacename, float freq, float jitter) {
    point pp = transform(spacename, p) * freq;
    point thiscell = point(floor(pp[0]) + 0.5,
                           floor(pp[1]) + 0.5,
                           floor(pp[2]) + 0.5);
    float dist2nearest = 1000;
    int i,j,k;
    for(i = -1; i <= 1; i += 1)
       for(j = -1; j <= 1; j += 1)
           for(k = -1; k <= 1; k += 1) {
              point testcell = thiscell + vector(i,j,k);
              point pos = testcell + (noise("cell", testcell) * jitter) - 0.5;
              float dist = distance(pos, pp);
              if(dist < dist2nearest)
                 dist2nearest = dist;
              }
    return dist2nearest;
    }
///////////////////////////////////////////////////////////////////////////////////////////////


shader vfbmShader(
//basic gradient color input
float  graMinheight = 1.25,
                 float  graMaxheight = 2.5,
                 color  graMinBaseColor = color(1,0,0),
                 color  graMaxBaseColor = color(0,1,0),
//stripe color input
color  stripeColor = color(0,1,1),
float stripeMix = 0.08,
                 float stripeFreq = 10,
float s = 0 [[int lockgeom = 0]],
//voronoi noise input
string spacename = "object",
float vorCellfreq = 5,
float vorRadius = 0.15,
float vorBlur = 0.1,
float vorJitter = 1,
float vorMix = 0.06,
color vorPatcolor = color(1,0,1),
//vfBm noise input
float fbmFreq = 1,
float fbmFiltwidth = 1,
float fbmOctaves = 1,
float fbmLacunarity = 1,
float fbmGain = 1,
float fbmMix = 0.1,
color fbmColor = color(0),
output color resultRGB = 0,

)

{
point localOrigin = transform("object",P);
float x = localOrigin[0];
float y = localOrigin[1];
float z = localOrigin[2];
float width = abs(x);
float height = abs(y);
float depth = abs(z);

float blend = smoothstep(graMinheight, graMaxheight, height);
color baseRGB = mix(graMinBaseColor, graMaxBaseColor, blend);

float stripeSwitch = sin(s*2*M_PI*stripeFreq);
color stripeRGB = mix(baseRGB,stripeColor,stripeMix*stripeSwitch*blend);

//voronoi noise
float d = voronoi(P, spacename, vorCellfreq, vorJitter);
float resultF = 1 - smoothstep(vorRadius, vorRadius + vorBlur, d);
color voronoiColor = mix(stripeRGB, vorPatcolor, vorMix*resultF);
// vfbm noise
point PP = transform(spacename,P);
vector fbmNoise = vfBm(PP*fbmFreq, fbmFiltwidth,fbmOctaves, fbmLacunarity, fbmGain);
float fbmFillter = fbmNoise[1];
resultRGB = mix(voronoiColor,fbmColor,fbmMix*fbmFillter);


}
__________________________________________________________________________________________
P.S. Also planning to use Voronoi Noise creating ambient occlusion and roughness
tried to make it looks translucent, but RenderMan can't use translucent yet. I've considered using PxrDisney to create the effect of specular and translucent. But I think I should write shader by myself rather than use exists shaders. I'm planning to learn light and shadow in the future.
__________________________________________________________________________________________
Step2. Setting models and light

After the "expert section", I learned more features of Renderman and PxrSurface. So I start to add more things in my grape not only the base color.

I used a clear coat to make a feel of thin.


And a little bit glass refraction and reflection to make my grape looks organic and translucent.

Here are my shading nodes.

Base color Image:


Final render Image:

评论

此博客中的热门博文

Moon Island --- Final Project of Rendering and Shading class

Walkway and Temple Generater Tool

Assignment04 Rebuild Mark Twain's House