FOG; COMPOSITING 1 OUTLINE Fog Compositing Blending - - PowerPoint PPT Presentation

fog compositing
SMART_READER_LITE
LIVE PREVIEW

FOG; COMPOSITING 1 OUTLINE Fog Compositing Blending - - PowerPoint PPT Presentation

FOG; COMPOSITING 1 OUTLINE Fog Compositing Blending Transparency Clipping 3D Textures Noise 2 FOG Atmospheric haze Provides more realism in a scene Also provides more sense of scene depth Simple


slide-1
SLIDE 1

1

FOG; COMPOSITING

slide-2
SLIDE 2

OUTLINE

2

  • Fog
  • Compositing
  • Blending
  • Transparency
  • Clipping
  • 3D Textures
  • Noise
slide-3
SLIDE 3

FOG

  • Atmospheric haze
  • Provides more realism in a scene
  • Also provides more sense of scene depth
  • Simple (and effective) approach is to blend fog color with pixel color dependent on depth
  • Can be done in the fragment shader
slide-4
SLIDE 4

FRAGMENT SHADER

#version 430 in vec3 vertEyeSpacePos; in vec2 tc;

  • ut vec4 fragColor;

uniform mat4 mv_matrix; uniform mat4 proj_matrix; layout (binding=0) uniform sampler2D t; // for texture layout (binding=1) uniform sampler2D h; // for height map void main(void) { vec4 fogColor = vec4(0.7, 0.8, 0.9, 1.0); // bluish gray float fogStart = 0.2; float fogEnd = 0.8; // the distance from the camera to the vertex in eye space is simply the length of a // vector to that vertex, because the camera is at (0,0,0) in eye space. float dist = length(vertEyeSpacePos.xyz); float fogFactor = clamp(((fogEnd-dist)/(fogEnd-fogStart)), 0.0, 1.0); fragColor = mix(fogColor,(texture(t,tc)),fogFactor); }

slide-5
SLIDE 5

FOG RESULT

slide-6
SLIDE 6

COMPOSITING

slide-7
SLIDE 7

COMPOSITING

  • Pixel operations use the z-buffer
  • Until now, we only used this to determine which fragments were visible or not
  • Depth buffer – hidden surface removal
  • But we can do more than this
  • First, color vectors (vec4) have the alpha component
  • alpha = 1, totally opaque
  • alpha = 0, totally transparent
  • Second, we can use glBlendEquation() and glBlendFunc() to specify how to treat
  • verlapping pixels
  • This has to be done in the Java/JOGL code – this step is not programmable
slide-8
SLIDE 8

COMPOSITING

  • How it works:
  • Source and destination pixels are multiplied by the source and destination factors

specified to glBlendFunc(src, dest)

  • The operation specified in glBlendEquation is used to combine the source and

destination pixels

  • Also use glEnable(GL_BLEND) OR glDisable(GL_BLEND)
  • Tables for these constants are in the next slides
  • Default are GL_ONE for source, GL_ZERO for destination
  • Default operation is GL_BLEND
slide-9
SLIDE 9

GLBLENDFUNC() PARAMETERS

slide-10
SLIDE 10

GLBLENDEQUATION() PARAMETERS

Constant Operation GL_FUNC_ADD result = source + destination GL_FUNC_SUBTRACT result = source – destination GL_FUNC_REVERSE_SUBTRACT result = destination – source GL_MIN result = min(source, destination) GL_MAX result = max(source, destination)

slide-11
SLIDE 11

TRANSPARENCY

  • Picture on left has alpha = 1 in pyramid
  • Picture on right has alpha = 0.8 in pyramid
  • Sufficient for flat transparent objects, but maybe not for 3D objects
slide-12
SLIDE 12

TRANSPARENCY

  • Just disabling back face culling doesn’t have the effect we really want
  • Artifacts occur based on the order of rendering
  • One simple approach is to render non-transparent objects first, but that doesn’t fix

this particular situation

  • In this case, a two pass approach in rendering first front faces and then back faces works
  • Need to flip normal vectors for lighting to appear correct on back faces
slide-13
SLIDE 13

USER DEFINED CLIPPING PLANES

  • You may want to slice an object at some point (who wouldn’t?)
  • Can define a clipping plane with the equation:
  • ax + by + cz + d = 0
  • (a, b, c) is the normal to the plan
  • d defines its distance from the origin
  • Can use the “built-in” GLSL variable gl_clip_distance[ ] in the vertex shader
  • e.g.: gl_clip_distance[0] = dot(clip_plane.xyz, vertPos) + clip_plane.w
  • … assuming you have defined clip_plane to hold your (a, b, c, d) values
slide-14
SLIDE 14

THE RESULT

  • Making macaroni from a torus…
  • Not ideal – inside faces are not drawn
slide-15
SLIDE 15

RESULT OF A TWO PASS PROCESS

  • Now back faces are shown as well
  • As before, winding order needs to be reversed, and normals need to be flipped so

that lighting works correctly

slide-16
SLIDE 16

3D TEXTURES

  • Unlike 2D textures, these are usually generated procedurally
  • Can conceptualize this as an object being carved out of a 3D block of material
slide-17
SLIDE 17

CODE TO GENERATE STRIPE

void generate3Dpattern() { for (int x=0; x<texHeight; x++) { for (int y=0; y<texWidth; y++) { for (int z=0; z<texDepth; z++) { if ((y/10)%2 == 0) tex3Dpattern[x][y][z] = 0.0; else tex3Dpattern[x][y][z] = 1.0; } } } }

slide-18
SLIDE 18

CAN APPLY THIS TO ANY OBJECT

slide-19
SLIDE 19

CODE TO GENERATE CHECKERBOARD

slide-20
SLIDE 20

CHECKERBOARD DRAGON

slide-21
SLIDE 21

NOISE

  • Many natural materials can be modeled with various noise patterns
  • Construct your 3D pattern with random numbers
  • You can then fill an array with the noise and a function to create different patterns
slide-22
SLIDE 22

NOISE

  • Same “granite” cube as before, but with different levels of resolution
slide-23
SLIDE 23

SMOOTHED NOISY PATTERNS

  • Again, same “granite” pattern with smoothed noise – based on texel distance from each
  • ther, shown at different resolutions
slide-24
SLIDE 24

TURBULENCE

  • Combining smoothed levels to create a more random looking “turbulent” pattern
slide-25
SLIDE 25

MARBLE PATTERN

  • Start with stripe pattern – this starts out diagonal
  • Sine function produce the blurry edges
  • Add varying level of noise to perturb the stripes
  • Can include lighting to make it look realistic
slide-26
SLIDE 26

“MARBLE” STANFORD DRAGON

slide-27
SLIDE 27

“WOOD” 3D TEXTURE

  • Start with striped texture, but arranged in rings
  • Can both perturb the stripes, as with marble, and “rotate” the texel coordinates a bit for

more enhancement

slide-28
SLIDE 28

“WOOD” DOLPHIN

slide-29
SLIDE 29

“CLOUDS”

  • Use the turbulence map from the cube we looked at previously
  • Change the color
  • Stretch it to fit the half sphere
  • Voila – looks like clouds
slide-30
SLIDE 30

MODIFIED TURBULENCE

  • By adding a logistic / sigmoid function to the texture, can get clouds with more distinct

boundaries

slide-31
SLIDE 31

DRIFTING CLOUDS – AND SLIGHT CHANGE

  • Make the z variable of the texture change gradually over time
slide-32
SLIDE 32

SPECIAL EFFECTS

  • Dissolve effect
  • Command in the GLSL language – discard

void main(void) { float noise = texture(s,originalPosition/2.0+.5).x; if (noise > t) { fragColor = texture(e,tc); } else { discard; } }

slide-33
SLIDE 33

SUMMARY

33

  • Fog
  • Compositing
  • Blending
  • Transparency
  • Clipping
  • 3D Textures
  • Noise