From 391d2ea73d6aa44fce076d2193c7f72e8b7073b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 17 Oct 2020 07:57:32 +0200 Subject: [PATCH] Rename vk uniforms to match the other backends --- GPU/Common/ShaderUniforms.h | 72 ++++++++++---------- GPU/GLES/VertexShaderGeneratorGLES.cpp | 8 +-- GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp | 42 ++++++------ GPU/Vulkan/VertexShaderGeneratorVulkan.cpp | 72 ++++++++++---------- 4 files changed, 94 insertions(+), 100 deletions(-) diff --git a/GPU/Common/ShaderUniforms.h b/GPU/Common/ShaderUniforms.h index 5915297818..81a4b10aae 100644 --- a/GPU/Common/ShaderUniforms.h +++ b/GPU/Common/ShaderUniforms.h @@ -46,30 +46,30 @@ struct UB_VS_FS_Base { }; static const char *ub_baseStr = -R"( mat4 proj_mtx; - mat4 proj_through_mtx; - mat3x4 view_mtx; - mat3x4 world_mtx; - mat3x4 tex_mtx; - vec4 uvscaleoffset; - vec4 depthRange; - vec2 fogcoef; - float stencilReplace; - vec4 matambientalpha; - uint spline_counts; - uint depal_mask_shift_off_fmt; - int pad2; - int pad3; - vec4 cullRangeMin; - vec4 cullRangeMax; - vec3 fogcolor; - vec3 texenv; - ivec4 alphacolorref; - ivec4 alphacolormask; - vec3 blendFixA; - vec3 blendFixB; - vec4 texclamp; - vec2 texclampoff; +R"( mat4 u_proj; + mat4 u_proj_through; + mat3x4 u_view; + mat3x4 u_world; + mat3x4 u_tex; + vec4 u_uvscaleoffset; + vec4 u_depthRange; + vec2 u_fogcoef; + float u_stencilReplaceValue; + vec4 u_matambientalpha; + uint u_spline_counts; + uint u_depal_mask_shift_off_fmt; + int u_pad2; + int u_pad3; + vec4 u_cullRangeMin; + vec4 u_cullRangeMax; + vec3 u_fogcolor; + vec3 u_texenv; + ivec4 u_alphacolorref; + ivec4 u_alphacolormask; + vec3 u_blendFixA; + vec3 u_blendFixB; + vec4 u_texclamp; + vec2 u_texclampoff; )"; // HLSL code is shared so these names are changed to match those in DX9. @@ -118,16 +118,16 @@ struct UB_VS_Lights { static const char *ub_vs_lightsStr = R"( vec4 u_ambient; - vec3 matdiffuse; - vec4 matspecular; - vec3 matemissive; - vec3 pos[4]; - vec3 dir[4]; - vec3 att[4]; - vec2 angle_spotCoef[4]; - vec3 ambient[4]; - vec3 diffuse[4]; - vec3 specular[4]; + vec3 u_matdiffuse; + vec4 u_matspecular; + vec3 u_matemissive; + vec3 u_lightpos[4]; + vec3 u_lightdir[4]; + vec3 u_lightatt[4]; + vec2 u_lightangle_spotCoef[4]; + vec3 u_lightambient[4]; + vec3 u_lightdiffuse[4]; + vec3 u_lightspecular[4]; )"; // HLSL code is shared so these names are changed to match those in DX9. @@ -167,13 +167,13 @@ R"( float4 u_ambient; )"; // With some cleverness, we could get away with uploading just half this when only the four or five first -// bones are being used. This is 512b, 256b would be great. +// bones are being used. This is 384b. struct UB_VS_Bones { float bones[8][12]; }; static const char *ub_vs_bonesStr = -R"( mat3x4 m[8]; +R"( mat3x4 u_bone[8]; )"; // HLSL code is shared so these names are changed to match those in DX9. diff --git a/GPU/GLES/VertexShaderGeneratorGLES.cpp b/GPU/GLES/VertexShaderGeneratorGLES.cpp index 8f775d2647..e31354118f 100644 --- a/GPU/GLES/VertexShaderGeneratorGLES.cpp +++ b/GPU/GLES/VertexShaderGeneratorGLES.cpp @@ -33,6 +33,7 @@ #include "GPU/GLES/ShaderManagerGLES.h" #include "GPU/Common/ShaderId.h" #include "GPU/Common/VertexDecoderCommon.h" +#include "GPU/Common/VertexShaderGeneratorCommon.h" #undef WRITE @@ -62,13 +63,6 @@ static const char * const boneWeightInDecl[9] = { "in mediump vec4 w1, w2;\n", }; -enum DoLightComputation { - LIGHT_OFF, - LIGHT_SHADE, - LIGHT_FULL, -}; - - // Depth range and viewport // // After the multiplication with the projection matrix, we have a 4D vector in clip space. diff --git a/GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp b/GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp index 3d2ad0d1d5..78e2592be3 100644 --- a/GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp +++ b/GPU/Vulkan/FragmentShaderGeneratorVulkan.cpp @@ -93,7 +93,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ WRITE(p, "layout (depth_unchanged) out float gl_FragDepth;\n"); } - WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseUBO {\n%s} base;\n", ub_baseStr); + WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseUBO {\n%s};\n", ub_baseStr); if (doTexture) { WRITE(p, "layout (binding = 0) uniform sampler2D tex;\n"); } @@ -167,18 +167,18 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ std::string modulo = (gl_extensions.bugs & BUG_PVR_SHADER_PRECISION_BAD) ? "mymod" : "mod"; if (id.Bit(FS_BIT_CLAMP_S)) { - ucoord = "clamp(" + ucoord + ", base.texclamp.z, base.texclamp.x - base.texclamp.z)"; + ucoord = "clamp(" + ucoord + ", u_texclamp.z, u_texclamp.x - u_texclamp.z)"; } else { - ucoord = modulo + "(" + ucoord + ", base.texclamp.x)"; + ucoord = modulo + "(" + ucoord + ", u_texclamp.x)"; } if (id.Bit(FS_BIT_CLAMP_T)) { - vcoord = "clamp(" + vcoord + ", base.texclamp.w, base.texclamp.y - base.texclamp.w)"; + vcoord = "clamp(" + vcoord + ", u_texclamp.w, u_texclamp.y - u_texclamp.w)"; } else { - vcoord = modulo + "(" + vcoord + ", base.texclamp.y)"; + vcoord = modulo + "(" + vcoord + ", u_texclamp.y)"; } if (textureAtOffset) { - ucoord = "(" + ucoord + " + base.texclampoff.x)"; - vcoord = "(" + vcoord + " + base.texclampoff.y)"; + ucoord = "(" + ucoord + " + u_texclampoff.x)"; + vcoord = "(" + vcoord + " + u_texclampoff.y)"; } WRITE(p, " vec2 fixedcoord = vec2(%s, %s);\n", ucoord.c_str(), vcoord.c_str()); @@ -203,7 +203,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ } WRITE(p, " vec2 tsize = textureSize(tex, 0);\n"); WRITE(p, " vec2 fraction;\n"); - WRITE(p, " bool bilinear = (base.depal_mask_shift_off_fmt >> 31) != 0;\n"); + WRITE(p, " bool bilinear = (u_depal_mask_shift_off_fmt >> 31) != 0;\n"); WRITE(p, " if (bilinear) {\n"); WRITE(p, " uv_round = uv * tsize - vec2(0.5, 0.5);\n"); WRITE(p, " fraction = fract(uv_round);\n"); @@ -215,10 +215,10 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ WRITE(p, " vec4 t1 = textureOffset(tex, uv_round, ivec2(1, 0));\n"); WRITE(p, " vec4 t2 = textureOffset(tex, uv_round, ivec2(0, 1));\n"); WRITE(p, " vec4 t3 = textureOffset(tex, uv_round, ivec2(1, 1));\n"); - WRITE(p, " uint depalMask = (base.depal_mask_shift_off_fmt & 0xFF);\n"); - WRITE(p, " uint depalShift = (base.depal_mask_shift_off_fmt >> 8) & 0xFF;\n"); - WRITE(p, " uint depalOffset = ((base.depal_mask_shift_off_fmt >> 16) & 0xFF) << 4;\n"); - WRITE(p, " uint depalFmt = (base.depal_mask_shift_off_fmt >> 24) & 0x3;\n"); + WRITE(p, " uint depalMask = (u_depal_mask_shift_off_fmt & 0xFF);\n"); + WRITE(p, " uint depalShift = (u_depal_mask_shift_off_fmt >> 8) & 0xFF;\n"); + WRITE(p, " uint depalOffset = ((u_depal_mask_shift_off_fmt >> 16) & 0xFF) << 4;\n"); + WRITE(p, " uint depalFmt = (u_depal_mask_shift_off_fmt >> 24) & 0x3;\n"); WRITE(p, " uvec4 col; uint index0; uint index1; uint index2; uint index3;\n"); WRITE(p, " switch (depalFmt) {\n"); // We might want to include fmt in the shader ID if this is a performance issue. WRITE(p, " case 0:\n"); // 565 @@ -299,7 +299,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ break; case GE_TEXFUNC_BLEND: - WRITE(p, " vec4 v = vec4(mix(p.rgb, base.texenv.rgb, t.rgb), p.a * t.a)%s;\n", secondary); + WRITE(p, " vec4 v = vec4(mix(p.rgb, u_texenv.rgb, t.rgb), p.a * t.a)%s;\n", secondary); break; case GE_TEXFUNC_REPLACE: @@ -326,7 +326,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ break; case GE_TEXFUNC_BLEND: - WRITE(p, " vec4 v = vec4(mix(p.rgb, base.texenv.rgb, t.rgb), p.a)%s;\n", secondary); + WRITE(p, " vec4 v = vec4(mix(p.rgb, u_texenv.rgb, t.rgb), p.a)%s;\n", secondary); break; case GE_TEXFUNC_REPLACE: @@ -374,7 +374,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ } else { const char *alphaTestFuncs[] = { "#", "#", " != ", " == ", " >= ", " > ", " <= ", " < " }; if (alphaTestFuncs[alphaTestFunc][0] != '#') { - WRITE(p, " if ((roundAndScaleTo255i(v.a) & base.alphacolormask.a) %s base.alphacolorref.a) %s\n", alphaTestFuncs[alphaTestFunc], discardStatement); + WRITE(p, " if ((roundAndScaleTo255i(v.a) & u_alphacolormask.a) %s u_alphacolorref.a) %s\n", alphaTestFuncs[alphaTestFunc], discardStatement); } else { // This means NEVER. See above. WRITE(p, " %s\n", discardStatement); @@ -384,7 +384,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ if (enableFog) { WRITE(p, " float fogCoef = clamp(v_fogdepth, 0.0, 1.0);\n"); - WRITE(p, " v = mix(vec4(base.fogcolor, v.a), v, fogCoef);\n"); + WRITE(p, " v = mix(vec4(u_fogcolor, v.a), v, fogCoef);\n"); // WRITE(p, " v.x = v_depth;\n"); } @@ -407,7 +407,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ const char *colorTestFuncs[] = { "#", "#", " != ", " == " }; if (colorTestFuncs[colorTestFunc][0] != '#') { WRITE(p, " ivec3 v_scaled = roundAndScaleTo255iv(v.rgb);\n"); - WRITE(p, " if ((v_scaled & base.alphacolormask.rgb) %s (base.alphacolorref.rgb & base.alphacolormask.rgb)) %s\n", colorTestFuncs[colorTestFunc], discardStatement); + WRITE(p, " if ((v_scaled & u_alphacolormask.rgb) %s (u_alphacolorref.rgb & u_alphacolormask.rgb)) %s\n", colorTestFuncs[colorTestFunc], discardStatement); } else { WRITE(p, " %s\n", discardStatement); } @@ -431,7 +431,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "vec3(1.0 - v.a * 2.0)"; break; case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "ERROR"; break; case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "ERROR"; break; - case GE_SRCBLEND_FIXA: srcFactor = "base.blendFixA"; break; + case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break; } WRITE(p, " v.rgb = v.rgb * %s;\n", srcFactor); @@ -454,7 +454,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ case GE_SRCBLEND_DOUBLEINVSRCALPHA: srcFactor = "vec3(1.0 - v.a * 2.0)"; break; case GE_SRCBLEND_DOUBLEDSTALPHA: srcFactor = "vec3(destColor.a * 2.0)"; break; case GE_SRCBLEND_DOUBLEINVDSTALPHA: srcFactor = "vec3(1.0 - destColor.a * 2.0)"; break; - case GE_SRCBLEND_FIXA: srcFactor = "base.blendFixA"; break; + case GE_SRCBLEND_FIXA: srcFactor = "u_blendFixA"; break; } switch (replaceBlendFuncB) { case GE_DSTBLEND_SRCCOLOR: dstFactor = "v.rgb"; break; @@ -467,7 +467,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ case GE_DSTBLEND_DOUBLEINVSRCALPHA: dstFactor = "vec3(1.0 - v.a * 2.0)"; break; case GE_DSTBLEND_DOUBLEDSTALPHA: dstFactor = "vec3(destColor.a * 2.0)"; break; case GE_DSTBLEND_DOUBLEINVDSTALPHA: dstFactor = "vec3(1.0 - destColor.a * 2.0)"; break; - case GE_DSTBLEND_FIXB: dstFactor = "base.blendFixB"; break; + case GE_DSTBLEND_FIXB: dstFactor = "u_blendFixB"; break; } switch (replaceBlendEq) { @@ -502,7 +502,7 @@ bool GenerateVulkanGLSLFragmentShader(const FShaderID &id, char *buffer, uint32_ if (stencilToAlpha != REPLACE_ALPHA_NO) { switch (replaceAlphaWithStencilType) { case STENCIL_VALUE_UNIFORM: - replacedAlpha = "base.stencilReplace"; + replacedAlpha = "u_stencilReplaceValue"; break; case STENCIL_VALUE_ZERO: diff --git a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp index 36574f24ae..d706c42e08 100644 --- a/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp +++ b/GPU/Vulkan/VertexShaderGeneratorVulkan.cpp @@ -134,11 +134,11 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { bool flipNormalTess = id.Bit(VS_BIT_NORM_REVERSE_TESS); WRITE(p, "\n"); - WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseVars {\n%s} base;\n", ub_baseStr); + WRITE(p, "layout (std140, set = 0, binding = 3) uniform baseVars {\n%s};\n", ub_baseStr); if (enableLighting || doShadeMapping) - WRITE(p, "layout (std140, set = 0, binding = 4) uniform lightVars {\n%s} light;\n", ub_vs_lightsStr); + WRITE(p, "layout (std140, set = 0, binding = 4) uniform lightVars {\n%s};\n", ub_vs_lightsStr); if (enableBones) - WRITE(p, "layout (std140, set = 0, binding = 5) uniform boneVars {\n%s} bone;\n", ub_vs_bonesStr); + WRITE(p, "layout (std140, set = 0, binding = 5) uniform boneVars {\n%s};\n", ub_vs_bonesStr); const char *shading = doFlatShading ? "flat " : ""; @@ -203,9 +203,9 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { // Apply the projection and viewport to get the Z buffer value, floor to integer, undo the viewport and projection. WRITE(p, "\nvec4 depthRoundZVP(vec4 v) {\n"); WRITE(p, " float z = v.z / v.w;\n"); - WRITE(p, " z = z * base.depthRange.x + base.depthRange.y;\n"); + WRITE(p, " z = z * u_depthRange.x + u_depthRange.y;\n"); WRITE(p, " z = floor(z);\n"); - WRITE(p, " z = (z - base.depthRange.z) * base.depthRange.w;\n"); + WRITE(p, " z = (z - u_depthRange.z) * u_depthRange.w;\n"); WRITE(p, " return vec4(v.x, v.y, z * v.w, v.w);\n"); WRITE(p, "}\n\n"); } @@ -263,7 +263,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { WRITE(p, " int index;\n"); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - WRITE(p, " index = (%i + point_pos.y) * int(base.spline_counts) + (%i + point_pos.x);\n", i, j); + WRITE(p, " index = (%i + point_pos.y) * int(u_spline_counts) + (%i + point_pos.x);\n", i, j); WRITE(p, " _pos[%i] = tess_data.data[index].pos.xyz;\n", i * 4 + j); if (doTexture && hasTexcoordTess) WRITE(p, " _tex[%i] = tess_data.data[index].uv.xy;\n", i * 4 + j); @@ -288,7 +288,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { if (hasColorTess) WRITE(p, " tess.col = tess_sample(_col, basis);\n"); else - WRITE(p, " tess.col = base.matambientalpha;\n"); + WRITE(p, " tess.col = u_matambientalpha;\n"); if (hasNormalTess) { // Derivatives as weight coefficients WRITE(p, " vec4 deriv_u = tess_weights_u.data[weight_idx.x].deriv;\n"); @@ -317,7 +317,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { if (lmode) WRITE(p, " v_color1 = color1;\n"); } else { - WRITE(p, " v_color0 = base.matambientalpha;\n"); + WRITE(p, " v_color0 = u_matambientalpha;\n"); if (lmode) WRITE(p, " v_color1 = vec3(0.0);\n"); } @@ -325,13 +325,13 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { WRITE(p, " v_fogdepth = position.w;\n"); } if (isModeThrough) { - WRITE(p, " vec4 outPos = base.proj_through_mtx * vec4(position.xyz, 1.0);\n"); + WRITE(p, " vec4 outPos = u_proj_through * vec4(position.xyz, 1.0);\n"); } else { // The viewport is used in this case, so need to compensate for that. if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) { - WRITE(p, " vec4 outPos = depthRoundZVP(base.proj_mtx * vec4(position.xyz, 1.0));\n"); + WRITE(p, " vec4 outPos = depthRoundZVP(u_proj * vec4(position.xyz, 1.0));\n"); } else { - WRITE(p, " vec4 outPos = base.proj_mtx * vec4(position.xyz, 1.0);\n"); + WRITE(p, " vec4 outPos = u_proj * vec4(position.xyz, 1.0);\n"); } } } else { @@ -342,17 +342,17 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { WRITE(p, " Tess tess;\n"); WRITE(p, " tessellate(tess);\n"); - WRITE(p, " vec3 worldpos = vec4(tess.pos.xyz, 1.0) * base.world_mtx;\n"); + WRITE(p, " vec3 worldpos = vec4(tess.pos.xyz, 1.0) * u_world;\n"); if (hasNormalTess) { - WRITE(p, " mediump vec3 worldnormal = normalize(vec4(%stess.nrm, 0.0) * base.world_mtx);\n", flipNormalTess ? "-" : ""); + WRITE(p, " mediump vec3 worldnormal = normalize(vec4(%stess.nrm, 0.0) * u_world);\n", flipNormalTess ? "-" : ""); } else { WRITE(p, " mediump vec3 worldnormal = vec3(0.0, 0.0, 1.0);\n"); } } else { // No skinning, just standard T&L. - WRITE(p, " vec3 worldpos = vec4(position.xyz, 1.0) * base.world_mtx;\n"); + WRITE(p, " vec3 worldpos = vec4(position.xyz, 1.0) * u_world;\n"); if (hasNormal) - WRITE(p, " mediump vec3 worldnormal = normalize(vec4(%snormal, 0.0) * base.world_mtx);\n", flipNormal ? "-" : ""); + WRITE(p, " mediump vec3 worldnormal = normalize(vec4(%snormal, 0.0) * u_world);\n", flipNormal ? "-" : ""); else WRITE(p, " mediump vec3 worldnormal = vec3(0.0, 0.0, 1.0);\n"); } @@ -365,10 +365,10 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { "w2.x", "w2.y", "w2.z", "w2.w", }; - WRITE(p, " mat3x4 skinMatrix = w1.x * bone.m[0];\n"); + WRITE(p, " mat3x4 skinMatrix = w1.x * u_bone[0];\n"); if (numBoneWeights > 1) { for (int i = 1; i < numBoneWeights; i++) { - WRITE(p, " skinMatrix += %s * bone.m[%i];\n", boneWeightAttr[i], i); + WRITE(p, " skinMatrix += %s * u_bone[%i];\n", boneWeightAttr[i], i); } } @@ -376,23 +376,23 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { // Trying to simplify this results in bugs in LBP... WRITE(p, " vec3 skinnedpos = (vec4(position, 1.0) * skinMatrix) %s;\n", factor); - WRITE(p, " vec3 worldpos = vec4(skinnedpos, 1.0) * base.world_mtx;\n"); + WRITE(p, " vec3 worldpos = vec4(skinnedpos, 1.0) * u_world;\n"); if (hasNormal) { WRITE(p, " mediump vec3 skinnednormal = vec4(%snormal, 0.0) * skinMatrix %s;\n", flipNormal ? "-" : "", factor); } else { WRITE(p, " mediump vec3 skinnednormal = vec4(0.0, 0.0, %s1.0, 0.0) * skinMatrix %s;\n", flipNormal ? "-" : "", factor); } - WRITE(p, " mediump vec3 worldnormal = normalize(vec4(skinnednormal, 0.0) * base.world_mtx);\n"); + WRITE(p, " mediump vec3 worldnormal = normalize(vec4(skinnednormal, 0.0) * u_world);\n"); } - WRITE(p, " vec4 viewPos = vec4(vec4(worldpos, 1.0) * base.view_mtx, 1.0);\n"); + WRITE(p, " vec4 viewPos = vec4(vec4(worldpos, 1.0) * u_view, 1.0);\n"); // Final view and projection transforms. if (gstate_c.Supports(GPU_ROUND_DEPTH_TO_16BIT)) { - WRITE(p, " vec4 outPos = depthRoundZVP(base.proj_mtx * viewPos);\n"); + WRITE(p, " vec4 outPos = depthRoundZVP(u_proj * viewPos);\n"); } else { - WRITE(p, " vec4 outPos = base.proj_mtx * viewPos;\n"); + WRITE(p, " vec4 outPos = u_proj * viewPos;\n"); } // TODO: Declare variables for dots for shade mapping if needed. @@ -536,7 +536,7 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { else WRITE(p, " v_color0 = color0;\n"); } else { - WRITE(p, " v_color0 = base.matambientalpha;\n"); + WRITE(p, " v_color0 = u_matambientalpha;\n"); } if (lmode) { WRITE(p, " v_color1 = vec3(0.0);\n"); @@ -553,17 +553,17 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { if (scaleUV) { if (hasTexcoord) { if (doBezier || doSpline) - WRITE(p, " v_texcoord = vec3(tess.tex.xy * base.uvscaleoffset.xy + base.uvscaleoffset.zw, 0.0);\n"); + WRITE(p, " v_texcoord = vec3(tess.tex.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n"); else - WRITE(p, " v_texcoord = vec3(texcoord.xy * base.uvscaleoffset.xy, 0.0);\n"); + WRITE(p, " v_texcoord = vec3(texcoord.xy * u_uvscaleoffset.xy, 0.0);\n"); } else { WRITE(p, " v_texcoord = vec3(0.0);\n"); } } else { if (hasTexcoord) { - WRITE(p, " v_texcoord = vec3(texcoord.xy * base.uvscaleoffset.xy + base.uvscaleoffset.zw, 0.0);\n"); + WRITE(p, " v_texcoord = vec3(texcoord.xy * u_uvscaleoffset.xy + u_uvscaleoffset.zw, 0.0);\n"); } else { - WRITE(p, " v_texcoord = vec3(base.uvscaleoffset.zw, 0.0);\n"); + WRITE(p, " v_texcoord = vec3(u_uvscaleoffset.zw, 0.0);\n"); } } break; @@ -599,15 +599,15 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { break; } // Transform by texture matrix. XYZ as we are doing projection mapping. - WRITE(p, " v_texcoord = (%s * base.tex_mtx).xyz * vec3(base.uvscaleoffset.xy, 1.0);\n", temp_tc.c_str()); + WRITE(p, " v_texcoord = (%s * u_tex).xyz * vec3(u_uvscaleoffset.xy, 1.0);\n", temp_tc.c_str()); } break; case GE_TEXMAP_ENVIRONMENT_MAP: // Shade mapping - use dots from light sources. { - std::string lightFactor0 = StringFromFormat("(length(light.pos[%i]) == 0.0 ? worldnormal.z : dot(normalize(light.pos[%i]), worldnormal))", ls0, ls0); - std::string lightFactor1 = StringFromFormat("(length(light.pos[%i]) == 0.0 ? worldnormal.z : dot(normalize(light.pos[%i]), worldnormal))", ls1, ls1); - WRITE(p, " v_texcoord = vec3(base.uvscaleoffset.xy * vec2(1.0 + %s, 1.0 + %s) * 0.5, 1.0);\n", lightFactor0.c_str(), lightFactor1.c_str()); + std::string lightFactor0 = StringFromFormat("(length(u_lightpos[%i]) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos[%i]), worldnormal))", ls0, ls0); + std::string lightFactor1 = StringFromFormat("(length(u_lightpos[%i]) == 0.0 ? worldnormal.z : dot(normalize(u_lightpos[%i]), worldnormal))", ls1, ls1); + WRITE(p, " v_texcoord = vec3(u_uvscaleoffset.xy * vec2(1.0 + %s, 1.0 + %s) * 0.5, 1.0);\n", lightFactor0.c_str(), lightFactor1.c_str()); } break; @@ -619,17 +619,17 @@ bool GenerateVulkanGLSLVertexShader(const VShaderID &id, char *buffer) { // Compute fogdepth if (enableFog) - WRITE(p, " v_fogdepth = (viewPos.z + base.fogcoef.x) * base.fogcoef.y;\n"); + WRITE(p, " v_fogdepth = (viewPos.z + u_fogcoef.x) * u_fogcoef.y;\n"); } if (!isModeThrough && gstate_c.Supports(GPU_SUPPORTS_VS_RANGE_CULLING)) { WRITE(p, " vec3 projPos = outPos.xyz / outPos.w;\n"); // Vertex range culling doesn't happen when depth is clamped, so only do this if in range. - WRITE(p, " if (base.cullRangeMin.w <= 0.0 || (projPos.z >= base.cullRangeMin.z && projPos.z <= base.cullRangeMax.z)) {\n"); - const char *outMin = "projPos.x < base.cullRangeMin.x || projPos.y < base.cullRangeMin.y || projPos.z < base.cullRangeMin.z"; - const char *outMax = "projPos.x > base.cullRangeMax.x || projPos.y > base.cullRangeMax.y || projPos.z > base.cullRangeMax.z"; + WRITE(p, " if (u_cullRangeMin.w <= 0.0 || (projPos.z >= u_cullRangeMin.z && projPos.z <= u_cullRangeMax.z)) {\n"); + const char *outMin = "projPos.x < u_cullRangeMin.x || projPos.y < u_cullRangeMin.y || projPos.z < u_cullRangeMin.z"; + const char *outMax = "projPos.x > u_cullRangeMax.x || projPos.y > u_cullRangeMax.y || projPos.z > u_cullRangeMax.z"; WRITE(p, " if (%s || %s) {\n", outMin, outMax); - WRITE(p, " outPos.xyzw = vec4(base.cullRangeMax.w);\n"); + WRITE(p, " outPos.xyzw = vec4(u_cullRangeMax.w);\n"); WRITE(p, " }\n"); WRITE(p, " }\n"); }