PDA

View Full Version : Problem with MEL ocean script


Paddelli
10-22-2010, 10:42 PM
I've been trying to create a cg ocean using a greyscale map deforming a plane and was struggling to get particles to emit off the tops of the waves. So I went back to using an oceanshader and using the original script grabbed off another site, namely

vector $pos = particleShape1.position;

float $pu = $pos.x;
float $pv = $pos.z;

float $disp[] = `colorAtPoint -u $pu -v $pv oceanShader1`;
float $dispY = $disp[0];
float $height = .5;



if ($disp[0] > $height) {
particleShape1.position = <<$pos.x, $dispY, $pos.z>>;
particleShape1.lifespanPP=1;
}
else{
particleShape1.lifespanPP=0;

}


But it's still not working. I'm guessing the array should be filling with alpha values generated by the `colorAtPoint` command so 0-1 but its not I'm getting all kinds of numbers in there and particles are appearing even if they haven't passed the conidtions of the 'if' statement. Any help would be hugely appreciated I'm banging my head against the wall here.

Pad

mduvekot
10-25-2010, 02:05 AM
The code works, that's probably not where your problem is. You're running this as a runTime expression and the Lifespan Mode of the particleShape is lifespanPP only? Foam Emission on the oceanShader is nonZero?

Paddelli
10-26-2010, 12:04 AM
Sorry for the late response. My browser crashed as I was posting this thread so I didn't think it had worked. I posted more details here:

http://forums.cgsociety.org/showthread.php?f=86&t=929758

with a link to my scene file. I'm still having problems with referencing a file in the code. It seems that the file's UV position changes depending on what object I put the code on? So when the particles settle on the water it doesn't line up with the actual height deformation at that point. Is there any way you can reference a file as it appears on a plane? So that I know all of the deformations will be the same?

Thanks,
Pad

mduvekot
10-26-2010, 03:24 AM
I don't think I understand what you're asking. You're explaining things in a way that doesn't make sense to me.

I'm still having problems with referencing a file in the code. [QUOTE]

I don't know what that means. What code, the expression? You're not referencing a file there. In fact, you're not using referencing at all.

[QUOTE] It seems that the file's UV position changes depending on what object I put the code on?

Sorry. Files or (texture) file nodes don't have UVs and you can't "put code on an object".


So when the particles settle on the water it doesn't line up with the actual height deformation at that point.


I think I see that, yes.

Is there any way you can reference a file as it appears on a plane? So that I know all of the deformations will be the same?

I think what you're asking is how to relate the world space position of the particle to the UV coordinates of the file texture. The UVs have values between 0 and 1 and the emitter is probably larger than 1 unit and may not be positioned at precisely 0. You have to take the world space position of the particle subtract the translation of the emitting surface and then divide it by the width or height of the emitting surface to "normalize" the particle position.
You can do that as follows:

float $pu = $pos.x;
float $pv = $pos.z;

float $offsetU = 0.8; // center (in X) of bounding box of emitting surface
float $offsetV = 0.5; // center (in Z) of bounding box of emitting surface

float $scaleU = 5; // width of bounding box of emitting surface
float $scaleV = 5; // depth of bounding box of emitting surface

$pu -= $offsetU;
$pv -= $offsetV;

$pu /= $scaleU;
$pv /= $scaleV;

Paddelli
10-26-2010, 04:07 AM
Ah ok. Thanks for deciphering my ramblings. Instead of UVs I meant UV co-ordinates and by 'putting code on an object' I meant writing a creation / runtime after dynamics expression for the position of the particles and by referencing the file I meant calling the 'colorAtPoint' command to check and relay information from it. It's four in the morning here and I've been working for thirteen hours. My brain's not functioning too well. So for the two to line up automatically the emitter plane would have to be centered at 0,0,0 in world space and 1 unit square?

Thanks for your help.
P

Paddelli
10-28-2010, 05:05 PM
Quick last question. I added the code in to my expression but some of the $pv values were coming through as minus number so were sitting in negative v space and hitting the wrong point on the texture file. I added a conditional to say:

if ($pv <0){
$pv = $pv * (-1);
}

Does this seem right or have I done somethign wrong further up and this is a kind of fake fix?

CGTalk Moderation
10-28-2010, 05:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.