mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Add geometry shader generator for stereo 3D.
This commit is contained in:
@ -38,7 +38,8 @@ set(SRCS BoundingBox.cpp
|
||||
VideoConfig.cpp
|
||||
VideoState.cpp
|
||||
XFMemory.cpp
|
||||
XFStructs.cpp)
|
||||
XFStructs.cpp
|
||||
GeometryShaderGen.cpp)
|
||||
set(LIBS core png)
|
||||
|
||||
if(_M_X86)
|
||||
|
109
Source/Core/VideoCommon/GeometryShaderGen.cpp
Normal file
109
Source/Core/VideoCommon/GeometryShaderGen.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <cmath>
|
||||
#include <locale.h>
|
||||
#ifdef __APPLE__
|
||||
#include <xlocale.h>
|
||||
#endif
|
||||
|
||||
#include "VideoCommon/GeometryShaderGen.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
#include "VideoCommon/VertexShaderGen.h"
|
||||
#include "VideoCommon/LightingShaderGen.h"
|
||||
|
||||
static char text[16384];
|
||||
|
||||
template<class T>
|
||||
static inline void GenerateGeometryShader(T& out, u32 components, API_TYPE ApiType)
|
||||
{
|
||||
// Non-uid template parameters will write to the dummy data (=> gets optimized out)
|
||||
geometry_shader_uid_data dummy_data;
|
||||
geometry_shader_uid_data* uid_data = out.template GetUidData<geometry_shader_uid_data>();
|
||||
if (uid_data == nullptr)
|
||||
uid_data = &dummy_data;
|
||||
|
||||
out.SetBuffer(text);
|
||||
const bool is_writing_shadercode = (out.GetBuffer() != nullptr);
|
||||
#ifndef ANDROID
|
||||
locale_t locale;
|
||||
locale_t old_locale;
|
||||
if (is_writing_shadercode)
|
||||
{
|
||||
locale = newlocale(LC_NUMERIC_MASK, "C", nullptr); // New locale for compilation
|
||||
old_locale = uselocale(locale); // Apply the locale for this thread
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_writing_shadercode)
|
||||
text[sizeof(text) - 1] = 0x7C; // canary
|
||||
|
||||
out.Write("//Geometry Shader for 3D stereoscopy\n");
|
||||
|
||||
if (ApiType == API_OPENGL)
|
||||
{
|
||||
// Insert layout parameters
|
||||
out.Write("layout(triangles, invocations = %d) in;\n", g_ActiveConfig.bStereo ? 2 : 1);
|
||||
out.Write("layout(triangle_strip, max_vertices = 3) out;\n");
|
||||
}
|
||||
|
||||
out.Write("%s", s_lighting_struct);
|
||||
|
||||
// uniforms
|
||||
/*if (ApiType == API_OPENGL)
|
||||
out.Write("layout(std140%s) uniform VSBlock {\n", g_ActiveConfig.backend_info.bSupportsBindingLayout ? ", binding = 2" : "");
|
||||
else
|
||||
out.Write("cbuffer VSBlock {\n");
|
||||
out.Write(
|
||||
"\tfloat4 " I_POSNORMALMATRIX"[6];\n"
|
||||
"\tfloat4 " I_PROJECTION"[4];\n"
|
||||
"\tint4 " I_MATERIALS"[4];\n"
|
||||
"\tLight " I_LIGHTS"[8];\n"
|
||||
"\tfloat4 " I_TEXMATRICES"[24];\n"
|
||||
"\tfloat4 " I_TRANSFORMMATRICES"[64];\n"
|
||||
"\tfloat4 " I_NORMALMATRICES"[32];\n"
|
||||
"\tfloat4 " I_POSTTRANSFORMMATRICES"[64];\n"
|
||||
"\tfloat4 " I_DEPTHPARAMS";\n"
|
||||
"};\n");*/
|
||||
|
||||
ShaderCode code;
|
||||
char buf[16384];
|
||||
code.SetBuffer(buf);
|
||||
GenerateVSOutputStructForGS(code, ApiType);
|
||||
out.Write(code.GetBuffer());
|
||||
|
||||
out.Write("in VS_OUTPUT vertices[];\n");
|
||||
out.Write("out VS_OUTPUT frag;\n");
|
||||
|
||||
out.Write("void main()\n{\n");
|
||||
out.Write("\tfor (int i = 0; i < gl_in.length(); ++i) {\n");
|
||||
out.Write("\t\tfrag = vertices[i];\n");
|
||||
out.Write("\t\tgl_Position = gl_in[i].gl_Position;\n");
|
||||
out.Write("\t\tgl_Layer = gl_InvocationID;\n");
|
||||
out.Write("\t\tEmitVertex();\n");
|
||||
out.Write("\t}\n");
|
||||
out.Write("\tEndPrimitive();\n");
|
||||
out.Write("}\n");
|
||||
|
||||
if (is_writing_shadercode)
|
||||
{
|
||||
if (text[sizeof(text) - 1] != 0x7C)
|
||||
PanicAlert("GeometryShader generator - buffer too small, canary has been eaten!");
|
||||
|
||||
#ifndef ANDROID
|
||||
uselocale(old_locale); // restore locale
|
||||
freelocale(locale);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void GetGeometryShaderUid(GeometryShaderUid& object, u32 components, API_TYPE ApiType)
|
||||
{
|
||||
GenerateGeometryShader<GeometryShaderUid>(object, components, ApiType);
|
||||
}
|
||||
|
||||
void GenerateGeometryShaderCode(ShaderCode& object, u32 components, API_TYPE ApiType)
|
||||
{
|
||||
GenerateGeometryShader<ShaderCode>(object, components, ApiType);
|
||||
}
|
25
Source/Core/VideoCommon/GeometryShaderGen.h
Normal file
25
Source/Core/VideoCommon/GeometryShaderGen.h
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2013 Dolphin Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "VideoCommon/ShaderGenCommon.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct geometry_shader_uid_data
|
||||
{
|
||||
u32 NumValues() const { return sizeof(geometry_shader_uid_data); }
|
||||
|
||||
u32 components : 23;
|
||||
u32 stereo : 1;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
typedef ShaderUid<geometry_shader_uid_data> GeometryShaderUid;
|
||||
|
||||
void GenerateGeometryShaderCode(ShaderCode& object, u32 components, API_TYPE ApiType);
|
||||
void GetGeometryShaderUid(GeometryShaderUid& object, u32 components, API_TYPE ApiType);
|
@ -489,7 +489,7 @@ void VertexShaderManager::SetConstants()
|
||||
|
||||
PRIM_LOG("Projection: %f %f %f %f %f %f\n", rawProjection[0], rawProjection[1], rawProjection[2], rawProjection[3], rawProjection[4], rawProjection[5]);
|
||||
|
||||
if ((g_ActiveConfig.bFreeLook || g_ActiveConfig.bAnaglyphStereo ) && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
if (g_ActiveConfig.bFreeLook && xfmem.projection.type == GX_PERSPECTIVE)
|
||||
{
|
||||
Matrix44 mtxA;
|
||||
Matrix44 mtxB;
|
||||
|
@ -60,6 +60,7 @@
|
||||
<ClCompile Include="PostProcessing.cpp" />
|
||||
<ClCompile Include="RenderBase.cpp" />
|
||||
<ClCompile Include="Statistics.cpp" />
|
||||
<ClCompile Include="GeometryShaderGen.cpp" />
|
||||
<ClCompile Include="TextureCacheBase.cpp" />
|
||||
<ClCompile Include="TextureConversionShader.cpp" />
|
||||
<ClCompile Include="VertexLoader.cpp" />
|
||||
@ -110,6 +111,7 @@
|
||||
<ClInclude Include="RenderBase.h" />
|
||||
<ClInclude Include="ShaderGenCommon.h" />
|
||||
<ClInclude Include="Statistics.h" />
|
||||
<ClInclude Include="GeometryShaderGen.h" />
|
||||
<ClInclude Include="TextureCacheBase.h" />
|
||||
<ClInclude Include="TextureConversionShader.h" />
|
||||
<ClInclude Include="TextureDecoder.h" />
|
||||
|
@ -143,6 +143,9 @@
|
||||
<ClCompile Include="BoundingBox.cpp">
|
||||
<Filter>Util</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GeometryShaderGen.cpp">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CommandProcessor.h" />
|
||||
@ -275,6 +278,9 @@
|
||||
<ClInclude Include="BoundingBox.h">
|
||||
<Filter>Util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GeometryShaderGen.h">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
@ -66,9 +66,9 @@ void VideoConfig::Load(const std::string& ini_file)
|
||||
settings->Get("DumpEFBTarget", &bDumpEFBTarget, 0);
|
||||
settings->Get("FreeLook", &bFreeLook, 0);
|
||||
settings->Get("UseFFV1", &bUseFFV1, 0);
|
||||
settings->Get("AnaglyphStereo", &bAnaglyphStereo, false);
|
||||
settings->Get("AnaglyphStereoSeparation", &iAnaglyphStereoSeparation, 200);
|
||||
settings->Get("AnaglyphFocalAngle", &iAnaglyphFocalAngle, 0);
|
||||
settings->Get("Stereo", &bStereo, false);
|
||||
settings->Get("StereoSeparation", &iStereoSeparation, 200);
|
||||
settings->Get("StereoFocalAngle", &iStereoFocalAngle, 0);
|
||||
settings->Get("EnablePixelLighting", &bEnablePixelLighting, 0);
|
||||
settings->Get("FastDepthCalc", &bFastDepthCalc, true);
|
||||
settings->Get("MSAA", &iMultisampleMode, 0);
|
||||
@ -140,9 +140,9 @@ void VideoConfig::GameIniLoad()
|
||||
CHECK_SETTING("Video_Settings", "UseRealXFB", bUseRealXFB);
|
||||
CHECK_SETTING("Video_Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
|
||||
CHECK_SETTING("Video_Settings", "HiresTextures", bHiresTextures);
|
||||
CHECK_SETTING("Video_Settings", "AnaglyphStereo", bAnaglyphStereo);
|
||||
CHECK_SETTING("Video_Settings", "AnaglyphStereoSeparation", iAnaglyphStereoSeparation);
|
||||
CHECK_SETTING("Video_Settings", "AnaglyphFocalAngle", iAnaglyphFocalAngle);
|
||||
CHECK_SETTING("Video_Settings", "Stereo", bStereo);
|
||||
CHECK_SETTING("Video_Settings", "StereoSeparation", iStereoSeparation);
|
||||
CHECK_SETTING("Video_Settings", "StereoFocalAngle", iStereoFocalAngle);
|
||||
CHECK_SETTING("Video_Settings", "EnablePixelLighting", bEnablePixelLighting);
|
||||
CHECK_SETTING("Video_Settings", "FastDepthCalc", bFastDepthCalc);
|
||||
CHECK_SETTING("Video_Settings", "MSAA", iMultisampleMode);
|
||||
@ -230,9 +230,9 @@ void VideoConfig::Save(const std::string& ini_file)
|
||||
settings->Set("DumpEFBTarget", bDumpEFBTarget);
|
||||
settings->Set("FreeLook", bFreeLook);
|
||||
settings->Set("UseFFV1", bUseFFV1);
|
||||
settings->Set("AnaglyphStereo", bAnaglyphStereo);
|
||||
settings->Set("AnaglyphStereoSeparation", iAnaglyphStereoSeparation);
|
||||
settings->Set("AnaglyphFocalAngle", iAnaglyphFocalAngle);
|
||||
settings->Set("Stereo", bStereo);
|
||||
settings->Set("StereoSeparation", iStereoSeparation);
|
||||
settings->Set("StereoFocalAngle", iStereoFocalAngle);
|
||||
settings->Set("EnablePixelLighting", bEnablePixelLighting);
|
||||
settings->Set("FastDepthCalc", bFastDepthCalc);
|
||||
settings->Set("ShowEFBCopyRegions", bShowEFBCopyRegions);
|
||||
|
@ -92,9 +92,9 @@ struct VideoConfig final
|
||||
bool bDumpEFBTarget;
|
||||
bool bUseFFV1;
|
||||
bool bFreeLook;
|
||||
bool bAnaglyphStereo;
|
||||
int iAnaglyphStereoSeparation;
|
||||
int iAnaglyphFocalAngle;
|
||||
bool bStereo;
|
||||
int iStereoSeparation;
|
||||
int iStereoFocalAngle;
|
||||
bool bBorderlessFullscreen;
|
||||
|
||||
// Hacks
|
||||
|
Reference in New Issue
Block a user