Bloom is an effect that brightens the light areas in an image or in video games. It creates an illusion that makes bright lights seem brighter.
High Dynamic Range Rendering is the rendering of computer graphics scenes. This is a very good way to create realistic and pretty scenes in games or movies.
How are Bloom Shaders Effects used in video games????
In video games, Bloom shader effects are used many times. Games like The Legend of Zelda, Twilight Princess, and many others. Ico was one of the first video games to use bloom effects.
What do you need in order to perform bloom???
Well, in your vertex shader you will need all the necessary information to pass into the fragment shader. Things like: attributes, uniforms, and varyings. Because you are dealing with bloom you will also need ambient, diffuse, and specular lighting as well. In your void main(), you will want to state the gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex as well as your definitions of your variables which you listed as your attributes, uniforms, and varyings.Your fragment shader, is where you can do the fun stuff. This is where you can calculate the lights, colour, and the position and implement them into your program.
An example is given here.
void main ()
{
// vWorldNormal is interpolated when passed into the fragment shader.
// We need to renormalize the vector so that it stays at unit length.
vec3 normal = normalize(vWorldNormal);
vec3 colour = Material.Ambient;
for (int i = 0; i < 4; ++i)
{
if ( i >= NumLight )
break;
// Calculate diffuse term
vec3 lightVec = normalize(Light[i].Position - vWorldVertex.xyz);
float l = dot(normal, lightVec);
if ( l > 0.0 )
{
// Calculate spotlight effect
float spotlight = 1.0;
if ( Light[i].Type == 1 )
{
spotlight = max(-dot(lightVec, Light[i].Direction), 0.0);
float spotlightFade = clamp((Light[i].OuterCutoff - spotlight) / (Light[i].OuterCutoff - Light[i].InnerCutoff), 0.0, 1.0);
spotlight = pow(spotlight * spotlightFade, Light[i].Exponent);
}
// Calculate specular term
vec3 r = -normalize(reflect(lightVec, normal));
float s = pow(max(dot(r, vViewVec), 0.0), Material.Shininess);
// Calculate attenuation factor
float d = distance(vWorldVertex.xyz, Light[i].Position);
float a = 1.0 / (Light[i].Attenuation.x + (Light[i].Attenuation.y * d) + (Light[i].Attenuation.z * d * d));
// Add to colour
colour += ((Material.Diffuse.xyz * l) + (Material.Specular * s)) * Light[i].Colour * a * spotlight;
}
}
gl_FragColor = clamp(vec4(colour, Material.Diffuse.w), 0.0, 1.0);// * texture2D(Sample0, vUv);
}
When you are finished with all of that, you can get something like this.
No comments:
Post a Comment