GeometryShader: Adjust positions after projection.
By adjusting the positions in clip space we can avoid the re-projection.
This commit is contained in:
parent
ee76c03160
commit
51a4d6a4be
|
@ -77,25 +77,16 @@ static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiTy
|
|||
out.Write("\tfor (layer = 0; layer < %d; ++layer) {\n", g_ActiveConfig.iStereoMode > 0 ? 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.iStereoMode > 0)
|
||||
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");
|
||||
|
||||
if (ApiType == API_D3D)
|
||||
{
|
||||
out.Write("\t\to.pos.z = " I_DEPTHPARAMS".x * o.pos.w + o.pos.z * " I_DEPTHPARAMS".y;\n");
|
||||
}
|
||||
else // OGL
|
||||
{
|
||||
out.Write("\t\to.pos.z = o.pos.w + o.pos.z * 2.0;\n");
|
||||
out.Write("\t\to.clipPos.x += o.clipPos.w * " I_STEREOOFFSET"[layer] * " I_PROJECTION"[0][0];\n");
|
||||
out.Write("\t\to.pos.x += o.pos.w * " I_STEREOOFFSET"[layer] * " I_PROJECTION"[0][0];\n");
|
||||
}
|
||||
|
||||
out.Write("\t\to.pos.xy = o.pos.xy - " I_DEPTHPARAMS".zw;\n");
|
||||
out.Write("\t\tgl_Position = o.pos;\n");
|
||||
out.Write("\t\tEmitVertex();\n");
|
||||
out.Write("\t}\n");
|
||||
|
|
|
@ -52,9 +52,6 @@ static inline void GenerateVSOutputStruct(T& object, API_TYPE api_type)
|
|||
if (g_ActiveConfig.bEnablePixelLighting)
|
||||
DefineVSOutputStructMember(object, api_type, "float4", "Normal", -1, "TEXCOORD", xfmem.numTexGen.numTexGens + 1);
|
||||
|
||||
if (g_ActiveConfig.iStereoMode > 0)
|
||||
DefineVSOutputStructMember(object, api_type, "float4", "rawpos", -1, "POSITION");
|
||||
|
||||
object.Write("};\n");
|
||||
}
|
||||
|
||||
|
@ -125,6 +122,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
|
|||
out.Write("in float%d tex%d; // ATTR%d,\n", hastexmtx ? 3 : 2, i, SHADER_TEXTURE0_ATTRIB + i);
|
||||
}
|
||||
|
||||
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
|
||||
out.Write("centroid out VS_OUTPUT %s;\n", (g_ActiveConfig.iStereoMode > 0) ? "v" : "o");
|
||||
|
||||
out.Write("void main()\n{\n");
|
||||
|
@ -205,10 +203,6 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ
|
|||
|
||||
out.Write("o.pos = float4(dot(" I_PROJECTION"[0], pos), dot(" I_PROJECTION"[1], pos), dot(" I_PROJECTION"[2], pos), dot(" I_PROJECTION"[3], pos));\n");
|
||||
|
||||
uid_data->stereo = g_ActiveConfig.iStereoMode > 0;
|
||||
if (g_ActiveConfig.iStereoMode > 0)
|
||||
out.Write("o.rawpos = pos;\n");
|
||||
|
||||
out.Write("int4 lacc;\n"
|
||||
"float3 ldir, h;\n"
|
||||
"float dist, dist2, attn;\n");
|
||||
|
|
|
@ -516,8 +516,8 @@ void VertexShaderManager::SetConstants()
|
|||
if (g_ActiveConfig.iStereoMode > 0 && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
{
|
||||
float offset = g_ActiveConfig.iStereoSeparation / (200.0f * g_ActiveConfig.iStereoFocalLength);
|
||||
constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset;
|
||||
constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset;
|
||||
constants.stereooffset[0] = (g_ActiveConfig.bStereoSwapEyes) ? offset : -offset;
|
||||
constants.stereooffset[1] = (g_ActiveConfig.bStereoSwapEyes) ? -offset : offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue