Lighting 2-Computer Graphics-Lecture Notes, Study notes of Computer Graphics

Computer Graphics involves technology to accept, process, transform and present information in a visual form that also concerns with producing images and animations using a computer. This course teach how to make your own design in computer using OpenGl. This lecture includes: Clamping, Color, Values, Scaling, Values, Intensity, Graphics, Implicit, Pipline, Shading, Technology

Typology: Study notes

2011/2012

Uploaded on 08/04/2012

parnashi
parnashi 🇮🇳

4.4

(49)

71 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture No.24 Lighting II
Clamping Color Values
Now it's perfectly fine to end up with an oversaturated color and pass this result along to
the graphics engine. What happens in the pipeline is an implicit clamping of the color
values. Any value that's greater than one is clamped to one, and any less than zero are
clamped to zero. So this has the benefit of requiring no effort on the part of the shader
(technology that is being used today for lighting and shading supported by Graphics
hardware) writer. Though this may make the rendering engine happy, it probably isn't
what we want. Intuitively, we'd think that shining orange and green lights on a white
surface would yield a strong green result. But letting the hardware clamp eradicates any
predominant effect from the green light. Clamping is fast, but it tends to lose fidelity in
the scene, particularly in areas where we would want and expect subtle changes as the
light intensities interact, but end up with those interactions getting eradicated because the
differences are all getting clamped out by the graphics hardware.
Scaling Color Values by Intensity
Instead of clamping, we might want to scale the color by dividing by the largest color
value, thus scaling the rgb values into the [0,1] range. In the example from figure 1, the
final color values were [1.0,1.49,0.49] meaning our largest color value was the green, at
1.49. Using this approach, we divide each element by 1.49, yielding a scaled color of
[0.671,1.0,0.329]. Thus any values greater than one are scaled to one, while any other
values are also scaled by the same amount. This maintains the hue and saturation but
loses the intensity. This might not be acceptable because the contrast with other colors is
lost, since contrast perception is nonlinear and we're applying a linear scaling. By looking
at the three results, we can see the large difference between the resulting colors.
Figure 1: Adding colors can result in colors that are outside the displayable range.
Shifting Color Values to Maintain Saturation
One problem with clamping or scaling colors is that they get darker (lose saturation). An
alternative to scaling is to maintain saturation by shifting color values. This technique is
called clipping, and it's a bit more complicated than color scaling or clamping. The idea is
to create a gray-scale vector that runs along the black-white axis of the color cube that's
got the same brightness as the original color and then to draw a ray at right angles to this
vector that intersects (i.e., clips) the original color's vector. We need to check to make
sure that the grayscale vector is itself within the [0,1] range and then to check the sign of
the ray elements to see if the color elements need to be increased or decreased. As we are
probably wondering, this can result in adding in a color value that wasn't in the original
color, but this is a direct result of wanting to make sure that the overall brightness is the
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Lighting 2-Computer Graphics-Lecture Notes and more Study notes Computer Graphics in PDF only on Docsity!

Lecture No.24 Lighting II

Clamping Color Values

Now it's perfectly fine to end up with an oversaturated color and pass this result along to the graphics engine. What happens in the pipeline is an implicit clamping of the color values. Any value that's greater than one is clamped to one, and any less than zero are clamped to zero. So this has the benefit of requiring no effort on the part of the shader ( technology that is being used today for lighting and shading supported by Graphics hardware ) writer. Though this may make the rendering engine happy, it probably isn't what we want. Intuitively, we'd think that shining orange and green lights on a white surface would yield a strong green result. But letting the hardware clamp eradicates any predominant effect from the green light. Clamping is fast, but it tends to lose fidelity in the scene, particularly in areas where we would want and expect subtle changes as the light intensities interact, but end up with those interactions getting eradicated because the differences are all getting clamped out by the graphics hardware.

Scaling Color Values by Intensity Instead of clamping, we might want to scale the color by dividing by the largest color value, thus scaling the rgb values into the [0,1] range. In the example from figure 1, the final color values were [1.0,1.49,0.49] meaning our largest color value was the green, at 1.49. Using this approach, we divide each element by 1.49, yielding a scaled color of [0.671,1.0,0.329]. Thus any values greater than one are scaled to one, while any other values are also scaled by the same amount. This maintains the hue and saturation but loses the intensity. This might not be acceptable because the contrast with other colors is lost, since contrast perception is nonlinear and we're applying a linear scaling. By looking at the three results, we can see the large difference between the resulting colors.

Figure 1: Adding colors can result in colors that are outside the displayable range.

Shifting Color Values to Maintain Saturation

One problem with clamping or scaling colors is that they get darker (lose saturation). An alternative to scaling is to maintain saturation by shifting color values. This technique is called clipping, and it's a bit more complicated than color scaling or clamping. The idea is to create a gray-scale vector that runs along the black-white axis of the color cube that's got the same brightness as the original color and then to draw a ray at right angles to this vector that intersects (i.e., clips) the original color's vector. We need to check to make sure that the grayscale vector is itself within the [0,1] range and then to check the sign of the ray elements to see if the color elements need to be increased or decreased. As we are probably wondering, this can result in adding in a color value that wasn't in the original color, but this is a direct result of wanting to make sure that the overall brightness is the

docsity.com

same as the original color. And, of course, everything goes to hell in a handbasket if we've got overly bright colors, which leave we with decisions about how to nudge the gray-scale vector into the [0,1] range, since that means you can't achieve the input color's saturation value. Then we're back to clamping or scaling again.

ColorSpace Tool

The ColorSpace tool is a handy tool that we can use to interactively add two colors together to see the effects of the various strategies for handling oversaturated colors. We simply use the sliders to select the rgb color values for each color. The four displays in Figure 5 show the composite, unmodified values of the resulting color (with no color square) and the clamped, clipped, and scaled color rgb values along with a color square illustrating those color values.

Figure 2: The ColorSpace tool interface.

Negative Colors and Darklights

We may be wondering, if we can have color values greater than the range in intermediate calculations, can we have negative values? Yes, we can! They are called "darklights" after their description in an article [GLASSNER 1992] in Graphic Gems III. Since this is all just math until we pass it back to the graphics hardware, we can pretty much do anything we want, which is pretty much the idea behind programmable shaders ( technology used by today graphics hardware for lighting and shading )! Darklights are nothing more than lights in which one or more of the color values are negative. Thus instead of contributing to the overall lighting in a scene, we can specify a light that diminishes the overall lighting in a scene. Darklights are used to eliminate bright areas when we're happy with all the lighting in your scene except for an overly bright area. Darklights can also be used to affect a scene if we want to filter out a specific rgb color. If we wanted to get a night vision effect, we could use a darklight with negative red and blue values, for example, which would just leave the green channel.

docsity.com

In this equation, the destination blend factor is set to the source color itself. Also, since the source blend factor is set to zero, the left-hand side of the equation drops away and we are left with:

Code Example //This code will blend one image into the second

struct COLOR3{ BYTE b; BYTE g; BYTE r; };

//Assume the two bitmaps have the same size

COLOR3 *p1; //pointer to first bitmap; COLOR3 *p2; //pointer to Second bitmap;

int k=0;

now we compute the blending factor av.

float av=(float)(alpha&255)/255;// alphaValue in floating point

compute the new pixel by using the alpha blending formula.

for(int i=firstBMP.Height; i>0; i--) { for(int j=0; j<firstBMP.Width; j++) { get the red color p1->r =(BYTE)(( p1->r * (av))+ p2->r(1.0f-(av)) ); get the green color p1->g =(BYTE)(( p1->g * (av))+ p2->g(1.0f-(av)) ); get the blue color p1->b =(BYTE)(( p1->b * (av))+ p2->b*(1.0f-(av)) );

p1++; p2++; } }

send the new bitmap to display device

BlitData(displaydeviceContext, 0,0,firstImage.Width,firstImage.Height);

Following images shows the result of the above code.

docsity.com

Figure 3: First Image

Figure 4: Second Image

Figure 5: Blended image

docsity.com