Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rendering 4 viewports

Started by Nanook Feb 29, 2012 at 11:40 PM 2 replies 4.1k views
Original Post
Nanook
Nanook
I'm using my own engine to create a world editor.. Whats the best way to render 4 viewports from 4 different directions?

I've been thinking about rendering from 4 different cameras either to texture or to different viewports.. are there other ways? Whats the pros and cons of the different solutions?
turch
turch
Render to viewports. If you render to textures, you then have to copy the data to the back buffer as an additional step. When you render to viewports, you render directly to the back buffer.
Aqua Costa
Aqua Costa
If you're using DirectX 10 or 11 you can render everything in a single pass to a single render target using the geometry shader.

In the vertex shader output each vertex world position. Then in the geometry shader you can output a triangle to be rendered to each viewport using the SV_ViewportArrayIndex semantic...

struct GS_OUT
{
float4 position : POSITION;
uint viewportIndex : SV_ViewportArrayIndex;
//... other attributes
};


[maxvertexcount(12)]
void GS(riangle GS_IN input[3], inout TriangleStream<GS_OUT> VStream
{
//4 viewports and camera
for(uint i = 0; i < 4; i++)
{
GS_OUT output;

//select the correct viewport
output.viewportIndex = i;

//generate a triangle
for(int v = 0; v < 3; v++)
{
//transform the vertex to view space using the correct view matrix
output.position = mul(input[v], gViewMatrix);
//transfrom to homogenous space
output.position = mul(input[v], gProjMatrix);

//other attributes here

VStream.append(output);
}
VStream.RestartStrip();
}
}
}
Nanook
Nanook
TiagoCosta:
Aah right.. hmm.. I guess I would be able to do that in a CG shader? Then It will work for both dx11 and opengl? I'm writing a renderer that can use both api's..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.