Making holes in geometry using Alpha Maps

   10934   8   2
User Avatar
Member
133 posts
Joined: July 2005
Offline
I'm trying to makes some holes in my geometry. Some of these shapes may be a bit complex; and, as I am using polygonal models, the Cookie SOP creates triangles out of my polygons.

I was wondering if there was an easier way to do this using Alpha Maps?

Otherwise, does anyone have suggestions as to how to do this?

Thanks!
Frankie
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
154 posts
Joined: July 2005
Offline
hey fxrod

what i think might work is
after ur poly,
add a point sop
then under color, have add color

then for each color use the “tex” feature
ie.
tex (“Ework/avril.bmp”, $BBX, $BBY, r)

use exhelp to check out the syntax

then use a delete sop

with delete by expression
expression being : point (“../point1”, $PT, “Cd” , 1) > .5

and the .5 is ur threshold

it works for me, but ur geometry count is gonna have to be quite high.
i ran a subdivide after a fairly high grid to start, and te results were ok.

is there any reason why u cant use an opcacity map?

all the best
brian
User Avatar
Staff
2675 posts
Joined: July 2005
Offline
fxrod
I'm trying to makes some holes in my geometry. Some of these shapes may be a bit complex; and, as I am using polygonal models, the Cookie SOP creates triangles out of my polygons.

I was wondering if there was an easier way to do this using Alpha Maps?

Otherwise, does anyone have suggestions as to how to do this?

Thanks!
Frankie

If you can get good texture coordinates on your geometry, then you should be able to have a shader which does something like:


surface
generateHoles(…)
{
vector4 mapclr;

// Compute normal shading.

// At the conclusion of the normal shading:
// Cf should have the surface color
// Of should have the surface opacity
// Af should have the surface alpha

mapclr = texture(“holemap.rat”, u, v);

// Now, blend between the computed surface color and a fully
// transparent, colorless surface based on the map alpha.
Cf = lerp({0,0,0}, Cf, mapclr.a);
Of = lerp({0,0,0}, Of, mapclr.a);
Af = lerp(0, Af, mapclr.a);
}


This will “eliminate” the surface from areas where the alpha of the map is 0. You will also get nice anti-aliasing since the alpha will perform fractional blends of the surface color and total transparency.

This same technique can obviously be extended to blend any two materials, rather than just a fully transparent, colorless material.

As well, you can use any channel of the texture map, though alpha makes more intuitive sense.
User Avatar
Member
2199 posts
Joined: July 2005
Offline
You can of course just use a point sop to add Alpha of zero to any parts you want transparent. You'll need to modify any shaders you use to pick this up ( the Houdini default shaders don't ) But it's easy enough just add the following couple of lines and recompile.

Say your shader code looks like this:

surface
foo ( vector diff = {1,1,0};
vector amb = 0;
//the rest of your shader parameters….
)
{
.
.
.

//normal shader code

Cf = final colour;

}


just add a float called Alpha to your surface parameters
and at the bottom multiply Cf by Alpha and set Of equal to Alpha


so….

surface
foo ( vector diff = {1,1,0};
vector amb = 0;
//the rest of your shader parameters….
float Alpha = 1;
)
{
.
.
.

//normal shader code

Cf = final colour;
Cf *= Alpha;
Of = Alpha;
}

Hope this helps….
The trick is finding just the right hammer for every screw
User Avatar
Member
133 posts
Joined: July 2005
Offline
Thanks for everyone's help!

Brian, I tried generating the holes using the point SOP as you suggested. However, this requires some really high subdivision to get the holes to be clearly defined. You mentioned opacity maps… is this possible without writing shaders?

I'm new to writing shaders. Could someone please go into a little more detail in explaining the shader code that has been discussed?

I'm wondering where in Houdini you would write this code and recompile.

Thanks,
Frankie
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
2199 posts
Joined: July 2005
Offline
It's not too hard if you don't mind getting your hands a little bit dirty.
You can basically modify any of the shaders that come with Houdini without having to start from scratch. Or you can use VOPs to write your own. Here's how to modify existing ones.

1. Go to a shader pane and RMB on the shader you want to change.
2. Select “Operator Type Manager…” A floating window should appear, which is the operator type manager.
3. The shader should be highlighted, RMB on the shader in the operator manager and select “Copy”
This will create a copy of the code that you can change without loosing the original in case it all goes wrong.
4. Keep the default $HOME/houdini6.5/otls/OPcustom.otl as the path and click accept.
5. You will get a warning saying the shader name is already in use, don't worry about this just click ok. This will replace the shader in Houdini with your new copy.
6. Back in the normal Houdini ui RMB on the shader again and select “Type Properties”
This should bring up a window where you can edit the shader.
7. Go to the VEX code tab of this new window and scroll to the bottom,
the very last line should just be a “}”, on the line before insert the following two lines. NOTE: make sure Alpha is spelt with an uppercase “A”

Cf *= Alpha;
Of *= Alpha;

8. Scroll up some more until you get to a couple of lines that say something like

shader
decal ( vector amb = 1;
.
.
.
etc

insert a line that says

float Alpha = 1;

so now you should have

shader
decal ( float Alpha = 1;
vector amb = 1;
.
.
.
.
etc

9. In the bottom left hand corner of the window there is a button called “Test Compile”, press it and with luck it should say the compile was successful, if it does the press “ok” and then click “Accept” on the type manager window (also on the bottom left )
10. If the compile wasn't successful post what the dialog says and I'll try and let you know what went wrong.

You should now be able to add a point sop with Alpha in it to your geometry and the shader should pick it up. Setting a group of points to have an Alpha of zero will make them completely transparent.
The trick is finding just the right hammer for every screw
User Avatar
Member
133 posts
Joined: July 2005
Offline
Hi Simon:

I modified a VEX Decal Shader with the code you suggested and this is what it looks like:

surface
decal( float Alpha = 1;
vector amb = 1;
vector diff = .8;
vector spec = .8;
float rough = .1;

string map = “”; // Name of the map
string uwrap = “decal”, vwrap = “decal”;

vector uv=0; // Texture coordinates
)
{
float ss, tt;
vector dclr;
vector4 mapclr;
vector nn;

dclr = diff;
if (map != “”)
{
if (isbound(“uv”))
{
ss = uv.x;
tt = uv.y;
}
else
{
ss = s;
tt = t;
}
mapclr = texture(map, ss, tt, “uwrap”, uwrap, “vwrap”, vwrap);
dclr *= (1 - mapclr.a); // Scale the original color
dclr += mapclr; // Assume that the map is pre-filtered
}
nn = frontface(normalize(N), I);
Cf = (ambient()*amb + diffuse(nn))*dclr;
Cf += specular(nn, -normalize(I), rough)*spec;
Cf *= Alpha;
Of = Alpha;
}

I imported a .tiff, which includes an alpha channel, into the modified shader.

Then, in SOPs, I have a simple network.
Sphere -> Point -> UV Texture -> Shader

I set the Point SOP to Add Alpha, but this doesn't seem to work. I see the holes in the viewport Open GL as a result of the .tiff's alpha, but it doesn't seem to actually create holes in the geometry nor does it render with holes.

Thoughts?

BTW: Thank you very much for your time
-Frankie
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
User Avatar
Member
2199 posts
Joined: July 2005
Offline
Ah yes, you won't see holes unless you render, that's the point, it's a rendering solution. If you want real physical holes try using polysplit and then blasting out the bits you don't want.
Also, just adding a point sop which adds alpha won't do anything. Put a point range into the point sop, select add Alpha and then delete the channel that appears. By default it will say $Alpha. Then make the Alpha 0. This should make the points you select disappear in the render with a nice soft edge.
Don't use a .tiff with Alpha in to start with as this will just confuse the issue.
The trick is finding just the right hammer for every screw
User Avatar
Member
133 posts
Joined: July 2005
Offline
I've been reading the DIGITAL LIGHTING & RENDERING book and they had an example of what I was looking for. The terminology they use for it is clip mapping or visibility mapping. Turns out I wasn't explaining myself correctly.

Anyways, I created a VOP network that allows you to create a clip map. It also allows you to add a lighting model to the image.


http://us.f2.yahoofs.com/bc/414502b9_503a/bc/houdini/clip_shader.hip.hip?BCFSiRBBZd4ojYPX [us.f2.yahoofs.com]

Do a test render at object level to see how this works.

Best!
Frankie
Francisco Rodriguez
Effects Animator | Walt Disney Animation Studios
  • Quick Links