Download presentation
Presentation is loading. Please wait.
Published byΝαθαναήλ Αποστολίδης Modified over 6 years ago
1
blending blending textures reflection fog
2
blendRectangles1.cpp
3
Fragments color and depth information
destination - the pixel that is already on the screen source - the pixel that might be written to the screen
4
Recall with Blending OFF and Depth testing OFF
How does the computer decide if source pixel replaces the destination pixel?
5
Recall with Blending OFF and Depth testing OFF
source pixel replaces destination pixel always
6
Recall with Blending OFF and Depth testing ON
How does the computer decide if source pixel replaces the destination pixel?
7
Recall with Blending OFF and Depth testing ON
if source fragments's z-value is less than (closer than) destination fragments's z-value then source replaces destination. if source fragments's z-value is greater than or equal to (further than) destination fragments's z-value then source fragment is discarded.
8
With Blending ON and Depth testing ON or OFF
if source fragment would be discarded without blending, it is still discarded. if source fragments would replace the destination fragment without blending, now they will be blended.
9
Blending formula terms
Let X be a color (R,G,B,A) Let SX be the X color value for the source fragment and DX for the destination fragment Let SbX be the X color blending factor for the source fragment and DbX for the destination fragment.
10
Blending Formula DX = SbX * SX + DbX * DX
11
Some ways to set SbX and DbX
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); SbX = SA DbX = 1- SA
12
Some other ways to set SbX and DbX
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); SbX = DA DbX = 1- DA glBlendFunc(GL_ONE, GL_ZERO); SbX = 1 DbX = 0 Lots more.
13
Experiment 1: blendRectangles1.cpp
Left side of room: compute red rectangle pixels after blending with white background, and then pixels in the overlap after blending. Right side of room: compute blue rectangle pixels after blending with white background, and then pixels in the overlap after blending.
14
Experiment 1 results Red first: ( , , , ) after 1st rect.
( , , , ) after 2nd rect. Blue first: ( , , , ) after 1st rect.
15
Experiment 2 Change the background color to black and run. Are the colors the same?
16
blendRectangles2.cpp What we want:
red and blue rectangles transparent and green rectangle opaque red closest, then green, then blue.
17
blendRectangles2.cpp Why do we get what we get? Check setup
note alpha values of r,b, and g rectangles note z values of all three rectangles note gluLookAt
18
Experiment 3 Make blendRectangles2 do what is intended.
19
Experiment 4 Change the viewpoint to glLookAt(0.0, 0.0, -3.0,
0.0, 0.0, 0.0, 0.0, 1.0, 0.0 ); Does it still work correctly? (Now blue should be closest)
20
Strategy for drawing opaque and translucent objects
Turn on depth testing. Draw all the opaque items. Make the depth buffer read only : glDepthMask(GL_FALSE); Draw the transparent objects. (set the depth buffer back to read/write: glDepthMask(GL_TRUE);
21
Experiment 5 try it!
22
sphereInGlassBox.cpp run it and observe.
23
Review Textures In loadExternalTextures () we have
glBindTexture(GL_TEXTURE_2D, texture[0]); This says texture[0] is the active texture (the state). Here we set some of its properties. In drawScene() we have At this point we are setting the state, so that texture[0] will be used to draw the following polygon(s). Start here for 21
24
Blending Textures Run fieldAndSkyTexturesBlended.cpp
notice the blending functions used ONE and ZERO
25
Blending to simulate reflection
run ballAndTorusReflected.cpp discuss technique glScalef(1.0, -1.0, 1.0); glFrontFace(GL_CW); //good choice? different alphas for transparent (reflective) and opaque.
26
Fog Run fieldAndSkyFogged.cpp glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR,fogColor); fogColor is a pointer to a color glFogi(GL_FOG_MODE,fogmode); fogmode can be GL_LINEAR,GL_EXP, or GL_EXP2
27
parameters for fog for GL_LINEAR glFogf(GL_FOG_START, fogstart);
glFogf(GL_FOG_END, fogend); for GL_EXP and GL_EXP2 glFogf(GL_DENSITY,fogdensity); glHint(GL_FOG, GL_NICEST);
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.