Multiple-pass Reflection & Depth of Field Assignment 2
200 likes | 219 Views
Implement multiple-pass reflection and depth of field techniques for assignment 2. Deadline: 12/18/23:59. Follow system settings and implement the main function, display function, and mirror reflections. Use stencil buffer and draw scenes accordingly. Apply depth of field using accumulation buffer and jittered positions.
Multiple-pass Reflection & Depth of Field Assignment 2
E N D
Presentation Transcript
Multiple-pass Reflection Depth of Field Assignment 2
Assignment 2 • DeadLine: 12/18 23:59 • Multiple-pass Reflection • Depth of Field
Assignment 2 • It is not necessary to follow TAs implementation rule/steps. • It is free if it comes up the same result. • Do Not Copy • We ‘ll announce Demo after deadline.
System Setting • Main Function • glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
System Setting • Display Function • glEnable(GL_STENCIL_TEST); • glClearStencil(initial_value); • glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT);
Multiple-pass Reflection– Mirror Data • Front Mirror Reflection • position is (-40, 20, 0) • parallel to yz-plane. • Back Mirror Reflection • position is (40, 20, 0) • parallel to yz-plane
Multiple-pass Reflection- Step • Set Stencil Buffer value • Use “glColorMask before” / “glClear after” drawing make it non-visible • Not visible • Draw Scene • In each case(value),draw the “Right” Scene
Stencil Buffer - Reflection • glCullFace(GLenummode); • Default = GL_BACK • Doing back-face culling • Drawing Reflection of Scene,we only take the BACK-FACE part. • Doing front-face culling
Set Stencil Buffer value- Initial Value 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Set Stencil Buffer value- Setting Mirror • glStencilFunc(GL_ALWAYS, 1, 0xFF); • glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); • drawMirror()
Set Stencil Buffer value- Mirror Value 000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000
Set Stencil Buffer value– Setting Scene • glStencilFunc(GL_EQUAL, 1, 0xFF); • glStencilOp(GL_KEEP, GL_KEEP, GL_DECR); • drawScene() • //The part closer to Camera than Mirror
Set Stencil Buffer value- Final Value 000000000000000000000000000000000000000000000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100001111111111111111111111111111111111111000011111111111111111111111111111111111110000111111111111111111111111111111111111100001111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000
Stencil Buffer– Draw Scene • glStencilFunc(GL_EQUAL, 0, 0xFF); • glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); • drawScene() • //The part closer to Camera than Mirror
Stencil Buffer– Draw Scene • glStencilFunc(GL_EQUAL, 1, 0xFF); • glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); • drawScene() • 1st Reflection in the Mirror
Depth Of Field • gluLookAt( eyes, target, up ) • Combine the result with Accumulation Buffer • gluLookAt( eyes + jitter, object, up )
Depth of Field (III) • 算出 新的 座標系 (forward, right, up) • For i = [ 0 : N) • 用 right & up 算出 jitter 的新位置 • ( jitter = right * cosine + up * sine ) • glEnable(GL_MODELVIEW) • glLoadIdentity() • glLookAt() • (draw your scene) • glAccum( i ? GL_ACCUM : GL_LOAD, 1.0 / N); • glAccum(GL_RETURN, 1.0)
Assignment Request • Mobile Camera • Multi-pass Reflection • At least 4 passes each mirror • Depth of Field • Render Normally