A phong ramp (car paint?) OSL shader for Cycles

A phong ramp closure has been available for quite some time in Blenders OSL implementation (see the commit log) but this hasn't been exposed as a shader node yet. That is quite simple to do and in this post I present a bare bones implementation of such a shader node

I don't know much about car paint shaders, may be the reflection color changes as well with the view angle and not just the diffuse color but this might be a start for people wanting to implement such a fancy shader. This shader might be useful as well to implement soap bubble irridescence in a different way. (you might want to check the dicussion on Blender Artists).

surface phong_ramp(
 float Exp = 1,

 color C1=color(1,0,0),
 color C2=color(.8,.2,0),
 color C3=color(.6,0.4,0),
 color C4=color(.4,0.4,0.2),
 color C5=color(.2,0.4,0.4),
 color C6=color(0,0.4,0.6),
 color C7=color(0,0.2,0.8),
 color C8=color(0,0,1),
 output closure color Cout = 0
 color colors[8] = {C1,C2,C3,C4,C5,C6,C7,C8};
 Cout = phong_ramp(N, Exp, colors);
As you can see, all there is to this code is transfering the input values to the arguments of the built-in function. The function takes an array of eight colors so we have created eight input color sockets. I admit that it lacks elegance but it works.

Example node setup

the sphere in the example image was created with the following node setup:

No comments:

Post a Comment