Docsity

Understanding Textures, Formats, and Deferred Shading in Computer Graphics - Prof. Timothy, Study notes of Computer Science

Partial preview of the text

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