Jump to content
  • Advertisement
Sign in to follow this  

Alpha blending with Cg shaders

This topic is 3531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to use alpha blending in my Cg shaders. This is my code in the application:

	// Test alpha blending.
	render_plane(-3, 0,2, 0, 0,0, 1, 10);

        // Render transparent sphere.
		glScalef(2.0, 2.0, 2.0);
		glTranslatef(0.0, 0.0, 1.5);

	//--- Disable GL blending

I would like the sphere to be transparent so I can see the plane thats behind it. In the fragment program for the plane I set the color.a = 1.0 and in the fragment program for the sphere I set the color.a = 0.5. But the sphere is not transparent, what am I doing wrong?

Share this post

Link to post
Share on other sites
It works because of the equation from (Chapter 7 Blending, Antialiasing, and Fog):


when you use:

You use 100% of the source color, and 0% of the dstination color - and then the sphere - in your sample code - was wisible with the full color and the background was invisible.

If you dont want to bother we can assume that glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); is most common for blending :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!