Jump to content

Surface that read Displacement?


TheAdmira1

Recommended Posts

im pretty new to VEX, so please dont mind my ignorance at the moment... basically I have a displacement I made in vex... i have several layers on the beak of a macaw that i need to be different surface colors... but honestly i dont even know where to start... i wrote a very similar set of PRman shaders last 1/4 however the actual functions that allow the surface to read the displacement do not exist in vfl? any help at all would be awesome! thanks!

Link to comment
Share on other sites

Ive been using the dimport... but it doesnt want to work? heres a shot of my surface shadeer and the hip file its in ( dnt mind the displacement, there are probably a whole bunch of parameter that i do not need, but im still learning and that is the only way i could get the texture was looking for) thanks again

SnyderGlenn_P1_ProjectFile.hip

post-3685-1233082837_thumb.jpg

post-3685-1233082914_thumb.jpg

post-3685-1233082921_thumb.jpg

Link to comment
Share on other sites

oh ya... and it swims like all hell if anyone can help with that as well id be more than appreciative...

You might need to double check how you're sending your uvs to the material. I could be just missing it, but I don't see them in there, which would explain the swimming.

Link to comment
Share on other sites

In your displacement shader you are most likely using P or position to place the noise on your geometry.

You are getting swimming because P is with respect to the camera.

You need to add a "rest" attribute to your geometry then use the Rest Position VOP to fetch the "rest" attribute.

The idea is to use the Rest SOP up the SOP chain where the geometry isn't deforming. There is nothing magical about the rest attribute. It is just a three float vector that grabs a snapshot of the current point position. You can verify this by looking at the spreadsheet through the Rest SOP and note that rest = P.

The rest position attribute remains unchanged as your geometry deforms. If your displacement shader pattern generator VOPs use "rest" instead of P, your procedural textures will "stick" quite nicely.

No worries if the geometry or Object Transforms.

This has come up often in the past so you may want to do a search on rest or swimming textures.

Note:

Rest really only applies to procedural patterns. If you are using texture maps or uv's then that is an entirely different method.

Tip:

You can use uv's instead of P in to your procedural pattern textures if you have decent uv's that is. It's much easier to use "rest" though. No stretching on your procedural patterns.

Link to comment
Share on other sites

thanks alot, im about to put the rest in...

as for the output displacement/ input shader... My prof, Malcolm Kesson, told me of a way that Stephen Regelous of massive showed him to distort normals in order to take the output/input relation out of the two... this allows you to disregard the differences in any language.. allowing you to do things like right your PRman displacement and never have to worry if your Houdini/Maya shaders will read the "height" difference for attributes like color or specular... (please dont mind all of the inline commentary... when I make a script that I know Ill need later, I like to give myself notes as to what exactly the script does)

code for PRman is a little something like this:

displacement
snyDisplace(float	  Km = 0.1,  // displacement magnitude
							  amplitude = 1.0, // multiplier for noise funct
							  freq = 1.0;
				  string	 space = "object" )
{

// in PRman you can either declare these variables at the beginning of your code 
// where I assume the rest of your variables are declared or directly above this function like so

float hump = 0,  // amount of displacement
	   cutOff = 0,  // cutoff for change in displacement
			  f = freq; // easier that writing out freq

normal n = normalize(N);   //normalize the normal to make it easier to use in the displacement equation
point	p = transform(space,P);   //lock the points to the "space" you wish to use

// once you normalize any vector, in the most basic terms, becomes a line  that is a single unit 
// long at the origin in the direction of the original vector 

// in this case, we are normalizing a normal, therefore it will be at an angle
// or direction, perpendicular micro-polygon it is associated with
// the normal is now referred to as a surface normal  
// this allows us to manipulate the attributes of them to our needs
// for this code it is the length

// using this code will first use a simple noise() function to displace the point P for each micro-polygon
// then it will change the length of the surface normal depending 
// on the amount of displacement per micro-polygon

hump = hump + (noise(p * f) - 0.5) * amplitude;   //general noise function for displacement

hump = hump + Km;   // calculates final displacement


P = P - n * hump  // recalculate the point P after the displacement
N = calculatenormal(P)   // just as it says, recalculate the normal at point P
			  }

// this if() statement reads the displacement (hump) then 
// changes the normals 
// note: this must be done after you recalculate the N at point P: (N = calculatenormal(P))

		if (hump > cutOff) {
			   N = normalize(N * 0.75);
		   else
			   N = normalize(N * 0.5);
			   }

for a .vfl in vex:

(template courtesy of Malcolm Kesson - Fundza.com / use cutter for scripting,

now supports .vfl and .ifd files so you can render you written shaders on a

surface directly in cuter without having to move back and forth from Houdini)

// must declare the variables at the beginning of your .vfl code

#pragma help	  "a template displacement shader"
#pragma hint 	Km 	float
#pragma label 	Km 	"Bump Height"
#pragma range	Km 	-1 1

#pragma hint 	cutOff 	float
#pragma label	cutOff "Color cut off"
#pragma range	cutOff 	0 1

displacement
bumpy (float Km = 0.1, 
				height = 0.5)

{
float hump = 0; // variable for displacement later

vector n = normalize(N);

// once you normalize any vector, in the most basic terms, the vector becomes a line  that is a single unit 
// long at the origin in the direction of the original vector 

// in this case, we are normalizing a normal, therefore it will be at an angle
// or direction, perpendicular micro-polygon it is associated with
// the normal is now referred to as a surface normal  
// this allows us to manipulate the attributes of them to our needs
// for this code it is the length

// using this code will first use a simple noise() function to displace the point P for each micro-polygon
// then it will change the length of the surface normal depending 
// on the amount of displacement per micro-polygon

hump = noise(P * 8); //general noise function for displacement

P = P - n * hump * Km; //calculate amount of displacement for point P
N = computenormal(P);  // just as it says, recalculate the normal at point P

// this if() statement reads the displacement (hump) then 
// changes the normals 
// note: this must be done after you recalculate the N at point P: (N = calculatenormal(P))

if(hump > height)
	N = normalize(N) * 0.75;
else
	N = normalize(N) * 0.5;
}

I hope this as helpful for others as it was for me...

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...