GeometryShader: Transform the projection within the geometry shader.
Reduces the amount of data transferred through uniforms. The shearing transformation is reduced to a single multiplication/addition for optimization.
This commit is contained in:
parent
4fd943aedd
commit
6cacfad010
|
@ -43,6 +43,6 @@ struct VertexShaderConstants
|
|||
float4 normalmatrices[32];
|
||||
float4 posttransformmatrices[64];
|
||||
float4 depthparams;
|
||||
float4 stereoprojection[8];
|
||||
float4 stereooffset;
|
||||
};
|
||||
|
||||
|
|
|
@ -70,16 +70,18 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
|
|||
out.Write("flat out int layer;\n");
|
||||
|
||||
out.Write("void main()\n{\n");
|
||||
if (!g_ActiveConfig.backend_info.bSupportsGSInstancing)
|
||||
if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
|
||||
out.Write("\tlayer = gl_InvocationID;\n");
|
||||
else
|
||||
out.Write("\tfor (layer = 0; layer < %d; ++layer) {\n", g_ActiveConfig.bStereo ? 2 : 1);
|
||||
out.Write("\tgl_Layer = layer;\n");
|
||||
out.Write("\tvec4 stereoproj = "I_PROJECTION"[0];\n");
|
||||
out.Write("\tstereoproj[2] += "I_STEREOOFFSET"[layer] * stereoproj[0];\n");
|
||||
out.Write("\tfor (int i = 0; i < gl_in.length(); ++i) {\n");
|
||||
out.Write("\t\to = v[i];\n");
|
||||
if (g_ActiveConfig.backend_info.bSupportsGSInstancing)
|
||||
out.Write("\t\tlayer = gl_InvocationID;\n");
|
||||
if (g_ActiveConfig.bStereo)
|
||||
out.Write("\t\to.pos = float4(dot(" I_STEREOPROJECTION"[layer * 4 + 0], v[i].rawpos), dot(" I_STEREOPROJECTION"[layer * 4 + 1], v[i].rawpos), dot(" I_STEREOPROJECTION"[layer * 4 + 2], v[i].rawpos), dot(" I_STEREOPROJECTION"[layer * 4 + 3], v[i].rawpos)); \n");
|
||||
out.Write("\t\to.pos = float4(dot(stereoproj, v[i].rawpos), dot(" I_PROJECTION"[1], v[i].rawpos), dot(" I_PROJECTION"[2], v[i].rawpos), dot(" I_PROJECTION"[3], v[i].rawpos)); \n");
|
||||
out.Write("\t\tgl_Position = o.pos;\n");
|
||||
out.Write("\t\tgl_Layer = layer;\n");
|
||||
out.Write("\t\tEmitVertex();\n");
|
||||
out.Write("\t}\n");
|
||||
out.Write("\tEndPrimitive();\n");
|
||||
|
|
|
@ -239,7 +239,7 @@ private:
|
|||
#define I_NORMALMATRICES "cnmtx"
|
||||
#define I_POSTTRANSFORMMATRICES "cpostmtx"
|
||||
#define I_DEPTHPARAMS "cDepth" // farZ, zRange
|
||||
#define I_STEREOPROJECTION "csproj"
|
||||
#define I_STEREOOFFSET "csoffset"
|
||||
|
||||
static const char s_shader_uniforms[] =
|
||||
"\tfloat4 " I_POSNORMALMATRIX"[6];\n"
|
||||
|
@ -251,4 +251,4 @@ static const char s_shader_uniforms[] =
|
|||
"\tfloat4 " I_NORMALMATRICES"[32];\n"
|
||||
"\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n"
|
||||
"\tfloat4 " I_DEPTHPARAMS";\n"
|
||||
"\tfloat4 " I_STEREOPROJECTION"[8];\n";
|
||||
"\tfloat4 " I_STEREOOFFSET";\n";
|
||||
|
|
|
@ -515,25 +515,13 @@ void VertexShaderManager::SetConstants()
|
|||
|
||||
if (g_ActiveConfig.bStereo && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
{
|
||||
Matrix44 projMtx;
|
||||
Matrix44::Set(projMtx, g_fProjectionMatrix);
|
||||
|
||||
Matrix44 leftShearMtx, rightShearMtx;
|
||||
Matrix44::Shear(leftShearMtx, g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength));
|
||||
Matrix44::Shear(rightShearMtx, -g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength));
|
||||
|
||||
Matrix44 leftProjMtx, rightProjMtx, leftCorrectedMtx, rightCorrectedMtx;
|
||||
Matrix44::Multiply(projMtx, leftShearMtx, leftProjMtx);
|
||||
Matrix44::Multiply(s_viewportCorrection, leftProjMtx, leftCorrectedMtx);
|
||||
Matrix44::Multiply(projMtx, rightShearMtx, rightProjMtx);
|
||||
Matrix44::Multiply(s_viewportCorrection, rightProjMtx, rightCorrectedMtx);
|
||||
memcpy(constants.stereoprojection, leftCorrectedMtx.data, 4*16);
|
||||
memcpy(constants.stereoprojection + 4, rightCorrectedMtx.data, 4*16);
|
||||
float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength);
|
||||
constants.stereooffset[0] = offset;
|
||||
constants.stereooffset[1] = -offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(constants.stereoprojection, constants.projection, 4 * 16);
|
||||
memcpy(constants.stereoprojection + 4, constants.projection, 4 * 16);
|
||||
constants.stereooffset[0] = constants.stereooffset[1] = 0;
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
|
|
Loading…
Reference in New Issue