Wireframes in OSL

I was inspired by Haken’s video for their single “Earthrise” to write a shader which essentially acts as a Mix Shader using the wireframe of the geometry as the mix factor.

Throughout the video is random geometry around the performing members of the band, intercut with a larger city scene – all of which only have the wireframe shaded.

The video is here:

Some of the geometry have the faces transparent where you can see the geometry behind it, but not the wires on the backfaces of the geo itself. The city scenes however don’t have that same transparency element.

The shader I’ve written allows for both effects, and can be toggled based on whether a BSDF is plugged into the “FaceShader” parameter.

I combined it with an updated version of my iridescence shader from my last post to emulate the effect from the music video.
The result is below:

Result
earthrise_shader2
Nodes
high_res_wireframe_nodes

My shader is here:

#include "oslutil.h"

shader CW_Wireframe(    
    closure color WireShader = diffuse(N),
    closure color FaceShader = transparent(),
    float LineWidth = 1,    
    int BackFacing = 0,  // boolean
    output closure color BSDF = diffuse(N)

){
    // get the wireframe
    float Wires = wireframe("polygons", LineWidth, 1);
    
    // Pass the WireShader and show that when we're dealing with a point
    // on the geometry which is a part of the wireframe.
    closure color WireCi = WireShader * Wires;
    
    // When we're not dealing with a geometry point which is part of the wireframe
    // pass through the FaceShader (which by default is transparent).
    WireCi += FaceShader * (1-Wires);
    
    // If FaceShader is transparent, we're seeing the wires on the backfaces...
    // Do we want that? If so, all good. Otherwise, negate them.
    if (BackFacing < 1) {
        Ci = ( transparent() * backfacing()) + ( WireCi * (1 - backfacing()));
    } else {
        Ci = WireCi;
    }
    
    BSDF = Ci;
}