We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › transparent texture mapping
Page Index Toggle Pages: 1
transparent texture mapping (Read 4231 times)
transparent texture mapping
Nov 13th, 2006, 9:20pm
 
Is there a way to map an object with a transparent texture, preferably in P3D?  

So if the object is red, you can put a texture on it and yet still see the red color underneath.  

I think this can be done, but I can't seem to find docs on it.
Re: transparent texture mapping
Reply #1 - Nov 13th, 2006, 9:55pm
 
What you want (I think) is a white texture, with a mask, then use that with fill(255,0,0) and you'll get what you want.

So create a plain white image, a black&white image and try the following:

Code:
PImage tex;
void setup()
{
// size etc etc
tex=loadImage("white.jpg");
tex.mask(loadImage("mask.jpg"));
}

void draw()
{
fill(255,0,0);
beginShape(QUADS);
texture(tex);
vertex(10,10,0,0,0);
vertex(190,10,0,tex.width,0);
vertex(190,190,0,tex.width,tex.height);
vertex(10,190,0,0,tex.height);
endShape();
}


That should give you red parts of the quad visible, with transparent areas.
Re: transparent texture mapping
Reply #2 - Nov 13th, 2006, 10:39pm
 
Very cool.  Masking is a nice trick, I'm glad to know about.  I'll try that out for sure.

As far as the question, I was thinking more along the lines of  a texture with alpha, so I can have a variable/dynamic-colored object with a faint texure overlaid.

So maybe masking would work, if the mask can be greyscale instead of B&W.  (ie, a solid mask of color(128) would do what I need)
Re: transparent texture mapping
Reply #3 - Nov 13th, 2006, 11:48pm
 
The mask is actually greyscale, it's just an alpha channel for a texture (but has to be part of a texture, you can't just have the alpha on it's own, but that texture can be white, which will pick up wahtever fill() colour you use)
Re: transparent texture mapping
Reply #4 - Nov 14th, 2006, 12:21am
 
Awesome, thanks for the clarification.
Re: transparent texture mapping
Reply #5 - Nov 14th, 2006, 4:16am
 
fwiw, this is actually a bit inconsistent in the current implementation. you'll get different results based on the renderer, but the "proper" behavior in future releases will be:

1) fill() will be ignored for textured shapes,
2) textured images with ARGB will work properly (they're having trouble with createGraphics right now), and
3) tint() will control both the coloring, and alpha, of the texture image as it's applied to the surface.
Re: transparent texture mapping
Reply #6 - Nov 14th, 2006, 10:20pm
 
Cool.  That seems a little more intuitive (and powerful) to me.  Thanks for the inside info fry!
Re: transparent texture mapping
Reply #7 - Nov 27th, 2006, 9:14pm
 
OK...  So I have been messing around with this, but I still can't get the behavior I'm looking for.  

Using masks, I can only seem to create a transparent, textured object (like a glass box with printing on it).  But what I want is an opaque object, with a semi-transparent texture (like a solid plastic box with faded printing on it).

Am I missing something?
Re: transparent texture mapping
Reply #8 - Nov 27th, 2006, 10:32pm
 
2 possible ways of doing that... only 1 is fairly simple though.

1: have 2 boxes, one the base colour/texture, another very slightly larger, with the transparent texture (100% transparent for see through bits, some fraction transparent for visible parts). This will put a semi-transparent image "on" the box.

2: t the hard way is called multi-texturing, and isn't supported by processing natively, but you can do it by hand by creating a PImage for the base texture (solid box), the transparent texture, and a 3rd which is the 2 combined in the way you want. This is expensive in terms of cpu time if you're changing the image as you'll have to re-make the 3rd image each time either of the 2 originals change.

Actually there's a 3rd way, but it means hacking into processing's guts, and using OPENGL to do native multi-texturing, but it's overkill for your needs probably.
Re: transparent texture mapping
Reply #9 - Nov 27th, 2006, 11:02pm
 
Ah-ha!  Yeah, I thought of #1, which would effectively double the polys being drawn.  So I'll probably go the route of #2 for now, and just do it once at the beginning.

The functionality fry describes will be great, because it will allow for what I want: a single texture image to be used on-the-fly with different tints and alphas.  That way an object-class can contain a variable for color, and the texture can be applied & mixed with that dynamic color.

Page Index Toggle Pages: 1