mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-29 15:22:08 +00:00
- added Build's NPOT emulation to the backend.
For GZDoom this is completely disabled, of course, because the Doom engine does not need it, but in order to have the same backend code in both engines it needs to be present.
This commit is contained in:
parent
65df05cba2
commit
9e51a2f63c
7 changed files with 164 additions and 98 deletions
|
@ -142,6 +142,9 @@ bool FGLRenderState::ApplyShader()
|
||||||
activeShader->muTextureModulateColor.Set(mStreamData.uTextureModulateColor);
|
activeShader->muTextureModulateColor.Set(mStreamData.uTextureModulateColor);
|
||||||
activeShader->muTextureBlendColor.Set(mStreamData.uTextureBlendColor);
|
activeShader->muTextureBlendColor.Set(mStreamData.uTextureBlendColor);
|
||||||
activeShader->muDetailParms.Set(&mStreamData.uDetailParms.X);
|
activeShader->muDetailParms.Set(&mStreamData.uDetailParms.X);
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
activeShader->muNpotEmulation.Set(&mStreamData.uNpotEmulation.X);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mGlowEnabled || activeShader->currentglowstate)
|
if (mGlowEnabled || activeShader->currentglowstate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include "hw_lightbuffer.h"
|
#include "hw_lightbuffer.h"
|
||||||
#include "i_specialpaths.h"
|
#include "i_specialpaths.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#include "gl_interface.h"
|
#include "gl_interface.h"
|
||||||
#include "gl_debug.h"
|
#include "gl_debug.h"
|
||||||
|
@ -232,105 +233,106 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
float uClipHeightDirection;
|
float uClipHeightDirection;
|
||||||
int uShadowmapFilter;
|
int uShadowmapFilter;
|
||||||
};
|
};
|
||||||
)";
|
|
||||||
|
|
||||||
i_data += "uniform int uTextureMode;\n";
|
uniform int uTextureMode;
|
||||||
i_data += "uniform vec2 uClipSplit;\n";
|
uniform vec2 uClipSplit;
|
||||||
i_data += "uniform float uAlphaThreshold;\n";
|
uniform float uAlphaThreshold;
|
||||||
|
|
||||||
// colors
|
// colors
|
||||||
i_data += "uniform vec4 uObjectColor;\n";
|
uniform vec4 uObjectColor;
|
||||||
i_data += "uniform vec4 uObjectColor2;\n";
|
uniform vec4 uObjectColor2;
|
||||||
i_data += "uniform vec4 uDynLightColor;\n";
|
uniform vec4 uDynLightColor;
|
||||||
i_data += "uniform vec4 uAddColor;\n";
|
uniform vec4 uAddColor;
|
||||||
i_data += "uniform vec4 uTextureBlendColor;\n";
|
uniform vec4 uTextureBlendColor;
|
||||||
i_data += "uniform vec4 uTextureModulateColor;\n";
|
uniform vec4 uTextureModulateColor;
|
||||||
i_data += "uniform vec4 uTextureAddColor;\n";
|
uniform vec4 uTextureAddColor;
|
||||||
i_data += "uniform vec4 uBlendColor;\n";
|
uniform vec4 uBlendColor;
|
||||||
i_data += "uniform vec4 uFogColor;\n";
|
uniform vec4 uFogColor;
|
||||||
i_data += "uniform float uDesaturationFactor;\n";
|
uniform float uDesaturationFactor;
|
||||||
i_data += "uniform float uInterpolationFactor;\n";
|
uniform float uInterpolationFactor;
|
||||||
|
|
||||||
// Glowing walls stuff
|
// Glowing walls stuff
|
||||||
i_data += "uniform vec4 uGlowTopPlane;\n";
|
uniform vec4 uGlowTopPlane;
|
||||||
i_data += "uniform vec4 uGlowTopColor;\n";
|
uniform vec4 uGlowTopColor;
|
||||||
i_data += "uniform vec4 uGlowBottomPlane;\n";
|
uniform vec4 uGlowBottomPlane;
|
||||||
i_data += "uniform vec4 uGlowBottomColor;\n";
|
uniform vec4 uGlowBottomColor;
|
||||||
|
|
||||||
i_data += "uniform vec4 uGradientTopPlane;\n";
|
uniform vec4 uGradientTopPlane;
|
||||||
i_data += "uniform vec4 uGradientBottomPlane;\n";
|
uniform vec4 uGradientBottomPlane;
|
||||||
|
|
||||||
i_data += "uniform vec4 uSplitTopPlane;\n";
|
uniform vec4 uSplitTopPlane;
|
||||||
i_data += "uniform vec4 uSplitBottomPlane;\n";
|
uniform vec4 uSplitBottomPlane;
|
||||||
|
|
||||||
i_data += "uniform vec4 uDetailParms;\n";
|
|
||||||
|
|
||||||
|
uniform vec4 uDetailParms;
|
||||||
// Lighting + Fog
|
// Lighting + Fog
|
||||||
i_data += "uniform vec4 uLightAttr;\n";
|
uniform vec4 uLightAttr;
|
||||||
i_data += "#define uLightLevel uLightAttr.a\n";
|
#define uLightLevel uLightAttr.a
|
||||||
i_data += "#define uFogDensity uLightAttr.b\n";
|
#define uFogDensity uLightAttr.b
|
||||||
i_data += "#define uLightFactor uLightAttr.g\n";
|
#define uLightFactor uLightAttr.g
|
||||||
i_data += "#define uLightDist uLightAttr.r\n";
|
#define uLightDist uLightAttr.r
|
||||||
i_data += "uniform int uFogEnabled;\n";
|
uniform int uFogEnabled;
|
||||||
|
|
||||||
// dynamic lights
|
// dynamic lights
|
||||||
i_data += "uniform int uLightIndex;\n";
|
uniform int uLightIndex;
|
||||||
|
|
||||||
// Blinn glossiness and specular level
|
// Blinn glossiness and specular level
|
||||||
i_data += "uniform vec2 uSpecularMaterial;\n";
|
uniform vec2 uSpecularMaterial;
|
||||||
|
|
||||||
// matrices
|
// matrices
|
||||||
i_data += "uniform mat4 ModelMatrix;\n";
|
uniform mat4 ModelMatrix;
|
||||||
i_data += "uniform mat4 NormalModelMatrix;\n";
|
uniform mat4 NormalModelMatrix;
|
||||||
i_data += "uniform mat4 TextureMatrix;\n";
|
uniform mat4 TextureMatrix;
|
||||||
|
|
||||||
// light buffers
|
// light buffers
|
||||||
i_data += "#ifdef SHADER_STORAGE_LIGHTS\n";
|
#ifdef SHADER_STORAGE_LIGHTS
|
||||||
i_data += "layout(std430, binding = 1) buffer LightBufferSSO\n";
|
layout(std430, binding = 1) buffer LightBufferSSO
|
||||||
i_data += "{\n";
|
{
|
||||||
i_data += " vec4 lights[];\n";
|
vec4 lights[];
|
||||||
i_data += "};\n";
|
};
|
||||||
i_data += "#elif defined NUM_UBO_LIGHTS\n";
|
#elif defined NUM_UBO_LIGHTS
|
||||||
i_data += "uniform LightBufferUBO\n";
|
uniform LightBufferUBO
|
||||||
i_data += "{\n";
|
{
|
||||||
i_data += " vec4 lights[NUM_UBO_LIGHTS];\n";
|
vec4 lights[NUM_UBO_LIGHTS];
|
||||||
i_data += "};\n";
|
};
|
||||||
i_data += "#endif\n";
|
#endif
|
||||||
|
|
||||||
// textures
|
// textures
|
||||||
i_data += "uniform sampler2D tex;\n";
|
uniform sampler2D tex;
|
||||||
i_data += "uniform sampler2D ShadowMap;\n";
|
uniform sampler2D ShadowMap;
|
||||||
i_data += "uniform sampler2D texture2;\n";
|
uniform sampler2D texture2;
|
||||||
i_data += "uniform sampler2D texture3;\n";
|
uniform sampler2D texture3;
|
||||||
i_data += "uniform sampler2D texture4;\n";
|
uniform sampler2D texture4;
|
||||||
i_data += "uniform sampler2D texture5;\n";
|
uniform sampler2D texture5;
|
||||||
i_data += "uniform sampler2D texture6;\n";
|
uniform sampler2D texture6;
|
||||||
i_data += "uniform sampler2D texture7;\n";
|
uniform sampler2D texture7;
|
||||||
i_data += "uniform sampler2D texture8;\n";
|
uniform sampler2D texture8;
|
||||||
|
|
||||||
// timer data
|
// timer data
|
||||||
i_data += "uniform float timer;\n";
|
uniform float timer;
|
||||||
|
|
||||||
// material types
|
// material types
|
||||||
i_data += "#if defined(SPECULAR)\n";
|
#if defined(SPECULAR)
|
||||||
i_data += "#define normaltexture texture2\n";
|
#define normaltexture texture2
|
||||||
i_data += "#define speculartexture texture3\n";
|
#define speculartexture texture3
|
||||||
i_data += "#define brighttexture texture4\n";
|
#define brighttexture texture4
|
||||||
i_data += "#define detailtexture texture5\n";
|
#define detailtexture texture5
|
||||||
i_data += "#define glowtexture texture6\n";
|
#define glowtexture texture6
|
||||||
i_data += "#elif defined(PBR)\n";
|
#elif defined(PBR)
|
||||||
i_data += "#define normaltexture texture2\n";
|
#define normaltexture texture2
|
||||||
i_data += "#define metallictexture texture3\n";
|
#define metallictexture texture3
|
||||||
i_data += "#define roughnesstexture texture4\n";
|
#define roughnesstexture texture4
|
||||||
i_data += "#define aotexture texture5\n";
|
#define aotexture texture5
|
||||||
i_data += "#define brighttexture texture6\n";
|
#define brighttexture texture6
|
||||||
i_data += "#define detailtexture texture7\n";
|
#define detailtexture texture7
|
||||||
i_data += "#define glowtexture texture8\n";
|
#define glowtexture texture8
|
||||||
i_data += "#else\n";
|
#else
|
||||||
i_data += "#define brighttexture texture2\n";
|
#define brighttexture texture2
|
||||||
i_data += "#define detailtexture texture3\n";
|
#define detailtexture texture3
|
||||||
i_data += "#define glowtexture texture4\n";
|
#define glowtexture texture4
|
||||||
i_data += "#endif\n";
|
#endif
|
||||||
|
|
||||||
|
)";
|
||||||
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// The noise functions are completely broken in macOS OpenGL drivers
|
// The noise functions are completely broken in macOS OpenGL drivers
|
||||||
|
@ -342,6 +344,10 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
i_data += "#define noise4(unused) vec4(0)\n";
|
i_data += "#define noise4(unused) vec4(0)\n";
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
i_data += "#define NPOT_EMULATION\nuniform vec2 uNpotEmulation;\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
|
int vp_lump = fileSystem.CheckNumForFullName(vert_prog_lump, 0);
|
||||||
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump);
|
if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump);
|
||||||
FileData vp_data = fileSystem.ReadFile(vp_lump);
|
FileData vp_data = fileSystem.ReadFile(vp_lump);
|
||||||
|
@ -577,6 +583,9 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
muSplitBottomPlane.Init(hShader, "uSplitBottomPlane");
|
muSplitBottomPlane.Init(hShader, "uSplitBottomPlane");
|
||||||
muSplitTopPlane.Init(hShader, "uSplitTopPlane");
|
muSplitTopPlane.Init(hShader, "uSplitTopPlane");
|
||||||
muDetailParms.Init(hShader, "uDetailParms");
|
muDetailParms.Init(hShader, "uDetailParms");
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
muNpotEmulation.Init(hShader, "uNpotEmulation");
|
||||||
|
#endif
|
||||||
muInterpolationFactor.Init(hShader, "uInterpolationFactor");
|
muInterpolationFactor.Init(hShader, "uInterpolationFactor");
|
||||||
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
|
muAlphaThreshold.Init(hShader, "uAlphaThreshold");
|
||||||
muSpecularMaterial.Init(hShader, "uSpecularMaterial");
|
muSpecularMaterial.Init(hShader, "uSpecularMaterial");
|
||||||
|
|
|
@ -262,6 +262,9 @@ class FShader
|
||||||
FBufferedUniform1f muAlphaThreshold;
|
FBufferedUniform1f muAlphaThreshold;
|
||||||
FBufferedUniform2f muSpecularMaterial;
|
FBufferedUniform2f muSpecularMaterial;
|
||||||
FBufferedUniform1f muTimer;
|
FBufferedUniform1f muTimer;
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
FBufferedUniform2f muNpotEmulation;
|
||||||
|
#endif
|
||||||
|
|
||||||
int lights_index;
|
int lights_index;
|
||||||
int modelmatrix_index;
|
int modelmatrix_index;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "hw_material.h"
|
#include "hw_material.h"
|
||||||
#include "texmanip.h"
|
#include "texmanip.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
struct FColormap;
|
struct FColormap;
|
||||||
class IVertexBuffer;
|
class IVertexBuffer;
|
||||||
|
@ -198,6 +199,9 @@ struct StreamData
|
||||||
FVector4 uSplitBottomPlane;
|
FVector4 uSplitBottomPlane;
|
||||||
|
|
||||||
FVector4 uDetailParms;
|
FVector4 uDetailParms;
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
FVector2 uNpotEmulation;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class FRenderState
|
class FRenderState
|
||||||
|
@ -289,7 +293,9 @@ public:
|
||||||
mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
mStreamData.uDynLightColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
mStreamData.uDynLightColor = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
mStreamData.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
|
mStreamData.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
mStreamData.uNpotEmulation = { 0,0 };
|
||||||
|
#endif
|
||||||
mModelMatrix.loadIdentity();
|
mModelMatrix.loadIdentity();
|
||||||
mTextureMatrix.loadIdentity();
|
mTextureMatrix.loadIdentity();
|
||||||
ClearClipSplit();
|
ClearClipSplit();
|
||||||
|
@ -472,6 +478,13 @@ public:
|
||||||
mStreamData.uAddColor = pe;
|
mStreamData.uAddColor = pe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetNpotEmulation(float factor, float offset)
|
||||||
|
{
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
mStreamData.uNpotEmulation = { offset, factor };
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void ApplyTextureManipulation(TextureManipulation* texfx)
|
void ApplyTextureManipulation(TextureManipulation* texfx)
|
||||||
{
|
{
|
||||||
if (!texfx || texfx->AddColor.a == 0)
|
if (!texfx || texfx->AddColor.a == 0)
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "hw_shaderpatcher.h"
|
#include "hw_shaderpatcher.h"
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "engineerrors.h"
|
#include "engineerrors.h"
|
||||||
|
#include "version.h"
|
||||||
#include <ShaderLang.h>
|
#include <ShaderLang.h>
|
||||||
|
|
||||||
VkShaderManager::VkShaderManager(VulkanDevice *device) : device(device)
|
VkShaderManager::VkShaderManager(VulkanDevice *device) : device(device)
|
||||||
|
@ -162,6 +163,9 @@ static const char *shaderBindings = R"(
|
||||||
vec4 uSplitBottomPlane;
|
vec4 uSplitBottomPlane;
|
||||||
|
|
||||||
vec4 uDetailParms;
|
vec4 uDetailParms;
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
vec2 uNpotEmulation;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(set = 0, binding = 3, std140) uniform StreamUBO {
|
layout(set = 0, binding = 3, std140) uniform StreamUBO {
|
||||||
|
@ -248,6 +252,7 @@ static const char *shaderBindings = R"(
|
||||||
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
|
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
|
||||||
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
|
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
|
||||||
#define uDetailParms data[uDataIndex].uDetailParms
|
#define uDetailParms data[uDataIndex].uDetailParms
|
||||||
|
#define uNpotEmulation data[uDataIndex].uNpotEmulation
|
||||||
|
|
||||||
#define SUPPORTS_SHADOWMAPS
|
#define SUPPORTS_SHADOWMAPS
|
||||||
#define VULKAN_COORDINATE_SYSTEM
|
#define VULKAN_COORDINATE_SYSTEM
|
||||||
|
@ -270,6 +275,9 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
|
||||||
FString code = GetTargetGlslVersion();
|
FString code = GetTargetGlslVersion();
|
||||||
code << defines;
|
code << defines;
|
||||||
code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
|
code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
code << "#define NPOT_EMULATION\n"
|
||||||
|
#endif
|
||||||
code << shaderBindings;
|
code << shaderBindings;
|
||||||
if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n";
|
if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n";
|
||||||
code << "#line 1\n";
|
code << "#line 1\n";
|
||||||
|
|
|
@ -175,6 +175,10 @@ static const uint8_t renderwalltotier[] =
|
||||||
side_t::mid,
|
side_t::mid,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
CVAR(Bool, hw_npottest, false, 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
|
void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
|
||||||
{
|
{
|
||||||
int tmode = state.GetTextureMode();
|
int tmode = state.GetTextureMode();
|
||||||
|
@ -187,6 +191,23 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
|
||||||
SetGlowPlanes(state, frontsector->ceilingplane, frontsector->floorplane);
|
SetGlowPlanes(state, frontsector->ceilingplane, frontsector->floorplane);
|
||||||
}
|
}
|
||||||
state.SetMaterial(texture, UF_Texture, 0, flags & 3, 0, -1);
|
state.SetMaterial(texture, UF_Texture, 0, flags & 3, 0, -1);
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
// Test code, could be reactivated as a compatibility option in the unlikely event that some old vanilla map eve needs it.
|
||||||
|
if (hw_npottest)
|
||||||
|
{
|
||||||
|
int32_t size = xs_CRoundToInt(texture->GetDisplayHeight());
|
||||||
|
int32_t size2;
|
||||||
|
for (size2 = 1; size2 < size; size2 += size2) {}
|
||||||
|
if (size == size2)
|
||||||
|
state.SetNpotEmulation(0.f, 0.f);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float xOffset = 1.f / texture->GetDisplayWidth();
|
||||||
|
state.SetNpotEmulation((1.f * size2) / size, xOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (type == RENDERWALL_M2SNF)
|
if (type == RENDERWALL_M2SNF)
|
||||||
{
|
{
|
||||||
|
@ -274,6 +295,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
|
||||||
|
|
||||||
state.EnableSplit(false);
|
state.EnableSplit(false);
|
||||||
}
|
}
|
||||||
|
state.SetNpotEmulation(0.f, 0.f);
|
||||||
state.SetObjectColor(0xffffffff);
|
state.SetObjectColor(0xffffffff);
|
||||||
state.SetObjectColor2(0);
|
state.SetObjectColor2(0);
|
||||||
state.SetAddColor(0);
|
state.SetAddColor(0);
|
||||||
|
|
|
@ -540,6 +540,14 @@ vec3 ApplyNormalMap(vec2 texcoord)
|
||||||
|
|
||||||
void SetMaterialProps(inout Material material, vec2 texCoord)
|
void SetMaterialProps(inout Material material, vec2 texCoord)
|
||||||
{
|
{
|
||||||
|
#ifdef NPOT_EMULATION
|
||||||
|
if (uNpotEmulation.y != 0.0)
|
||||||
|
{
|
||||||
|
float period = floor(texCoord.t / uNpotEmulation.y);
|
||||||
|
texCoord.s += uNpotEmulation.x * floor(mod(texCoord.t, uNpotEmulation.y));
|
||||||
|
texCoord.t = period + mod(texCoord.t, uNpotEmulation.y);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
material.Base = getTexel(texCoord.st);
|
material.Base = getTexel(texCoord.st);
|
||||||
material.Normal = ApplyNormalMap(texCoord.st);
|
material.Normal = ApplyNormalMap(texCoord.st);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue