Technically speaking, I’m an artist.

DSO ShadeOp

For our first project, we were to create a DSO in C in order to extend RSL’s capabilities. More specifically, we generated a series of points along a surface. Based on these points, we were to generate curves which followed the normals of the object.

We then tried to manipulate the curves with noise values attached to two of the four points per curve. Unfortunately, my implementation of this did not go according to plan. I instead found myself with curves that would no longer follow the normals.

I intend to revisit this problem in the future to debug my code and find a feasible solution.

Here are some of my renders for the curve systems:

Short curves on surface-

Shading Rate: 1000-

Shading Rate: 10-

Shading Rate: 100-

Code Examples:

curvy_read.rib-

Option "searchpath" "shader" "@:../shaders"
Option "searchpath" "texture" "../textures"
Option "searchpath" "archive" "../archives:Cutter_Help/templates/Rib:custom_templates/Rib"

Display "curvey_read" "framebuffer" "rgb"
Format 427 240 1
Projection "perspective" "fov" 20
ShadingRate 1

#LightSource "distantlight" 1 "intensity" 1.5 "from" [0 0 0] "to" [0 0 1]

Translate  0 0 10
Rotate 60 1 0 1
Rotate 90  0 1 1
Scale 1 1 -1

#Imager "background" "background" [1 1 1] # Background color
WorldBegin
    TransformBegin
        LightSource "pointlight" 1 "intensity" 25 "from" [1 4 1]
    TransformEnd
    AttributeBegin
        #Color 0 0.3 0.35
        ReadArchive "./curves.rib"
        #Surface "Plastic"
        ReadArchive "../ribs/d20.rib"
    AttributeEnd
WorldEnd

curvytest.rib

Option "searchpath" "shader" "@:../shaders"
Option "searchpath" "texture" "../textures"
Option "searchpath" "archive" "../archives:Cutter_Help/templates/Rib:custom_templates/Rib"
Option "limits" "gridsize" 12

Display "curvey_test" "framebuffer" "rgb"
Format 427 240 1
Projection "perspective" "fov" 20
ShadingRate 50

#LightSource "distantlight" 1 "intensity" 1.5 "from" [0 0 0] "to" [0 0 1]

Translate  0 0 7
Rotate 60 1 0 1
Rotate 90  0 1 1
Scale 1 1 -1

#Imager "background" "background" [1 1 1] # Background color
WorldBegin
    TransformBegin
        LightSource "pointlight" 1 "intensity" 25 "from" [1 4 1]
    TransformEnd

    Attribute "dice" "rasterorient" [0]
    Attribute "cull" "backfacing" [0]
    Attribute "cull" "hidden" [0]
    Surface "curvey_test"
            "Kd" .08
            "bakename" ["./curves.rib"]

    AttributeBegin
        #Displacement "test" "Km" 0.1
        ReadArchive "../ribs/d20.rib"
        #Cone 0.75 0.75 360
    AttributeEnd
WorldEnd

curvy.c

#include <stdio.h>
#include "shadeop.h"

/*our local private variables go here*/
FILE *f = NULL;
SHADEOP_INIT(curvey_init){
    return NULL;
}

SHADEOP_CLEANUP(curvey_cleanup){
    if(f!=NULL){
        fflush(f);
        fclose(f);
    }
}

SHADEOP_TABLE(curvey) =
{
    { "float curvey (string, point, point, point, point, vector, float)", "", "curvey_cleanup" },
    { "float curvey (string, point, point, point, point, normal, float)", "", "curvey_cleanup" },
    {""}
};

SHADEOP(curvey){

    STRING_DESC *str = (STRING_DESC*)argv[1];
    float *p1 = (float *) argv[2],
          *p2 = (float *) argv[3],
          *p3 = (float *) argv[4],
          *p4 = (float *) argv[5],
          *n = (float *) argv[6];
    float *width = (float *) argv[7];
    //float *p2 = (float *) argv[2];
    //float *p3 = (float *) argv[2];
    //float *p4 = (float *) argv[2];
    //p2 = (p + (n * 0.5);
    //p3 = p + n + (0.8 * 0.5);
    //p4 = p + n + (0.8 * 1.0);
    if(f == NULL){
        f = fopen(str->s, "w");    // 'w' stands for "write a file."  if it can't find a file of that name, it will write one. if it can, it will destroy and overwrite it."
        fprintf(f, "# my second wacky rib\n");
        fprintf(f, "Basis \"bezier\" 3 \"bezier\" 3\n"); /*bezier, b-spline*/
    }

    fprintf(f, "Curves \"linear\" [2] \"nonperiodic\" \"P\" [ %1.3f %1.3f %1.3f %1.3f %1.3f %1.3f ]\n", p1[0], p1[1], p1[2], p4[0], p4[1], p4[2] );
    fprintf(f, "\"constantwidth\" [ 0.005 ]\n", width);
    return 0;
}

curvy_test.sl

/* Shader description goes here */
surface
curvey_test(float    Kd = .33,
                    Ks = .84,
                    Ka = .2,
                    roughness = .18,
                    Krand = 0.01,
                    lengthmod = 0.8,
                    width = 0.005;
            color surfcl1 = color(.35, .5, .35),
                  surfcl2 = color(.06, .18, .06);
            string bakename = "")
{
    color   surfcolor = 1;            /*(0, 0, 0.7)*/

    normal nn = normalize (N);
    point pp = nn + P,
          p1 = P,
          p4 = pp,
          p2 = p4,
          p3 = p4;
    vector V = normalize(-I);
    normal nf = faceforward(nn, I);
    color speccolor = Ks * specular(nf,V,roughness),
          ambientcolor = Ka * ambient();
    color first = (0.2, 0.4, 0.35);
    color second = (0.1, 0.2, 0.4);
    color ramp1 = mix(first, second, 0.5);

    nn = transform("world", nn);
    nn = nn * lengthmod;
    float x = (random()-0.5) * Krand;
    float y = (random()-0.5) * Krand;
    float z = (random()-0.5) * Krand;
    pp = point( xcomp(pp) + x,
                ycomp(pp) + y,
                zcomp(pp) + z );
    color diffcolor = Kd * diffuse(nf);
    color hsv = ctransform("rgb", "hsv", diffcolor);
    if(bakename != "")
        curvey(bakename, p1, p2, p3, p4, (nn), width);

    Oi = Os;
    Ci = Oi * (Cs * surfcolor * (ambientcolor + diffcolor) + speccolor*Ks*speccolor);

}