VRML program: a fancy snowman + snow falls

Demonstrated to show some fancy features of VRML, I wrote this one line by line, without any help from any fancy software

#VRML V2.0 utf8

# xiaoyuan suo
# vrml world

NavigationInfo {
type ["EXAMINE", "ANY" ]
headlight TRUE
}
Viewpoint {
position 0.0 0.0 10
description "Initial View"
}
Background {
skyColor 0.4 0.4 0.4
}
Inline {
url ["snow.wrl"]
} # end inline
Inline {
url ["human.wrl"]
} # end inline
Inline {
url ["moutain.wrl"]
} # end inline
Inline {
url ["readme.wrl"]
} # end inline


Sound {
source AudioClip {
loop TRUE # Loop forever
url "christischristmas.wma"
}
minFront 1000.0
maxFront 1000.0
minBack 1000.0
maxBack 1000.0

}

Group{
children[
DEF myLeftLight TimeSensor { loop TRUE cycleInterval 5 }

DEF Bulb SpotLight { location -40 10 30}

Shape { geometry Sphere { } }

ROUTE myLeftLight.fraction TO Bulb.intensity

DEF myRightLight TimeSensor { loop TRUE cycleInterval 5 }

DEF Bulb SpotLight { location 40 10 30}

Shape { geometry Sphere { } }

ROUTE myRightLight.fraction TO Bulb.intensity

SpotLight { location -40 10 30
intensity 0.75
color 1 0 0 }
SpotLight { location 40 10 30
intensity 0.75
color 0 1 0 }

Transform {
translation 0 0 0
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the ON shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oObjectPos : TEXCOORD0,
out float3 oNormal : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"

}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 1.0 1.0 1.0
field SFColor Kd 1.0 1.0 1.0
field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.2 0.2 0.2
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFFloat rho 0.7
field SFFloat E0 80
field SFFloat theta_i 30.0
field SFFloat theta_r 40.0

field SFFloat sigma 30.0
field SFFloat fir 25.0
field SFFloat fii 10.0

url "cg:
void main(in float4 position : TEXCOORD0, //in world space
in float3 normal : TEXCOORD1, //in world space
uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 rho,
uniform float3 E0,
uniform float3 theta_i,
uniform float3 theta_r,

uniform float3 sigma,
uniform float3 fir,
uniform float3 fii,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{

float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
//float3 L = normalize(lightPosition - P);
//float diffuseLight = max(dot(N, L), 0);
//float3 diffuse = Kd * lightColor * diffuseLight;

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
float3 A = 1.0 - 0.5 * ((sigma*sigma)/((sigma*sigma)+0.33));
float3 B = 0.45 * ((sigma*sigma)/((sigma*sigma)+0.09));
float3 alpha = max(theta_i, theta_r);
float3 beta = min(theta_i, theta_r);
float3 temp1 = B*max(0, cos(fir-fii))*sin(alpha)*tan(beta);

float3 L = (rho/3.14)*E0*cos(theta_i)*(A+temp1);
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}
material Material {diffuseColor 1.0 0.2 0.3}
}
geometry Sphere { radius 1.0}

}
}
Transform {
translation 0 1.35 0
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the ON shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oObjectPos : TEXCOORD0,
out float3 oNormal : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"

}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 1.0 1.0 1.0
field SFColor Kd 1.0 1.0 1.0
field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.2 0.2 0.2
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFFloat rho 0.7
field SFFloat E0 80
field SFFloat theta_i 30.0
field SFFloat theta_r 40.0

field SFFloat sigma 30.0
field SFFloat fir 20.0
field SFFloat fii 10.0

url "cg:
void main(in float4 position : TEXCOORD0, //in world space
in float3 normal : TEXCOORD1, //in world space
uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 rho,
uniform float3 E0,
uniform float3 theta_i,
uniform float3 theta_r,

uniform float3 sigma,
uniform float3 fir,
uniform float3 fii,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{

float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
//float3 L = normalize(lightPosition - P);
//float diffuseLight = max(dot(N, L), 0);
//float3 diffuse = Kd * lightColor * diffuseLight;

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
float3 A = 1.0 - 0.5 * ((sigma*sigma)/((sigma*sigma)+0.33));
float3 B = 0.45 * ((sigma*sigma)/((sigma*sigma)+0.09));
float3 alpha = max(theta_i, theta_r);
float3 beta = min(theta_i, theta_r);
float3 temp1 = B*max(0, cos(fir-fii))*sin(alpha)*tan(beta);

float3 L = (rho/3.14)*E0*cos(theta_i)*(A+temp1);
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}
material Material {
diffuseColor 0.7294 0.1843 0.6588
ambientIntensity 1.0
specularColor 0 0 0
shininess 0.145
transparency 0
}
}
geometry Sphere { radius 0.5}

}
}
Transform {
translation 0 1.75 0
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the ON shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oObjectPos : TEXCOORD0,
out float3 oNormal : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"

}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 0.8 0.0 0.0
field SFColor Kd 0.8 0 0
field SFColor Ks 0.8 0 0
field SFTime phongN 100
field SFColor ambientLight 0.2 0.2 0.2
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFFloat rho 0.7
field SFFloat E0 80
field SFFloat theta_i 30.0
field SFFloat theta_r 40.0

field SFFloat sigma 30.0
field SFFloat fir 20.0
field SFFloat fii 10.0

url "cg:
void main(in float4 position : TEXCOORD0, //in world space
in float3 normal : TEXCOORD1, //in world space
uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 rho,
uniform float3 E0,
uniform float3 theta_i,
uniform float3 theta_r,

uniform float3 sigma,
uniform float3 fir,
uniform float3 fii,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{

float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
//float3 L = normalize(lightPosition - P);
//float diffuseLight = max(dot(N, L), 0);
//float3 diffuse = Kd * lightColor * diffuseLight;

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
float3 A = 1.0 - 0.5 * ((sigma*sigma)/((sigma*sigma)+0.33));
float3 B = 0.45 * ((sigma*sigma)/((sigma*sigma)+0.09));
float3 alpha = max(theta_i, theta_r);
float3 beta = min(theta_i, theta_r);
float3 temp1 = B*max(0, cos(fir-fii))*sin(alpha)*tan(beta);

float3 L = (rho/3.14)*E0*cos(theta_i)*(A+temp1);
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}
material Material {
diffuseColor 0.7294 0.1843 0.6588
ambientIntensity 1.0
specularColor 0 0 0
shininess 0.145
transparency 0
}
}
geometry Cylinder { height 0.01 radius 0.8 }


}
}


Transform {
translation 0 2.0 0
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the ON shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oObjectPos : TEXCOORD0,
out float3 oNormal : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"

}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 0.8 0.0 0.0
field SFColor Kd 0.8 0 0
field SFColor Ks 0.8 0 0
field SFTime phongN 100
field SFColor ambientLight 0.2 0.2 0.2
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFFloat rho 0.7
field SFFloat E0 80
field SFFloat theta_i 30.0
field SFFloat theta_r 40.0

field SFFloat sigma 30.0
field SFFloat fir 20.0
field SFFloat fii 10.0

url "cg:
void main(in float4 position : TEXCOORD0, //in world space
in float3 normal : TEXCOORD1, //in world space
uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 rho,
uniform float3 E0,
uniform float3 theta_i,
uniform float3 theta_r,

uniform float3 sigma,
uniform float3 fir,
uniform float3 fii,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{

float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
//float3 L = normalize(lightPosition - P);
//float diffuseLight = max(dot(N, L), 0);
//float3 diffuse = Kd * lightColor * diffuseLight;

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
float3 A = 1.0 - 0.5 * ((sigma*sigma)/((sigma*sigma)+0.33));
float3 B = 0.45 * ((sigma*sigma)/((sigma*sigma)+0.09));
float3 alpha = max(theta_i, theta_r);
float3 beta = min(theta_i, theta_r);
float3 temp1 = B*max(0, cos(fir-fii))*sin(alpha)*tan(beta);

float3 L = (rho/3.14)*E0*cos(theta_i)*(A+temp1);
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}
material Material {
diffuseColor 0.7294 0.1843 0.6588
ambientIntensity 1.0
specularColor 0 0 0
shininess 0.145
transparency 0
}
}
geometry Cylinder { height 0.5 radius 0.41 }


}
}


Transform {
translation 0 1.3 0.5
rotation 1 0 0 1.57
scale 0.2 0.8 0.2
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oObjectPos : TEXCOORD0,
out float3 oNormal : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 1 0.0 0.0
field SFColor Kd 1 0.0 0.0
field SFColor Ks 1 0.0 0.0
field SFTime phongN 100
field SFColor ambientLight 0.2 0.2 0.2
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15

url "cg:
void main(in float4 position : TEXCOORD0, //in world space
in float3 normal : TEXCOORD1, //in world space
uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{

float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight;

// compute the specular light contribution
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}
material Material {
diffuseColor 0.7294 0.1843 0.6588
ambientIntensity 1.0
specularColor 0 0 0
shininess 0.145
transparency 0
}

}

geometry Cone {
bottomRadius 0.5
height 1
}

}
}
DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 1 0 0, 0 1 0, 0 0 1 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation 2 -0.5 2

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 1.3
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor

DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 1 0 0, 0 1 0, 0 0 1 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation 2 0 2

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 1
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor
DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 1 0 0, 0 1 0, 0 0 1 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation 2 0.5 2

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 0.7
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor



Transform {
translation 0 -1 0
rotation 1 0 0 1.57
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float2 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float2 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT*5, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {
field SFColor Ka 1 1 1
field SFColor Kd 1 1 1
field SFColor Ks 1 1 1
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "snow.bmp" ]
}

url "cg:
const sampler2D texture0;

void main(in float2 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Ka, uniform float3 Kd, uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{


float3 P = position.xyz;
float3 N = normalize(normal);
float3 ambient = Ka * ambientLight; // ambient light contribution

//compute the diffuse light contribution
float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);
float3 diffuse = Kd * lightColor * diffuseLight * (0.3+0.7*tex2D(texture0,tex));

// compute the specular light contribution
float3 V = normalize(viewPosition - P);
float3 H = normalize(L + V);
float specularLight = pow(max(dot(N, H), 0), phongN);
if(diffuseLight <= 0)
specularLight = 0;
float3 specular = lightColor * specularLight;

oColor.xyz = (ambient + diffuse + specular);
oColor.w = 1.0;
}

"}

material Material {
diffuseColor 0 0 0
ambientIntensity 0.0
specularColor 0 0 0
shininess 0.0
transparency 0
}

}

geometry Box { size 40 40 0.01 }




}
}
DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 0 1 0, 0 0 1, 1 0 0 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation -3 0.5 7

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 1.3
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor

DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 0 1 0, 0 0 1, 1 0 0 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation -3 1 7

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 1
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor

DEF myColor ColorInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [ 0 1 0, 0 0 1, 1 0 0 ] # red, green, blue
}

DEF myClock TimeSensor {
cycleInterval 10.0 # 10 second animation
loop TRUE # infinitely cycling animation
}
Transform{
translation -3 1.5 7

children Shape {
appearance Appearance {
material DEF myMaterial Material { }
}
geometry Cone {
bottomRadius 0.7
height 1
}
}
}
ROUTE myClock.fraction_changed TO myColor.set_fraction
ROUTE myColor.value_changed TO myMaterial.set_diffuseColor

Transform {
translation 3 2 4
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}
geometry Cylinder { radius 0.06 height 6 }

}
}



Transform {
translation 6 2 4
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}
geometry Cylinder { radius 0.06 height 6 }

}
}
Transform {
translation 4.5 4.5 3.92
rotation 1 0 0 -1.57
rotation 0 0 1 -1.57
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}
geometry Cylinder { radius 0.06 height 3.5 }

}
}

Transform {
translation 4.5 0.5 3.92
rotation 1 0 0 -1.57
rotation 0 0 1 -1.57
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.2*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}
geometry Box {size 0.13 1.5 0.6}

}
}

Transform {
translation 4 2.6 4
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}

geometry Cylinder { radius 0.04 height 4.2 }
}
}

Transform {
translation 5 2.6 4
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}

geometry Cylinder { radius 0.04 height 4.2 }
}
}


DEF XForm Transform {
children [
Shape {
appearance DEF PhongLambertShader ShaderAppearance {
vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.6 0.4 0.15
field SFColor Kd2 0.27 0.2 0.07
#field SFColor Kd1 0.4 0.2 0.1
#field SFColor Kd2 0.8 0.4 0.2
field SFColor Kd3 0.18 0.13 0.05
field SFColor Kd4 0.44 0.3 0.11

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}

geometry Cylinder { radius 0.04 height 4.2 }
}
DEF Clicker TouchSensor {}

# Run once for 2 sec.
DEF TimeSource TimeSensor { cycleInterval 2.0 }

# Animate one full turn about Y axis:
DEF Animation OrientationInterpolator {
key [ 0, .33, .66, 1.0 ]
keyValue [ 0 1 0 0, 0 1 0 2.1, 0 1 0 4.2, 0 1 0 0 ]
}
]
}

ROUTE Clicker.touchTime TO TimeSource.startTime
ROUTE TimeSource.fraction_changed TO Animation.set_fraction
ROUTE Animation.value_changed TO XForm.rotation


Transform {
translation -3 -1 7
rotation 0 1 0 0.57
scale 0.4 0.2 0.4
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 0.75 0.67 0.754
field SFColor Kd2 0.875 0.867 0.55
field SFColor Kd3 0.23 0.66 0.8
field SFColor Kd4 0.672 0.773 0.656

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}

geometry Extrusion {
creaseAngle 1.57
endCap FALSE
solid FALSE
crossSection
[ #circle 1 0, 0.9135 -0.4067,
0.6691 -0.7431, 0.309 -0.9511,
-0.1045 -0.9945, -0.5 -0.866,
-0.809 -0.5878, -0.9781 -0.2079,
-0.9781 0.2079, -0.809 0.5878, -0.5 0.866,
-0.1045 0.9945, 0.309 0.9511, 0.6691 0.7431,
0.9135 0.4067, 1 0 ]
spine
[ # straight-line 0.0 0.0 0.0,
0.0 0.4 0.0, 0.0 0.8 0.0, 0.0 1.2 0.0,
0.0 1.6 0.0, 0.0 2.0 0.0, 0.0 2.4 0.0,
0.0 2.8 0.0, 0.0 3.2 0.0, 0.0 3.6 0.0,
0.0 4.0 0.0, 0.0 4.4 0.0, 0.0 4.8 0.0 ]
scale [ 1.2 1.2, 1.5 1.5, 1.8 1.8,
1.95 1.95, 2.0 2.0, 1.95 1.95, 1.8 1.8,
1.5 1.5, 1.2 1.2, 1.05 1.05, 1.0 1.0, 1.05 1.05,
1.15 1.15 ] }
}
}

Transform {
translation -3 2 7
children Shape {
appearance DEF PhongLambertShader ShaderAppearance {
# Vertext shader computes necessary transforms
# Fragment shader computes the Phong and Lambert shader terms

vertexShader DEF VertexSimple VertexShader {
url "cg:
void main(in float4 position : POSITION, //in object space
in float4 normal : NORMAL, //in object space
in float3 tex : TEXCOORD0,

//mandatory parameters
uniform float4x4 modelViewProjection,
uniform float4x4 model,
uniform float4x4 modelIT,
uniform float3 viewPosition,

//output parameters
out float4 oPosition : POSITION,
out float3 oTex : TEXCOORD0,
out float3 oObjectPos : TEXCOORD1,
out float3 oNormal : TEXCOORD2

)
{
oTex = tex; //texture coordinates
oPosition = mul(modelViewProjection, position); //position in projected coordinates

//transform the vertex position and normal into World Space:
oObjectPos = mul(model, position).xyz;
oNormal = mul(modelIT, normal).xyz;
}
"
}
fragmentShader DEF PhongLambertFragShader FragmentShader {

field SFColor Kd1 1 1 0.5
field SFColor Kd2 1 0.64 1
field SFColor Kd3 1 0.617 0.242
field SFColor Kd4 1 0.77 0.547

field SFColor Ks 0.7 0.7 0.7
field SFTime phongN 100
field SFColor ambientLight 0.4 0.4 0.4
field SFColor lightColor 1.0 1.0 1.0
field SFVec3f lightPosition 0 0 15
field SFNode texture0 ImageTexture {
url [ "noiseL8_32x32x32.dds" ]
}

url "cg:
const sampler3D texture0;

float3 Col (float w, float3 Kd1, float3 Kd2, float3 Kd3, float3 Kd4)
{
float3 Kd;
float x;

if (w < 0.10)
{ x = smoothstep(0.0, 0.10, w);
Kd = lerp(Kd4, Kd1, x);
}
else if (w < 0.20) Kd = Kd1;
else if (w < 0.30)
{ x = smoothstep(0.20, 0.30, w);
Kd = lerp(Kd1, Kd2, x);
}
else if (w < 0.4) Kd = Kd2;
else if (w < 0.5)
{ x = smoothstep(0.4, 0.5, w);
Kd = lerp(Kd2, Kd3, x);
}
else if (w < 0.7) Kd = Kd3;
else if (w < 0.8)
{ x = smoothstep(0.75, 0.8, w);
Kd = lerp(Kd3, Kd4, x);
}
else Kd = Kd4;
return Kd;
}



void main(in float3 tex : TEXCOORD0,
in float4 position : TEXCOORD1, //in world space
in float3 normal : TEXCOORD2, //in world space

uniform float3 viewPosition, //in world space
uniform float3 Kd1,
uniform float3 Kd2,
uniform float3 Kd3,
uniform float3 Kd4,
uniform float3 Ks,
uniform float phongN,
uniform float3 ambientLight,
uniform float3 lightColor,
uniform float3 lightPosition, //in world space
out float4 oColor : COLOR)
{



float3 P = position.xyz;
float3 N = normalize(normal);
float3 noise = tex3D(texture0,tex);
float pi = 3.14159;
float w = abs(P.x/0.2);
float snoise = 2 * tex3D(texture0, tex) - 1;
float frequency =4.0;
float noiseScale = 0.5;

//w = frac(frequency * P.z + noiseScale * snoise);
w = abs(sin(pi*(P.x + 0.5*(noise.x + noise.y+noise.z) + 1)));
//w = w + 0.8 * (0.5* noise.x + 0.5 * noise.y + 0.5*noise.z);
int ip;
w = modf(w, ip);
float3 Kd = Col (w, Kd1, Kd2, Kd3, Kd4);

float3 L = normalize(lightPosition - P);
float diffuseLight = max(dot(N, L), 0);

float3 diffuse = Kd * lightColor * (diffuseLight + ambientLight);

// compute the specular light contribution
//float3 V = normalize(viewPosition - P);
//float3 H = normalize(L + V);
//float specularLight = pow(max(dot(N, H), 0), phongN);
//if(diffuseLight <= 0)
// specularLight = 0;
//float3 specular = lightColor * specularLight;

oColor.xyz = (diffuse);
oColor.w = 1.0;
}

"}
}

geometry Sphere { radius 0.17 }
}
}

]
}


DEF SpinMe Transform {
children [
DEF B Transform {
translation 1.0 0.0 0.0
children [
Shape {
appearance Appearance { }
geometry Box { size 0.1 0.4 0.1 }
}
]
}
Transform { rotation 0.0 0.0 1.0 0.785 children USE B }
Transform { rotation 0.0 0.0 1.0 -0.785 children USE B }
Transform { rotation 0.0 0.0 1.0 1.571 children USE B }
Transform { rotation 0.0 0.0 1.0 -1.571 children USE B }
]
}
DEF Clock TimeSensor {
cycleInterval 0.03
loop TRUE
}
DEF Spinner OrientationInterpolator {
key [ 0.0, 0.5, 1.0 ]
keyValue [
0.0 0.0 1.0 0.0,
0.0 0.0 1.0 3.14,
0.0 0.0 1.0 6.28
]
}
ROUTE Clock.fraction_changed TO Spinner.set_fraction
ROUTE Spinner.value_changed TO SpinMe.set_rotation

DEF waterTransform Transform {
translation 0 -0.85 13

children [
DEF waterShape Shape {
appearance Appearance {
texture ImageTexture {
url "waterripples.jpg"
}

textureTransform DEF waterTextureTransform TextureTransform {
scale 10 10
}
}
geometry Box {size 40 .001 5}
}
]
}

DEF waterTimer TimeSensor {
cycleInterval 10
loop TRUE
}

DEF textureInterpolatorScript Script {
eventIn SFFloat currentFraction
eventOut SFVec2f new_translation
directOutput TRUE
url "javascript:
function currentFraction() {
new_translation = new SFVec2f(currentFraction, 0);
}
"
}

ROUTE waterTimer.fraction_changed TO textureInterpolatorScript.currentFraction
ROUTE textureInterpolatorScript.new_translation TO waterTextureTransform.set_translation