Log in or register to post comments

Transparent textures

November 30, 2011 - 5:50am #1

Hi,

I m trying to get parts of my model appearing transparent.

I have the texture as a 1024 x 1024 24 bit PNG with some transparency on it.

I have added the following lines to my renderFrameQCAR method:


            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This does make the model transparent where it should be but it also makes the view that shows the camera appear black.

Any ideas?

Transparent textures

April 7, 2015 - 12:53pm #16

Hi AlessandroB,

I need to do just as you did with the cube, for Java. Please, I would like to help me how could you do? Please, thank you!

Mafda

Transparent textures

April 6, 2015 - 1:12pm #15

Hi Denmas,

I need to do just as you did with the cube, for Java. Please, I would like to help me how could you do?

Please, thank you!

Mafda

Transparent textures

May 25, 2013 - 9:13am #14

Glad to hear this is solved!

Transparent textures

May 25, 2013 - 6:36am #13

Hi AlessandroB, i think i have found where's my fault :D

My fault is when i flip vertically the texture. I used paint program to flip the transparant texture before. But when save the the fliped texture, texture hasn't transparant any more (i don't know why it happened). Because that, my object hasn't transparant.

So, i try to flip the texture with photoshop. And then, the texture still tranparent. :D (tadaaa !!!)

Now, my object has transparent. Maybe, this trick may be useful for others that have a problem like me. And thanks for your response AlessandroB :D

Warm Regards.

- denmas

AttachmentSize
Image icon SC20130525-201759.png540.95 KB

Transparent textures

May 24, 2013 - 1:18am #12

Hi, I cannot see the attached image...

 

EDIT:

now I can see the image.

But this is a genuine problem of OpenGL programming (nothing really about Vuforia per se).

I would recommend to read about handling transparency in OpenGL (as I said before)

Transparent textures

May 23, 2013 - 11:53pm #11

hemm AlessandroB ,

I mean, i want make my object like that attached image, whether to make such an object using method "Transparency Sorting" ?

So, can you help me to give a simple code to make my object like that image. :D

Thanks.

- denmas

AttachmentSize
Image icon unnamed.jpg60.76 KB

Transparent textures

May 22, 2013 - 8:57am #10

Hi, yes, it is possible to make both the cube and the sphere transparent, essentially you can use the same shader (with your custom alpha) for both the cube and the sphere rendering.

One issue however is that you need to render first the sphere (i.e. the object inside) and then the cube (i.e. the external object), otherwise you might get weird results due to the depth testing.

Rendering order is of crucial importance when rendering multiple transparent objects; if you are interested to dig more into this subject, you can read this article:

http://www.opengl.org/wiki/Transparency_Sorting

 

Transparent textures

May 22, 2013 - 1:04am #9

Hi AlessandroB, i'm happy now XD

I have combined the texture of the object with alpha value succesfully, by add this code in CubeShaders.h  :

gl_FragColor = vec4(texture2D(texSampler2D, texCoord).xyz, 0.5);

that code can combine the texture with alpha value, but i'm a bit hesitant. For my project, i have a cube object that has a sphere inside. I want to tranparanted that cube to make sphere visible. So, the cube is tranparant but sphere is not.

My question is, is it possible to make it ?

Warm Regards,

Thanks.

- denmas

Transparent textures

May 21, 2013 - 8:58pm #8

thanks AlessandroB, sorry i could just reply this post now. :D

I've been try your code to make transparant object. Yeah, your code have managed to create transparant object, but that's not what i mean. I want to combine the texture of the object with transparant value. So, texture what i want has been transparant. XD

I wanna ask you, is it possible AlessandroB ? Now i'm studying OpenGl programing to combine it, but still can't. do it :(

Warm Regards,

Thanks.

Transparent textures

May 18, 2013 - 5:02am #7

Hi,

in the shader code you can see a line starting with "gl_FragColor = .."

this is where the picsel color (and transparency) is set; to combine tecture color with some transparency you can just change the alpha component of the vec4 (note: the vec4 represents Red, Green, Blue and Alpha), for instance:

float opacity = 0.5; // for instance, half transparent

gl_FragColor = vec4(1.0, 0.5, 0.2, opacity) * texture2D(texSampler2D, texCoord);

For more advanced use cases, it is better to consult the OpenGL developer guide and learn a bit of Shader programming

Transparent textures

May 18, 2013 - 12:06am #6

Hi AlessandroB, thanks for a quick replies. :D

I have seen your suggest link : https://developer.vuforia.com/resources/dev-guide/enabling-lighting-effects and try to understanding the code mean. So, the function of CubeShader.h's file is for rendering the object what we want (like description from that link). And then, add the pixel color from texture image to the mesh.

To make transparent object, i have to combine the pixel color with transparent value and add it into the mesh, right ? but, i still confuse how to do that with OpenGl code. I'm still newbie in OpenGl programming :(

So, can you help me to give the example code that can make it ? or maybe you can give the instruction where i must modify the CubeShader.h.

Thanks before AlessandroB,

- denmas

Transparent textures

May 17, 2013 - 8:51am #5

Hi, things are a little bit more complex whn it comes to using OpenGL ES 2.0;

the samples use GLSL shaders for rendering (see for instance the file CubeShaders.h in the Image Targets sample);

the basic shaders provided with the samples are quite basic, as they simply determine the color of your model based on the color of the texture.

If you have some transparency in your model (expressed by your material), this will simply not be taken into account, unless you:

  1. write some code to parse your material file and extract the necessary information (e.g. transparency, diffuse color, specular, emissive)
  2. modify the shaders to use that information

We don't have a comprehensive tutorial for that, but this article might be of help:

https://developer.vuforia.com/resources/dev-guide/enabling-lighting-effects

 

Transparent textures

May 17, 2013 - 7:45am #4

Hello gary and everyone, maybe this is the old post but i have a same problem in here. :D

i was put the code like this post. i was enable that code :

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

after this QCAR::State state = QCAR::Renderer::getInstance().begin(); and I did this with glDisable(GL_BLEND); just before QCAR::Renderer::getInstance().end();

my 3d object still same, the object is not transparent. where's my fault ? Any special settings to make a transparent object in blender which is compatible with OpenGL? because i just made the object with enable the transparent and set the alpha parameter.

Thanks,

Warm Regards.

Re: Transparent textures

November 30, 2011 - 6:21am #3

That was the solution! I was enabling it after QCAR::State state = QCAR::Renderer::getInstance().begin(); but I was never turing it off again.

I did this with glDisable(GL_BLEND); just before QCAR::Renderer::getInstance().end();

Thanks :)

Re: Transparent textures

November 30, 2011 - 6:00am #2

Hi Gary,

Make sure that this is done after the QCAR::Renderer::getInstance().begin() otherwise you are interfering with QCAR's render of the camera view.

And do remember to switch it off at the end of your drawing code.

Log in or register to post comments