diff options
Diffstat (limited to 'Source/Core/VideoCommon/VertexShaderGen.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexShaderGen.cpp | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 9fe4bfcada..2ee9532254 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -26,11 +26,6 @@ VertexShaderUid GetVertexShaderUid() uid_data->numTexGens = xfmem.numTexGen.numTexGens; uid_data->components = VertexLoaderManager::g_current_components; - uid_data->pixel_lighting = g_ActiveConfig.bEnablePixelLighting; - uid_data->vertex_rounding = - g_ActiveConfig.bVertexRounding && g_ActiveConfig.iEFBScale != SCALE_1X; - uid_data->msaa = g_ActiveConfig.iMultisamples > 1; - uid_data->ssaa = g_ActiveConfig.iMultisamples > 1 && g_ActiveConfig.bSSAA; uid_data->numColorChans = xfmem.numChan.numColorChans; GetLightingShaderUid(uid_data->lighting); @@ -81,9 +76,16 @@ VertexShaderUid GetVertexShaderUid() return out; } -ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_data* uid_data) +ShaderCode GenerateVertexShaderCode(APIType api_type, const ShaderHostConfig& host_config, + const vertex_shader_uid_data* uid_data) { ShaderCode out; + + const bool per_pixel_lighting = g_ActiveConfig.bEnablePixelLighting; + const bool msaa = host_config.msaa; + const bool ssaa = host_config.ssaa; + const bool vertex_rounding = host_config.vertex_rounding; + out.Write("%s", s_lighting_struct); // uniforms @@ -96,7 +98,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("};\n"); out.Write("struct VS_OUTPUT {\n"); - GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, uid_data->pixel_lighting, ""); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, ""); out.Write("};\n"); if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) @@ -127,12 +129,11 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da } // We need to always use output blocks for Vulkan, but geometry shaders are also optional. - if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { out.Write("VARYING_LOCATION(0) out VertexData {\n"); - GenerateVSOutputMembers( - out, api_type, uid_data->numTexGens, uid_data->pixel_lighting, - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa, true, false)); + GenerateVSOutputMembers(out, api_type, uid_data->numTexGens, per_pixel_lighting, + GetInterpolationQualifier(msaa, ssaa, true, false)); out.Write("} vs;\n"); } else @@ -142,23 +143,17 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da { if (i < uid_data->numTexGens) { - out.Write("%s out float3 uv%u;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa), i); + out.Write("%s out float3 uv%u;\n", GetInterpolationQualifier(msaa, ssaa), i); } } - out.Write("%s out float4 clipPos;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - if (uid_data->pixel_lighting) + out.Write("%s out float4 clipPos;\n", GetInterpolationQualifier(msaa, ssaa)); + if (per_pixel_lighting) { - out.Write("%s out float3 Normal;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - out.Write("%s out float3 WorldPos;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); + out.Write("%s out float3 Normal;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("%s out float3 WorldPos;\n", GetInterpolationQualifier(msaa, ssaa)); } - out.Write("%s out float4 colors_0;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); - out.Write("%s out float4 colors_1;\n", - GetInterpolationQualifier(uid_data->msaa, uid_data->ssaa)); + out.Write("%s out float4 colors_0;\n", GetInterpolationQualifier(msaa, ssaa)); + out.Write("%s out float4 colors_1;\n", GetInterpolationQualifier(msaa, ssaa)); } out.Write("void main()\n{\n"); @@ -406,7 +401,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // clipPos/w needs to be done in pixel shader, not here out.Write("o.clipPos = o.pos;\n"); - if (uid_data->pixel_lighting) + if (per_pixel_lighting) { out.Write("o.Normal = _norm0;\n"); out.Write("o.WorldPos = pos.xyz;\n"); @@ -421,7 +416,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // If we can disable the incorrect depth clipping planes using depth clamping, then we can do // our own depth clipping and calculate the depth range before the perspective divide if // necessary. - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + if (host_config.backend_depth_clamp) { // Since we're adjusting z for the depth range before the perspective divide, we have to do our // own clipping. We want to clip so that -w <= z <= 0, which matches the console -1..0 range. @@ -446,7 +441,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("o.pos.z = o.pos.w * " I_PIXELCENTERCORRECTION ".w - " "o.pos.z * " I_PIXELCENTERCORRECTION ".z;\n"); - if (!g_ActiveConfig.backend_info.bSupportsClipControl) + if (!host_config.backend_clip_control) { // If the graphics API doesn't support a depth range of 0..1, then we need to map z to // the -1..1 range. Unfortunately we have to use a substraction, which is a lossy floating-point @@ -466,7 +461,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da // get rasterized correctly. out.Write("o.pos.xy = o.pos.xy - o.pos.w * " I_PIXELCENTERCORRECTION ".xy;\n"); - if (uid_data->vertex_rounding) + if (vertex_rounding) { // By now our position is in clip space // however, higher resolutions than the Wii outputs @@ -491,9 +486,9 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da if (api_type == APIType::OpenGL || api_type == APIType::Vulkan) { - if (g_ActiveConfig.backend_info.bSupportsGeometryShaders || api_type == APIType::Vulkan) + if (host_config.backend_geometry_shaders || api_type == APIType::Vulkan) { - AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, uid_data->pixel_lighting); + AssignVSOutputMembers(out, "vs", "o", uid_data->numTexGens, per_pixel_lighting); } else { @@ -502,7 +497,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da for (unsigned int i = 0; i < uid_data->numTexGens; ++i) out.Write("uv%d.xyz = o.tex%d;\n", i, i); out.Write("clipPos = o.clipPos;\n"); - if (uid_data->pixel_lighting) + if (per_pixel_lighting) { out.Write("Normal = o.Normal;\n"); out.Write("WorldPos = o.WorldPos;\n"); @@ -511,7 +506,7 @@ ShaderCode GenerateVertexShaderCode(APIType api_type, const vertex_shader_uid_da out.Write("colors_1 = o.colors_1;\n"); } - if (g_ActiveConfig.backend_info.bSupportsDepthClamp) + if (host_config.backend_depth_clamp) { out.Write("gl_ClipDistance[0] = o.clipDist0;\n"); out.Write("gl_ClipDistance[1] = o.clipDist1;\n"); |
