This don't work (as expected):
---------------------------------
float veinPattern()
{
float pattern1 = 0;
float i1, newturb1, newdisp1;
float vein1 = 1;
float freq1 = 25;
for (i1 = 1; (i1 <= 4) && (vein1 > .1); i1 += 1)
{
newturb1 = 1 - abs(2 * noise((s + 1)* freq1, (t + 1)* freq1) - 1);
newdisp1 = pow (smoothstep (.7, 1, newturb1), 10);
pattern1 += (1-pattern1) * newdisp1 * smoothstep (.1, 0.6, vein1
* vein1);
vein1 *= newturb1;
freq1 *= 2;
}
return pattern1;
}
surface
veins (float Ka = .75, Kd = 0.75, Ks = 0.4, roughness = 0.1;
color eyeballcolor = color(1,1,1);
color bloodcolor = color(.8,.05,.05);
)
{
color Cball;
float veins_type1 = veinPattern();
Cball = mix (eyeballcolor, bloodcolor, smoothstep(0,.75,veins_type1));
Ci = Cball;
}
---------------------------------
While this work:
---------------------------------
surface
veins (float Ka = .75, Kd = 0.75, Ks = 0.4, roughness = 0.1;
color eyeballcolor = color(1,1,1);
color bloodcolor = color(.8,.05,.05);
)
{
color Cball;
float pattern1 = 0;
float i1, newturb1, newdisp1;
float vein1 = 1;
float freq1 = 25;
for (i1 = 1; (i1 <= 4) && (vein1 > .1); i1 += 1)
{
newturb1 = 1 - abs(2 * noise((s + 1)* freq1, (t + 1)* freq1) - 1);
newdisp1 = pow (smoothstep (.7, 1, newturb1), 10);
pattern1 += (1-pattern1) * newdisp1 * smoothstep (.1, 0.6, vein1
* vein1);
vein1 *= newturb1;
freq1 *= 2;
}
Cball = mix (eyeballcolor, bloodcolor, smoothstep(0,.75,pattern1));
Ci = Cball;
}
------------------------------------
It's exactely the same code (copy and paste), but not wrapped into a
function.
This is the rib I'm using:
-----------------------------------
FrameBegin 1
Display "simple.tif" "framebuffer" "rgb"
Display "+simple.tif" "file" "rgba"
Format 640 480 -1
ShadingRate 1
Projection "perspective" "fov" [30]
FrameAspectRatio 1.33
Identity
# Default distant headlight
LightSource "distantlight" 1 "intensity" 0.5
# Camera transformation
Translate 0 0 5
WorldBegin
Identity
AttributeBegin
Color [1.0 0.6 0.0] # A nice orange color
# Displacement bounds, important for correct rendering
Attribute "displacementbound" "float sphere" [0.1] "coordinatesystem"
["shader"]
Surface "veins"
TransformBegin
Rotate 90 1 0 0 # Make +z point "up", the default camera
coordinte system has +y up,
Sphere 1 -1 1 360 # but this Sphere primitive has its poles on the
z axis.
TransformEnd
AttributeEnd
WorldEnd
FrameEnd
----------------------------------------------
Thanks,
Manuel