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?
Rendering 4 viewports
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.
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...
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();
}
}
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement