Jump to content

  • Log In with Google      Sign In   
  • Create Account


SPHERICAL

Member Since 04 Sep 2013
Offline Last Active Sep 09 2013 01:35 PM

Posts I've Made

In Topic: OpenGL Fade In/Out Effect

04 September 2013 - 12:55 PM

I made a fade in/out for a simple polygon that fades in and out, because of the variation of the Z coordinate of that polygon.

#version 330 core

in vec4 fragColor;

out vec4 finalColor;

in float zPos;

void main()
{
	vec4 color = fragColor;

	float partA = -1.0 * zPos;
	float partB = partA - 7.0;
	color.a = 1.0 - partB;

	finalColor = color;
}

zPos is always negative in my case, so in partA I make it a positive value, then in partB I decrease it by 7. The value in partB is used to get alpha value for the color of the polygon.

 

The initial value of zPos is -8.0, then it increases to -7.0. This is a fade in. Then the zPos from value -7.0 dereases again to -8.0. This way i get a fade out.

 

http://www.youtube.com/watch?v=o1PYnmTaWWs

 

In this video a recorded the game that uses this fragment shader for fading in/out the squares that are in background.

 

Hope this will help you to write the right shader for your problem. :)

 

P.S. Sorry for my english, if i made any mistakes.


PARTNERS