Chap 7. OpenGL extension - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Chap 7. OpenGL extension

Description:

OpenGL programming guide chapter 9 'Texture Mapping' ... if it's not under shadow, render the fragment with diffuse and specular light. ... – PowerPoint PPT presentation

Number of Views:70
Avg rating:3.0/5.0
Slides: 17
Provided by: cggmcsie
Category:

less

Transcript and Presenter's Notes

Title: Chap 7. OpenGL extension


1
Chap 7. OpenGL extension
2
How to
  • By yourself
  • Query the OpenGL32.dll, and get the function
    address
  • Dont do it
  • glew
  • http//glew.sourceforge.net/

3
In your C project
  • Add include/glew.h to your Include Files
    folder in .NET
  • Put lib/glew32s.lib into your project folder
  • define GLEW_STATIC 1
  • include "glew.h
  • glutInit(argc, argv)
  • glewInit()

4
(No Transcript)
5
Some online resources
  • OpenGL programming guide chapter 9 Texture
    Mapping
  • http//www.opengl.org/documentation/red_book_1.0/O
    penGL_PG_ch09.pdf
  • An online tutorial on shadow map
  • http//www.paulsprojects.net/tutorials/smt/smt.htm
    l

6
Example Shadow map
  • What is shadow

light
eye
Object
Under shadow
7
What is a shadow map
  • A depth image as seen from the light
  • When the depth of a point is greater than the
    depth in the shadow map, it is under shadow
  • If you move the viewpoint to the light source
    position, there are no shadows from that
    perspective

8
Overview
  • 3-pass algorithm
  • First pass render the scene from the point of
    view of the light,and store the depth in the
    texture (shadow map)
  • projection modelview,
  • Second pass render the scene with only ambient
    light
  • Third pass render the scene,and compare the
    depth of the fragment to the shadow map, if its
    greater than the depth in the shadow map, its
    under shadow. if its not under shadow, render
    the fragment with diffuse and specular light.
  • How can we compare in different coordinate?

9
How can we compare in different coordinate
10
The transformation matrix
11
In OpenGL
  • First pass
  • Setup the projection and modelview matrix as
    seen from the light
  • draw your scene
  • glGenTextures(1, texID)
  • glBindTexture(GL_TEXTURE_2D, texID)
  • glCopyTexImage2D( GL_TEXTURE_2D, 0,
    GL_DEPTH_COMPONENT, 0, 0,
  • SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT, 0 )

12
  • void glCopyTexImage2D(
  • GLenum target,
  • GLint level,
  • GLint internalFormat,
  • GLint x, GLint y,
  • GLsizei width, GLsizei height,
  • GLint border)

13
  • Third pass
  • void generateTextureMatrix( float lightPos )
  • glMatrixMode(GL_TEXTURE)
  • glLoadIdentity()
  • glTranslatef( 0.5, 0.5, 0.0 )
  • glScalef( 0.5, 0.5, 1.0 )
  • gluPerspective( 80.0, 1.0, 10.0, 100.0 )
  • gluLookAt( lightPos0, lightPos1,
    lightPos2,
  • 0.0, 0.0, 0.0,
  • 0.0, 1.0, 0.0)
  • glEnable( GL_TEXTURE_GEN_S )
  • glEnable( GL_TEXTURE_GEN_T )
  • glEnable( GL_TEXTURE_GEN_R )
  • glEnable( GL_TEXTURE_GEN_Q )

14
  • float sPlane4 1.0, 0.0, 0.0, 0.0
  • float tPlane4 0.0, 1.0, 0.0, 0.0
  • float rPlane4 0.0, 0.0, 1.0, 0.0
  • float qPlane4 0.0, 0.0, 0.0, 1.0
  • glTexGeni( GL_S, GL_TEXTURE_GEN_MODE,
    GL_EYE_LINEAR )
  • glTexGeni( GL_T, GL_TEXTURE_GEN_MODE,
    GL_EYE_LINEAR )
  • glTexGeni( GL_R, GL_TEXTURE_GEN_MODE,
    GL_EYE_LINEAR )
  • glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE,
    GL_EYE_LINEAR )
  • glTexGenfv( GL_S, GL_EYE_PLANE, sPlane )
  • glTexGenfv( GL_T, GL_EYE_PLANE, tPlane )
  • glTexGenfv( GL_R, GL_EYE_PLANE, rPlane )
  • glTexGenfv( GL_Q, GL_EYE_PLANE, qPlane )

15
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE )
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE )
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER, GL_LINEAR )
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_MAG_FILTER, GL_LINEAR )
  • glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
    GL_MODULATE)
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL )
  • glTexParameteri( GL_TEXTURE_2D,
    GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE )
  • glTexParameteri( GL_TEXTURE_2D,
    GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE
    )
  • glMatrixMode(GL_MODELVIEW)

16
Not so easy
  • Self shadow
  • Add bias
  • glPolygonOffset(GLfloat factor, GLfloat units)
  • Render backface and cull front face when
    gererating shadow map
  • Aliasing
Write a Comment
User Comments (0)
About PowerShow.com