RenderMan & RISpec >> Problem writing a shader function

by Manuel » Sun, 16 Apr 2006 18:37:53 GMT

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

RenderMan & RISpec >> Problem writing a shader function

by Przemyslaw Koprowski » Mon, 17 Apr 2006 03:08:56 GMT



I don't have time to fully analyze the code, but the first think that
strikes me is that you are using s,t variables in the function without
declaring them! They are prefined in the shaders but not in the
function called from the shaders! Hence you should at least add
an extern declaration of them into the function.

Przemek

--
"Beauty is the first test: there is no permanent place
in the world for ugly mathematics." G.H. Hardy

RenderMan & RISpec >> Problem writing a shader function

by Manuel » Tue, 18 Apr 2006 07:02:07 GMT


This was the error!
Declaring s,t, it work.

Thanks!

Manuel

Similar Threads

1. write depth buffer from depth map in pixel shader

Hi evry one,

I m trying to write from a rectangular depth texture to the depth
buffer in a pixel shader. To so saw I draw in Opengl a quad of the
size of the screen with the corresponding texture coordinates. Then in
a shader I perform a texture lookup in my depth map at the position of
the pixel to get its depth and then I return that depth which would
write into the depth buffer (I verified my opengl states and the depth
mask is true). When I try to do so it seems not to work. My problem is
I don't understand what I am supposed to put in my OUT.depth because
the texRECT returns a float4 when I perform a texture lookup (what is
the format of result of texRECT with a depth map??? is it (D,D,D,1)
???). I use a 24bit depth map which is correct because I use it
elsewhere in my program.

When I try to display the depth map in the frame buffer to debug I
only get few pixels at 0 and the rest at 1. What do I do wrong

Here is my code :

Code:

struct fragment_out
{
   float4 color   : COLOR;
   float depth : DEPTH;
};

struct fragment_in
{
   float4 color   : COLOR;
   float4 position : WPOS;
};

fragment_out main(fragment_in IN,
                  uniform samplerRECT samplerZ,
                  uniform samplerRECT samplerColor)
{
   fragment_out OUT;   
   
   float4 res      = texRECT(samplerZ,IN.position.xy);
   float4 rescolor = texRECT(samplerColor,IN.position.xy); //just to
have the color of the pixel (no use for writting in the depth buffer)
 
  OUT.depth = res.r; // What should I put ( res = (D,D,D,1) ???)
   
   //OUT.color=rescolor; // for a correct color
   
   OUT.color[0]=res.r // to debug ....
   OUT.color[1]=0.0;
   OUT.color[2]=0.0;
   OUT.color[3]=1.0;
   return OUT;
}

2. question about the arguments in shader function

3. shader input semantics and function D3DXGetShaderInputSemantics

1) I can get shader input semantics from function
D3DXGetShaderInputSemantics. It will be useful to get type too, because I
don't know what format for example normal has, float3 or ubyte4? If the type
is known I can prepare data for this type dynamically. My question is: can I
get types and semantics together from shaders?

2) How can I get size of resources? (textures)

Thank you!


4. shader: function step working wrong?

5. how to organize multiple functions in a GLSL shader program

Hi all,

I am writing a fragment shader program. There are several sub-
functions and a main function. One of the sub-functions uses the
'uniform' variables. My problem is how to organize these functions
properly in grammar, and whether the use of uniform variables is
correct in my following program. If not, how to use the uniform
varibales in this case? My program structure is like follows:

/////////////////////////////////////////////////
uniform sampler2D tex;
uniform vec2 size;

void func1()
{
...
}

void func2()
{
...
// uniform variables are used here
a[0] = size[0];
a[1] = size[1];
 vec2 hi = texture2D( tex, pos).ra
....
}

void main()
{
...
func1();
func2();
...
}
/////////////////////////////////////////////////

Thanks,

J.

6. BMP-Threshold-8bit-->2 bit-problem-image writing

7. Problems with 'fast write on' on KT3 Ultra 2 with PowerColor 9800 pro

Hi

When 'fast write' is enabled in bios graphics get a bit corrupt in win
(xp) and in games. the mousepointer is for instance covered with black
stripes and icons on the desktop are weird. latest catalyst 3.8
installed, directx 9.0b, via 4.49. nothing is overclocked. my mobo
supports 4x agp. is that the problem?

any suggestions anyone?

thnx

8. Problem on writing a custom list view component