View Full Version : Rendering similar camera views in one go

08-03-2012, 10:04 AM
i am implementing a radiosity processor using hemicube renderings on the GPU and i was thinking about rendering multiple camera views inside the same rendered image buffer (with different quadrants assigned of course).

For example i've few texels to process on the same surface. For each of them i'd have to render its hemicube. Normally i'd do this:

set the first texel camera view corresponding to one of the hemicube faces
set the destination buffer where the rendering will be written
render the geometry (with proper culling based on this camera position)
process the other 4 faces of the hemicube in the same three steps above
do the same 4 steps for the other texels

The idea instead is to render the same face of all these near texels in one batch:

pass to the shader one projection matrix for all of the cameras to use (it's sure that is identical for all of them). Then pass a modelview matrix array containing the matrices for each of the cameras to process
set the destination buffer of a size multiple to the number of cameras you need to use
render the geometry only one time. The culling of the geometry will be "broader" to have in the set the geometries inside all the camera frustums considered. Because all the cameras will render the same hemicube face and represent near texels the geometries are almost the same for each of the views.
in the vertex shader multiply the geometry data by each camera matrix and separate each result passed to the fragment shader (another array of matrices)
in the fragment shader each result will be used to used to render a texel in the buffer of the quadrant assigned to that camera. For example we have 4 cameras, we subdivide the buffer in 2 both in horizontal than vertical and render the 4 final images in those 4 rectangles.
repeat the same process for the other 4 sides of the hemicube.

Are there advantages to use this approach or is something not feasible for some reason?


08-06-2012, 01:38 AM
This will not work: the fragment shader cannot chose which or how many pixels it updates. This is all controlled by the fixed rasterizer unit between the vertex shader and the fragment shader, and you can only pass a single gl_position to the rasterizer.

You can either add a geometry shader that converts each input triangle into four output triangles or use instancing to draw the geometry multiple times with a single draw call.