Download Understanding Textures, Formats, and Deferred Shading in Computer Graphics - Prof. Timothy and more Study notes Computer Science in PDF only on Docsity!
Textures
๎ Types
๎
Formats
๎ Samplers
๎ Access functions
๎ Deferred Shading
Types
๎ Signed or unsigned
๎ (^) Byte ๎ (^) Int ๎ (^) Short Int
๎ float
๎ half float (16 bit float)
GL_ARB_half_float_pixel
๎
Packed types (Version >= 1.2)
๎ GL_UNSIGNED_SHORT_5_6_
๎ GL_UNSIGNED_SHORT_5_5_5_
๎ (^) And many more...
sRGB Colorspace
๎ โstandardโ RGB
๎ (^) A perceptually uniform colorspace ๎ (^) Perceived intensity is proportional to sRGB values
๎ Related to gamma correction
๎ (^) Monitor doesn't output linear intensities ๎ (^) I: Intensity ๎ (^) C: contrast ๎ (^) V: pixel value ๎ (^) epsilon: black level (brightness)
I = CV
๎น ๎๎ป
sRGB Colorspace
๎ Gamma correction
๎
sRGB specifies different gamma for different intensity
ranges
๎ As a result doubling the color component values in an
sRGB texture will result in the perceived intensity doubling.
V
c
= V
1 ๎น V (^) c =
12.92 V for V <= 0. 1.055 V 1
โ0.055 for V > 0.
GLSL Samplers
๎ sampler1D, 2D, 3D
๎
samplerCube
๎ sampler1DShadow
๎ sampler2DShadow
๎ (^) Depth textures with comparison
๎ sampler2DRect
๎
sampler3DRect
๎ Sampler2DRectShadow
๎ (^) Bind to GL_TEXTURE_RECTANGLE_ARB ๎ (^) Use unnormalized texture coordinates
Access functions
๎ texture1D, 2D, 3D
๎
textureCube
๎ texture1DProj, 2DProj, 3DProj
๎ texture1DLod, 2DLod, 3DLod, CubeLod
๎ (^) Arguments (sampler, coord, lod) ๎ (^) Only in vertex shader ๎ (^) Why? Normally LOD (mipmap level) is determined at the fragment processing stage.
๎ texture1DProjLod, 2DProjLod, 3DProjLod
Depth Texture Access Functions
Commonly used for shadow mapping with
COMPARE_R_TO_TEXTURE
๎
shadow1D, 2D :
๎ (^) return 0.0 or 1.0 as comparison results ๎ (^) R = coord.p
๎ shadow1DProj, 2DProj
๎ (^) return 0.0 or 1.0 as comparison results ๎ (^) R = coord.p/coord.q ๎
shadow1DLod, 2DLod
๎
shadow1DProjLod, 2DProjLod
Deferred Shading
Deering, Michael; Stephanie Winner, Bic Schediwy, Chris Duffy, Neil Hunt. "The triangle processor and normal vector shader: a VLSI system for high performance graphics". ACM SIGGRAPH Computer Graphics 22 (4): 21โ30, 1988. Also see โ6800 Leagues Under the Seaโ Nvidia deferred shading presentation ๎
Avoid shading until pixel visibility has been determined.
๎
Render lighting parameters to textures, then compute
fragment colors
๎ โfat framebufferโ or โgeometry bufferโ (g-buffer)
๎ (^) use multiple render targets: ๎ (^) Position (or depth) ๎ (^) Normal ๎ (^) Base (diffuse color) ๎ (^) Material properties
Deferred Shading Setup
๎ Defining the g-buffer:
๎
What spatially varying parameters will you need to do
shading?
๎ (^) Normals : Normal mapping, diffuse and specular lighting ๎ (^) Diffuse color ๎ (^) Shininess : specular lighting
๎ Create framebuffer object and attach textures for g-buffer
๎
Create framebuffer object and attach textures for light
accumulation
G-buffer
๎ One possible layout:
8 bits per component won't be enough-
Use 16 or 32 bit float per component
3 Shininess Diffuse.r Diffuse.g Diffuse.b Amb. Occ. Position.x Position.y Position.z Emissive Normal.x Normal.y Normal.z
Geometry Phase
๎ Bind geometry framebuffer object
๎
Draw geometry
๎ In fragment shader write to g-buffer
๎
Unbind geometry framebuffer object
gl_FragData[0] = vec4( position, 0.0); gl_FragData[1] = vec4( bumpNormal * 0.5 + 0.5, base.a); gl_FragData[2] = vec4( base.rgb, 0.0);
Lighting Phase
๎ Bind light accumulation framebuffer object
๎
Bind g-buffer textures so we can read from g-buffer
๎ Use additive blending
๎ (^) glBlendFunc( GL_ONE, GL_ONE);
๎ Draw the light volumes (more later)
๎ In fragment shader
๎ (^) Look up normal, diffuse color, etc. from textures ๎ (^) Render lit colors ๎
Unbind light accumulation framebuffer object
The stencil buffer
A logical buffer (usually 1 to 8 bits) which can determine
where drawing happens on a pixel-by-pixel basis.
Stencil operations happen near the end of the pipeline โ after
fragment processing and even after alpha testing.
Stencil buffer applications
๎ Deferred shading light volumes
๎
Shadow volumes (โStencil shadowsโ)
๎ Portals / mirrors
๎ Screen overlays / UI
๎ Screen-space transitions : dissolve