Jump to content

Declaration of variables


Stremik

Recommended Posts

Would someone please explain why some of the variables are being declared in "header" part of the shader/operator

Lambert(
                            vector amb=1;
                            vector diff={0.545, 0.525, 0.306};
)

while others in "body" part

{
              vector nml;
              
              nml = frontface(normalize(N),I);
              Cf = amb * ambient()+diffuse(nml);
              Cf*=diff;
}

Is it important at all? If yes, what is the pattern,the rules?

Thanks in advance!

Link to comment
Share on other sites

Would someone please explain why some of the variables are being declared in "header" part of the shader/operator

Lambert(
							vector amb=1;
							vector diff={0.545, 0.525, 0.306};
)

while others in "body" part

{
			  vector nml;

			  nml = frontface(normalize(N),I);
			  Cf = amb * ambient()+diffuse(nml);
			  Cf*=diff;
}

Is it important at all? If yes, what is the pattern,the rules?

Thanks in advance!

Hi Stemik,

The first one, Lambert (vector amb, vector diff ) is the shader parameter. THe reason you have, say, vector amb = 1, is that this will set a default value to amb, which is 1, if the user did not specify any value for the variable amb. In your SHOP editor, the parameters that you can play with are those you declared inside the ().

As for the stuff inside the {} bracket, these are the shading language. The variable from inside the Lambert() can be passed down into the shading language. Here is where the real shader writing takes place, which is totally beyond me. :blink:

ANyhow, does that helps a little?

Link to comment
Share on other sites

Ok. Let me see if I get it right.

The "header" part of the shader/operator is where I declare variables to which I attach the "hint" , "label" etc. pragmas for further modification of values of those variables(through slides,input fields...) during Houdini session.

The variables that are declared in the "body" of the shader/operator

cannot(or can they?) be attached to any pragamas, hence will not show up in any of shader's/operator's parameters tab.

Is that right?

Link to comment
Share on other sites

The "header" part of the shader/operator is where I declare variables to which I attach the "hint" , "label" etc. pragmas for further modification of values of those variables(through slides,input fields...) during Houdini session.

Well, attaching the hints, labels, etc are done in the body section, not the headers. The header, Lambert(Type Variable), is more of just a parameter. For a regular user who don't write shaders, the parameter is just like a bridge that allows users to change the values within within the shader.

When you declare the variables in the header - a.k.a the parameter - you're essentially declaring the variable.

The value of the parameter from the header then passed down into the the body of the shader.

Take a look at this simple C-like example:

[example]

My_function(float User_Input1, float User_Input2) //Parameter variable declaration

{

//another variable declaration, which means here, Buffer is a string.

string Buffer;

//Here is where action takes place

if(User_Input2 > User_Input1)

Buffer = "Input 2 is greater than Input1";

else

Buffer = "Input 1 is greater than Input 2";

return Buffer;

}

[/example]

Does that help a bit?

[ack... there goes my English... my hand never really follows my brain... or is it the other way around... :wacko: ]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...