[REQ] Velvet Shader

Feature requests, bug reports and related discussion
Post Reply
8 posts • Page 1 of 1
easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

[REQ] Velvet Shader

Post by easyarchitect » Wed Sep 09, 2009 9:18 pm

Hi, I was playing around a Velvet Shader in GLSL derived from the Velvet Renderman Shader written by Stephen H. Westin (see attached file "SHW_velvet.zip"), maybe this can be used by Ono to add a Velvet like material to Indigo :wink:

P.S. I've attached the Paper written by Stephen H. Westin ("Stephen H. Westin.zip") and my GLSL Shader

Bye

GLSL Shader (Vertex):

Code: Select all

varying vec4 Ca;
varying vec4 Cd;
varying vec4 Cs;

varying vec4 V_eye;
varying vec4 L_eye;
varying vec4 N_eye;

void main(void)
{
  V_eye = gl_ModelViewMatrix * gl_Vertex;
  L_eye = (gl_ModelViewMatrix * gl_LightSource[0].position) - V_eye;
  N_eye = vec4(gl_NormalMatrix * gl_Normal, 1.0);

  gl_Position = gl_ProjectionMatrix * V_eye;
  V_eye = -V_eye;

  Ca = gl_FrontMaterial.ambient;
  Cd = gl_FrontMaterial.diffuse;
  Cs = gl_FrontMaterial.specular;
}
GLSL Shader (Fragment):

Code: Select all

varying vec4 Ca;
varying vec4 Cd;
varying vec4 Cs;

varying vec4 V_eye;
varying vec4 L_eye;
varying vec4 N_eye;

const float backscatter = 0.25;
const float edginess = 4.0;
const float sheen = 0.7;
const float roughness = 0.1;

void main(void)
{
  vec3 V = normalize(vec3(V_eye));
  vec3 L = -normalize(vec3(L_eye));
  vec3 N = normalize(vec3(N_eye));

  float diffuse = clamp(dot(L, N), 0.0, 1.0);

  float cosine = clamp(dot(L, V), 0.0, 1.0);
  float shiny = sheen * pow(cosine, 1/roughness) * backscatter;

  cosine = clamp(dot(N, V), 0.0, 1.0);
  float sine = sqrt(1.0 - cosine);
  shiny = shiny + sheen * pow(sine, edginess) * diffuse;

  gl_FragColor = Ca + (Cd*diffuse) + (Cs*shiny);
}
Attachments
Velvet.PNG
Velvet Sample
Velvet.PNG (64.11 KiB) Viewed 3973 times
Stephen H. Westin.zip
Stephen H. Westin Paper
(891.98 KiB) Downloaded 240 times
SHW_velvet.zip
Renderman Velvet Shader
(1.12 KiB) Downloaded 224 times
Last edited by easyarchitect on Wed Sep 09, 2009 10:17 pm, edited 2 times in total.

User avatar
OnoSendai
Developer
Posts: 6241
Joined: Sat May 20, 2006 6:16 pm
Location: Wellington, NZ
Contact:

Re: [REQ] Velvet Shader

Post by OnoSendai » Wed Sep 09, 2009 10:00 pm

Hi, I plan to do a bit of work on Indigo shader language (ISL) to allow for stuff like Velvet, thanks for the information!

easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

Re: [REQ] Velvet Shader

Post by easyarchitect » Wed Sep 09, 2009 10:08 pm

OnoSendai wrote:Hi, I plan to do a bit of work on Indigo shader language (ISL) to allow for stuff like Velvet, thanks for the information!
Hi Ono, I've modified the GLSL code in order to remove the "uniform" for Light's position..

Bye

User avatar
Zom-B
1st Place 100
Posts: 4700
Joined: Tue Jul 04, 2006 4:18 pm
Location: ´'`\_(ò_Ó)_/´'`
Contact:

Re: [REQ] Velvet Shader

Post by Zom-B » Wed Sep 09, 2009 10:55 pm

ISL updates are VERY welcome Ono :)

If they are also followed by some small tutorials just like here its even more awesome!!!
polygonmanufaktur.de

easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

Re: [REQ] Velvet Shader

Post by easyarchitect » Wed Sep 09, 2009 11:28 pm

OnoSendai wrote:Hi, I plan to do a bit of work on Indigo shader language (ISL) to allow for stuff like Velvet, thanks for the information!
Sorry but I've found a bug into GLSL Shader, now should be fine...
:oops:

GLSL Vertex Shader
varying vec4 Ca;
varying vec4 Cd;
varying vec4 Cs;

varying vec4 V_eye;
varying vec4 L_eye;
varying vec4 N_eye;

void main(void)
{
V_eye = gl_ModelViewMatrix * gl_Vertex;
L_eye = gl_LightSource[0].position - V_eye;
N_eye = vec4(gl_NormalMatrix * gl_Normal, 1.0);

gl_Position = gl_ProjectionMatrix * V_eye;
V_eye = -V_eye;

Ca = gl_FrontMaterial.ambient;
Cd = gl_FrontMaterial.diffuse;
Cs = gl_FrontMaterial.specular;
}
GLSL Fragment Shader
varying vec4 Ca;
varying vec4 Cd;
varying vec4 Cs;

varying vec4 V_eye;
varying vec4 L_eye;
varying vec4 N_eye;

const float backscatter = 0.25;
const float edginess = 4.0;
const float sheen = 0.7;
const float roughness = 0.1;

void main(void)
{
vec3 V = normalize(vec3(V_eye));
vec3 L = normalize(vec3(L_eye));
vec3 N = normalize(vec3(N_eye));

float diffuse = max(dot(L, N), 0.0);

float cosine = max(dot(L, V), 0.0);
float shiny = sheen * pow(cosine, 1.0 / roughness) * backscatter;

cosine = max(dot(N, V), 0.0);
float sine = sqrt(1.0 - cosine);
shiny = shiny + sheen * pow(sine, edginess) * diffuse;

gl_FragColor = Ca + (Cd*diffuse) + (Cs*shiny);
}
Attachments
Test velvet.jpg
Testing GLSL Velvet Shader
Test velvet.jpg (226.83 KiB) Viewed 3902 times

easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

Re: [REQ] Velvet Shader

Post by easyarchitect » Tue Sep 15, 2009 9:25 pm

Hi Ono, I've included this Shader into Povray, this is the result

When the ISL will permit these type of Shaders I'll try to port the Velvet Shader to Indigo :wink:

Bye
Attachments
Velvet sofa.jpg
Velvet sofa.jpg (292.39 KiB) Viewed 3831 times

easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

Re: [REQ] Velvet Shader

Post by easyarchitect » Tue Sep 15, 2009 9:29 pm

Here is the OpenGL Version (with Bump Mapping and Shadow Maps) :wink:
Attachments
Velvet OpenGL.jpg
Velvet OpenGL.jpg (291.8 KiB) Viewed 3828 times

easyarchitect
Posts: 47
Joined: Fri Jan 12, 2007 1:49 am

Re: [REQ] Velvet Shader

Post by easyarchitect » Wed Sep 16, 2009 2:36 am

Hi, I've created a video sequence (divx format) that shows the shader in action (frames rendered in OpenGL)

Please Ono.... :wink:

Bye
Attachments
Velvet Sofa mpeg4.zip
(4.3 MiB) Downloaded 218 times

Post Reply
8 posts • Page 1 of 1

Who is online

Users browsing this forum: No registered users and 54 guests