Closed DanielArnett closed 4 years ago
It turns out I successfully added transparency earlier, but that the ROS image viewer ignores the alpha channel. I just had to change CV_8UC3 to CV_8UC4, and GL_BGR to GL_BGRA.
For some reason though now when I pass an image topic with transparency into the node, I believe OpenGL doesn't recognize the transparency channel.
Thank you for using my code!
I think your change would work for alpha channel, but my current shader code does not take in account alpha channel for now. https://github.com/DanielArnett/opengl_ros/blob/7f1bebe2f990af0070322c3f1a51c57c06afadbd/opengl_ros/shader/fs_color_extraction.glsl#L66
Have you tried to change this line? I am out now, but i think i can test the code when i am back.
Yes, I have gotten the shader to publish transparent images, however when I finished experimenting I could not get it to read transparent inputs to the shader. I will create a simple test so I can show you.
And thank you for making such a wonderful node! It's so fast and easy to use!
I got the transparency fully working. The last thing I need to do to complete my project is to upload a second texture to the shader. Do you know how I can do this?
You can see in the below image I am creating two image topics with transparency. The image on the right is where I'm trying to blend the two images. This is where I'm trying to upload a second texture in the code, but I'm clearly not doing it the right way.
If you want to try it you can check out the image_blending
branch of my code and run roslaunch opengl_ros transparency_test.launch
.
Thank you for providing the code! and its nice to hear that alpha channel successfuly goes through to the shader!
For handling a second texture in the shader, you may need to
add another texture object for the second texture https://github.com/DanielArnett/opengl_ros/blob/4381df96a7b9b81e8eea7fe05e1e255bf76c259e/opengl_ros_lib/src/simple_renderer.cpp#L46
bind a sampler to the texture unit (the index number should be the same to layer value in AddTexture function); you can bind one sampler to two texture units, so you do not need to create another one. https://github.com/DanielArnett/opengl_ros/blob/4381df96a7b9b81e8eea7fe05e1e255bf76c259e/opengl_ros_lib/src/simple_renderer.cpp#L173
set the layer index of the unit to the shader uniform variable https://github.com/DanielArnett/opengl_ros/blob/4381df96a7b9b81e8eea7fe05e1e255bf76c259e/opengl_ros_lib/src/simple_renderer.cpp#L139
Cheers!
It's working! Thank you so much! I have a bug where it crashes every 2nd or 3rd time I run it, but I can debug that. Thank you for your help with OpenGL, this will really help me develop shaders for computer vision.
If anyone stumbles across this here is the commit with blending.
Hello, I'd like to add transparency to the images I publish from this node. How can I make that change?
Thank you!