More OpenGL More OpenGL Gustav Taxn, Ph. D. Associate Professor - - PowerPoint PPT Presentation

more opengl more opengl
SMART_READER_LITE
LIVE PREVIEW

More OpenGL More OpenGL Gustav Taxn, Ph. D. Associate Professor - - PowerPoint PPT Presentation

More OpenGL More OpenGL Gustav Taxn, Ph. D. Associate Professor CSC / KTH gustavt@csc.kth.se Fixed function function pipeline pipeline Fixed CPU Application Graphics hardware Per-vertex Primitive Rasteriza- operations assembly


slide-1
SLIDE 1

More OpenGL More OpenGL

Gustav Taxén, Ph. D.

Associate Professor CSC / KTH

gustavt@csc.kth.se

slide-2
SLIDE 2

Fixed Fixed function function pipeline pipeline

Application

CPU Per-vertex

  • perations

Primitive assembly Rasteriza- tion Per-fragment

  • perations

Framebuffer Graphics hardware

slide-3
SLIDE 3

Application

CPU Programmable vertex units Primitive assembly Rasteriza- tion Programmable fragment units Framebuffer Graphics hardware (GPU) Render target

Programmable Programmable pipeline pipeline

slide-4
SLIDE 4

Vertex unit

Vertex shader

slide-5
SLIDE 5

N2 L

float3 main(float3 N : NORMAL, uniform float3 L) { float d = dot(N, L); return float3(d, d, d); }

N1 L

slide-6
SLIDE 6

Pixel unit

Pixel shader

slide-7
SLIDE 7

float3 main(float2 uv : TEXCOORD0, sampler2D normalMap, uniform float3 L) { float3 N = tex2D(normalMap, uv); float d = dot(N, L); return float3(d, d, d); } http://nehe.gamedev.net

slide-8
SLIDE 8

Stream Stream processors processors

Stream processors Data in Raster ops

slide-9
SLIDE 9

VU PU VU VU VU PU PU PU PU PU PU PU 4 Vertex Units + 8 Pixel Units

slide-10
SLIDE 10

VU PU VU VU VU PU PU PU PU PU PU PU Vertex-intensive application

slide-11
SLIDE 11

VU PU VU VU VU PU PU PU PU PU PU PU Pixel-intensive application

slide-12
SLIDE 12

12 stream processors VU VU PU PU PU PU PU PU PU PU PU PU

slide-13
SLIDE 13
  • Limited instruction set
  • Optimized for 4D float

vectors

  • Inefficient branching
  • Small, fast RAM
  • Small, fast cache
  • Excellent for SIMD ops

Stream processor Data Stream processor ...

slide-14
SLIDE 14
slide-15
SLIDE 15

Geometry specification Geometry specification

glBegin(GL_QUADS); glVertex3f(...); ... glEnd();

6 sides x 4 corners per side: 24 vertices / 24 function calls

slide-16
SLIDE 16

Vertex arrays Vertex arrays

1 2 3 5 4 6 7 x y z

0 1 2 3 4 5 ...

Vertex Array index

1 2 3 5 4 6 7

slide-17
SLIDE 17

Indexed primitives Indexed primitives

1 2 3 5 4 6 7

0 1 2 3 4 5 ...

Vertex Array index

1 2 3 5 4 6 7 1 2 3 5 4

0 1 2 3 4 5...

Quad Array index

7 4 3 0

8 vertices, 2 function calls!

slide-18
SLIDE 18

Interleaved vertex arrays Interleaved vertex arrays

1 2 3

0 1 2 3 4 5 ...

Vertex Array index

x y z nx ny nz stride = 6 floats

slide-19
SLIDE 19

Reflection mapping Reflection mapping

(Rx Ry Rz )

slide-20
SLIDE 20

Jim Blinn, 1976

slide-21
SLIDE 21

Gene Miller, Michael Shou m.fl. 1982-1983

slide-22
SLIDE 22

Interface, Lance Williams, 1985

slide-23
SLIDE 23

Terminator 2, 1991

slide-24
SLIDE 24

Sphere mapping Sphere mapping

bildplan

slide-25
SLIDE 25

Sphere mapping Sphere mapping

 

  2

1 2 2 2

1 2 2 1 , 2 1        

z y x y x

R R R m m R t m R s

Reflection vector R = (Rx Ry Rz ) to texture coordinates (s, t):

slide-26
SLIDE 26

Sphere mapping Sphere mapping -

  • issues

issues

Resolution varies substantially with the reflection direction

Texture interpolation for “backwards” directions.

slide-27
SLIDE 27

Cube mapping Cube mapping

slide-28
SLIDE 28
slide-29
SLIDE 29

Buffer tests in OpenGL Buffer tests in OpenGL

Frame buffer Depth test Stencil test Alpha test

slide-30
SLIDE 30

Alpha test Alpha test

RGBA = (1, 1, 1, 0.7) RGBA = (1, 1, 1, 0.2) glAlphaFunc(GL_GREATER,0.5); glEnable(GL_ALPHA_TEST);

slide-31
SLIDE 31

Stencil test Stencil test

Stencil buffer Fragment Reference value

slide-32
SLIDE 32

Stencil test Stencil test

  • glStencilFunc()

– configures the test

  • glStencilOp()

– specifies how the reference value should be updated

slide-33
SLIDE 33

glStencilFunc(GL_EQUAL, 1, ~0);

Stencil test returns TRUE if the reference value equals 1 ~0 is a bit mask and specifies which bits in the reference value that should be compared (~0 = 0xFFFF, all bits)

Stencil test Stencil test

slide-34
SLIDE 34

Using stencils for reflections Using stencils for reflections

Use stencil buffer to cut this part

slide-35
SLIDE 35

Alpha blending Alpha blending

Rout = Rin  SR + Rframebuffer  DR

where (SR,DR), (SG,DG), (SB,DB) are blending factors

Gout = Gin  SG + Gframebuffer  DG Bout = Bin  SB + Bframebuffer  DB

slide-36
SLIDE 36

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Rout = Rin  Ain + Rframebuffer  (1 – Ain )

Step 1: Draw yellow triangle Step 2: glEnable(GL_BLEND); Draw blue triangle with A < 1 SR DR

slide-37
SLIDE 37

Multitexturing Multitexturing

slide-38
SLIDE 38

Multitexturing Multitexturing

RGBA från lighting (or glColor) RGBA from texture 0 Texture Unit 0 RGBA from texture 1 Texture Unit 1 ...

slide-39
SLIDE 39

#include <glew.h> glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ...); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ...);

slide-40
SLIDE 40

glBegin(GL_TRIANGLES); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.1, 0.2); glVertex3f(0.0, 0.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.6, 0.2); glVertex3f(1.0, 0.0, 0.0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5, 1.0); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.3, 0.5); glVertex3f(0.5, 1.0, 0.0); glEnd();

slide-41
SLIDE 41

Parsing images Parsing images

  • No image parser in OpenGL!
  • If you’re on Linux / Mac OS X, use libjpeg

source at http://www.ijg.org/

  • If you’re on Windows, use

http://corona.sourceforge.net/