Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES 2.0 Multi-Pass & Render to Texture Implementation

I need help setting up multi-pass rendering with OpenGL ES 2.0 on the iPhone. I haven't been able to find an example which implements both rendering to a texture and multi-pass shading.

I'm looking for some instructions and sample code which implement:

  • First stage: Render to a texture
  • Second stage: Input that texture and render to screen

I have referenced Apple's OpenGL ES Programming Guide, OpenGL Shading Language (Orange Book), and O'Reilly's iPhone 3D Programming Book.

The Orange Book discusses deferred shading and provides two shader programs for first-pass and second-pass rendering, but doesn't provide example code to setup that application or show how to communicate data between both shaders.

Questions:

  • How to render to texture?
    • Using glDrawElements
    • How to input that texture to the next pass?
  • How to implement two shading programs?
  • How to alternate first- and second-pass shading programs?
    • Need to attach, detach, and call 'use' for each pass?
  • How to implement multi-pass shading?
like image 881
amblatx1 Avatar asked Dec 06 '10 16:12

amblatx1


2 Answers

I wrote a short example of doing just this (multiple render-to-texture passes on the iPhone using OpenGL ES 2.0) a few weeks ago: http://www.mat.ucsb.edu/a.forbes/blog/?p=245

**

Edit, this post is a bit old, and it has moved here: http://blog.angusforbes.com/openglglsl-render-to-texture/

**

like image 95
Angus Forbes Avatar answered Sep 28 '22 13:09

Angus Forbes


Ok, first of all: I'm no expert on OpenGL ES 2.0. I was kind of in the same situation where I wanted to do a multipass render setup, in one of my first OpenGL ES applications.

I also used the Orange Book. Check chapter 12. Framebuffer Objects > Examples. The first example demonstrates how to use a framebuffer to render to a texture, and then draws that texture to screen.

Basically using that example I created an application that renders some geometry to a texture using an effect shader, then renders that texture to screen, layered with some other content all using a different shader.

I'm not sure if this is the best approach, but it works for my purposes. My setup:

  • I create two framebuffers, the default and an offscreen one. Same for the renderbuffers
  • I create a texture which the app will render to
  • I bind the offscreen framebuffer, and attach the texture to it using glFramebufferTexture2D

My rendering:

  • bind the offscreen framebuffer.
  • use my first shader program
  • draw my geometry
  • bind the default framebuffer
  • use my second shader program
  • draw a fullscreen quad with the texture attached to it.
like image 43
Joris Kluivers Avatar answered Sep 28 '22 13:09

Joris Kluivers