Rename StreamData to SurfaceUniforms

This commit is contained in:
Magnus Norddahl 2023-10-20 16:42:25 +02:00
commit e713299410
15 changed files with 222 additions and 263 deletions

View file

@ -172,6 +172,51 @@ struct LevelMeshSurfaceStats
Stats surfaces, pixels;
};
struct SurfaceUniforms
{
FVector4 uObjectColor;
FVector4 uObjectColor2;
FVector4 uDynLightColor;
FVector4 uAddColor;
FVector4 uTextureAddColor;
FVector4 uTextureModulateColor;
FVector4 uTextureBlendColor;
FVector4 uFogColor;
float uDesaturationFactor; // HWDrawInfo::SetColor
float uInterpolationFactor;
float timer;
int useVertexData;
FVector4 uVertexColor; // HWDrawInfo::SetColor
FVector4 uVertexNormal;
FVector4 uGlowTopPlane;
FVector4 uGlowTopColor;
FVector4 uGlowBottomPlane;
FVector4 uGlowBottomColor;
FVector4 uGradientTopPlane;
FVector4 uGradientBottomPlane;
FVector4 uSplitTopPlane;
FVector4 uSplitBottomPlane;
FVector4 uDetailParms;
FVector4 uNpotEmulation;
FVector2 uClipSplit;
FVector2 uSpecularMaterial;
float uLightLevel; // HWDrawInfo::SetColor
float uFogDensity;
float uLightFactor;
float uLightDist;
float uAlphaThreshold;
int uTextureIndex;
float padding2;
float padding3;
};
class LevelSubmesh
{
public:

View file

@ -35,13 +35,13 @@ void Mesh::Draw(FRenderState& renderstate)
origState.applyData.RenderStyle = renderstate.mRenderStyle;
origState.applyData.SpecialEffect = renderstate.mSpecialEffect;
origState.applyData.TextureEnabled = renderstate.mTextureEnabled;
origState.applyData.AlphaThreshold = renderstate.mStreamData.uAlphaThreshold;
origState.applyData.AlphaThreshold = renderstate.mSurfaceUniforms.uAlphaThreshold;
origState.applyData.FogEnabled = renderstate.mFogEnabled;
origState.applyData.BrightmapEnabled = renderstate.mBrightmapEnabled;
origState.applyData.TextureClamp = renderstate.mTextureClamp;
origState.applyData.TextureMode = renderstate.mTextureMode;
origState.applyData.TextureModeFlags = renderstate.mTextureModeFlags;
origState.streamData = renderstate.mStreamData;
origState.surfaceUniforms = renderstate.mSurfaceUniforms;
origState.material = renderstate.mMaterial;
origState.textureMatrix.loadIdentity();
@ -106,7 +106,7 @@ void Mesh::Apply(FRenderState& renderstate, const MeshApplyState& state)
renderstate.mTextureClamp = state.applyData.TextureClamp;
renderstate.mTextureMode = state.applyData.TextureMode;
renderstate.mTextureModeFlags = state.applyData.TextureModeFlags;
renderstate.mStreamData = state.streamData;
renderstate.mSurfaceUniforms = state.surfaceUniforms;
renderstate.mMaterial = state.material;
renderstate.SetTextureMatrix(state.textureMatrix);
}

View file

@ -63,18 +63,18 @@ void MeshBuilder::Apply()
state.applyData.RenderStyle = mRenderStyle;
state.applyData.SpecialEffect = mSpecialEffect;
state.applyData.TextureEnabled = mTextureEnabled;
state.applyData.AlphaThreshold = mStreamData.uAlphaThreshold;
state.applyData.AlphaThreshold = mSurfaceUniforms.uAlphaThreshold;
state.applyData.DepthFunc = mDepthFunc;
state.applyData.FogEnabled = mFogEnabled;
state.applyData.BrightmapEnabled = mBrightmapEnabled;
state.applyData.TextureClamp = mTextureClamp;
state.applyData.TextureMode = mTextureMode;
state.applyData.TextureModeFlags = mTextureModeFlags;
state.streamData = mStreamData;
state.surfaceUniforms = mSurfaceUniforms;
state.material = mMaterial;
state.textureMatrix = mTextureMatrix;
state.streamData.uVertexNormal = FVector4(0.0f, 0.0f, 0.0f, 0.0f); // Grr, this should be part of the vertex!!
state.surfaceUniforms.uVertexNormal = FVector4(0.0f, 0.0f, 0.0f, 0.0f); // Grr, this should be part of the vertex!!
mDrawLists = &mSortedLists[state];
}

View file

@ -25,7 +25,7 @@ public:
};
ApplyData applyData;
StreamData streamData;
SurfaceUniforms surfaceUniforms;
FMaterialState material;
VSMatrix textureMatrix;
@ -48,7 +48,7 @@ public:
if (result != 0)
return result < 0;
result = memcmp(&streamData, &other.streamData, sizeof(StreamData));
result = memcmp(&surfaceUniforms, &other.surfaceUniforms, sizeof(SurfaceUniforms));
return result < 0;
}
};

View file

@ -134,95 +134,7 @@ enum EPassType
MAX_PASS_TYPES
};
struct FVector4PalEntry
{
float r, g, b, a;
bool operator==(const FVector4PalEntry &other) const
{
return r == other.r && g == other.g && b == other.b && a == other.a;
}
bool operator!=(const FVector4PalEntry &other) const
{
return r != other.r || g != other.g || b != other.b || a != other.a;
}
FVector4PalEntry &operator=(PalEntry newvalue)
{
const float normScale = 1.0f / 255.0f;
r = newvalue.r * normScale;
g = newvalue.g * normScale;
b = newvalue.b * normScale;
a = newvalue.a * normScale;
return *this;
}
FVector4PalEntry& SetIA(PalEntry newvalue)
{
const float normScale = 1.0f / 255.0f;
r = newvalue.r * normScale;
g = newvalue.g * normScale;
b = newvalue.b * normScale;
a = newvalue.a;
return *this;
}
FVector4PalEntry& SetFlt(float v1, float v2, float v3, float v4)
{
r = v1;
g = v2;
b = v3;
a = v4;
return *this;
}
};
struct StreamData
{
FVector4PalEntry uObjectColor;
FVector4PalEntry uObjectColor2;
FVector4 uDynLightColor;
FVector4PalEntry uAddColor;
FVector4PalEntry uTextureAddColor;
FVector4PalEntry uTextureModulateColor;
FVector4PalEntry uTextureBlendColor;
FVector4PalEntry uFogColor;
float uDesaturationFactor; // HWDrawInfo::SetColor
float uInterpolationFactor;
float timer;
int useVertexData;
FVector4 uVertexColor; // HWDrawInfo::SetColor
FVector4 uVertexNormal;
FVector4 uGlowTopPlane;
FVector4 uGlowTopColor;
FVector4 uGlowBottomPlane;
FVector4 uGlowBottomColor;
FVector4 uGradientTopPlane;
FVector4 uGradientBottomPlane;
FVector4 uSplitTopPlane;
FVector4 uSplitBottomPlane;
FVector4 uDetailParms;
FVector4 uNpotEmulation;
FVector2 uClipSplit;
FVector2 uSpecularMaterial;
float uLightLevel; // HWDrawInfo::SetColor
float uFogDensity;
float uLightFactor;
float uLightDist;
float uAlphaThreshold;
float padding1;
float padding2;
float padding3;
};
inline FVector4 toFVector4(PalEntry pe) { const float normScale = 1.0f / 255.0f; return FVector4(pe.r * normScale, pe.g * normScale, pe.b * normScale, pe.a * normScale); }
struct Fogball
{
@ -255,7 +167,7 @@ protected:
int mColorMapSpecial;
float mColorMapFlash;
StreamData mStreamData = {};
SurfaceUniforms mSurfaceUniforms = {};
PalEntry mFogColor;
FRenderStyle mRenderStyle;
@ -278,29 +190,29 @@ public:
mTextureEnabled = true;
mBrightmapEnabled = mGradientEnabled = mFogEnabled = mGlowEnabled = false;
mFogColor = 0xffffffff;
mStreamData.uFogColor = mFogColor;
mSurfaceUniforms.uFogColor = toFVector4(mFogColor);
mTextureMode = -1;
mTextureClamp = 0;
mTextureModeFlags = 0;
mStreamData.uDesaturationFactor = 0.0f;
mStreamData.uAlphaThreshold = 0.5f;
mSurfaceUniforms.uDesaturationFactor = 0.0f;
mSurfaceUniforms.uAlphaThreshold = 0.5f;
mSplitEnabled = false;
mStreamData.uAddColor = 0;
mStreamData.uObjectColor = 0xffffffff;
mStreamData.uObjectColor2 = 0;
mStreamData.uTextureBlendColor = 0;
mStreamData.uTextureAddColor = 0;
mStreamData.uTextureModulateColor = 0;
mSurfaceUniforms.uAddColor = toFVector4(PalEntry(0));
mSurfaceUniforms.uObjectColor = toFVector4(PalEntry(0xffffffff));
mSurfaceUniforms.uObjectColor2 = toFVector4(PalEntry(0));
mSurfaceUniforms.uTextureBlendColor = toFVector4(PalEntry(0));
mSurfaceUniforms.uTextureAddColor = toFVector4(PalEntry(0));
mSurfaceUniforms.uTextureModulateColor = toFVector4(PalEntry(0));
mSoftLight = 0;
mStreamData.uLightDist = 0.0f;
mStreamData.uLightFactor = 0.0f;
mStreamData.uFogDensity = 0.0f;
mStreamData.uLightLevel = -1.0f;
mSurfaceUniforms.uLightDist = 0.0f;
mSurfaceUniforms.uLightFactor = 0.0f;
mSurfaceUniforms.uFogDensity = 0.0f;
mSurfaceUniforms.uLightLevel = -1.0f;
mSpecialEffect = EFF_NONE;
mLightIndex = -1;
mBoneIndexBase = -1;
mFogballIndex = -1;
mStreamData.uInterpolationFactor = 0;
mSurfaceUniforms.uInterpolationFactor = 0;
mRenderStyle = DefaultRenderStyle();
mMaterial.Reset();
mBias.Reset();
@ -313,57 +225,57 @@ public:
mVertexOffsets[0] = mVertexOffsets[1] = 0;
mIndexBuffer = nullptr;
mStreamData.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
mStreamData.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGlowTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGlowBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGradientTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGradientBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uSplitTopPlane = { 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, 1.0f };
mStreamData.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
mSurfaceUniforms.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGlowTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGlowBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGradientTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGradientBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uDynLightColor = { 0.0f, 0.0f, 0.0f, 1.0f };
mSurfaceUniforms.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
#ifdef NPOT_EMULATION
mStreamData.uNpotEmulation = { 0,0,0,0 };
mSurfaceUniforms.uNpotEmulation = { 0,0,0,0 };
#endif
ClearClipSplit();
}
void SetNormal(FVector3 norm)
{
mStreamData.uVertexNormal = { norm.X, norm.Y, norm.Z, 0.f };
mSurfaceUniforms.uVertexNormal = { norm.X, norm.Y, norm.Z, 0.f };
}
void SetNormal(float x, float y, float z)
{
mStreamData.uVertexNormal = { x, y, z, 0.f };
mSurfaceUniforms.uVertexNormal = { x, y, z, 0.f };
}
void SetColor(float r, float g, float b, float a = 1.f, int desat = 0)
{
mStreamData.uVertexColor = { r, g, b, a };
mStreamData.uDesaturationFactor = desat * (1.0f / 255.0f);
mSurfaceUniforms.uVertexColor = { r, g, b, a };
mSurfaceUniforms.uDesaturationFactor = desat * (1.0f / 255.0f);
}
void SetColor(PalEntry pe, int desat = 0)
{
const float scale = 1.0f / 255.0f;
mStreamData.uVertexColor = { pe.r * scale, pe.g * scale, pe.b * scale, pe.a * scale };
mStreamData.uDesaturationFactor = desat * (1.0f / 255.0f);
mSurfaceUniforms.uVertexColor = { pe.r * scale, pe.g * scale, pe.b * scale, pe.a * scale };
mSurfaceUniforms.uDesaturationFactor = desat * (1.0f / 255.0f);
}
void SetColorAlpha(PalEntry pe, float alpha = 1.f, int desat = 0)
{
const float scale = 1.0f / 255.0f;
mStreamData.uVertexColor = { pe.r * scale, pe.g * scale, pe.b * scale, alpha };
mStreamData.uDesaturationFactor = desat * (1.0f / 255.0f);
mSurfaceUniforms.uVertexColor = { pe.r * scale, pe.g * scale, pe.b * scale, alpha };
mSurfaceUniforms.uDesaturationFactor = desat * (1.0f / 255.0f);
}
void ResetColor()
{
mStreamData.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
mStreamData.uDesaturationFactor = 0.0f;
mSurfaceUniforms.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
mSurfaceUniforms.uDesaturationFactor = 0.0f;
}
void SetTextureClamp(bool on)
@ -425,8 +337,8 @@ public:
{
if (mGlowEnabled && !on)
{
mStreamData.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
}
mGlowEnabled = on;
}
@ -445,27 +357,27 @@ public:
{
if (mSplitEnabled && !on)
{
mStreamData.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
mSurfaceUniforms.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
}
mSplitEnabled = on;
}
void SetGlowParams(float *t, float *b)
{
mStreamData.uGlowTopColor = { t[0], t[1], t[2], t[3] };
mStreamData.uGlowBottomColor = { b[0], b[1], b[2], b[3] };
mSurfaceUniforms.uGlowTopColor = { t[0], t[1], t[2], t[3] };
mSurfaceUniforms.uGlowBottomColor = { b[0], b[1], b[2], b[3] };
}
void SetSoftLightLevel(int llevel, int blendfactor = 0)
{
if (blendfactor == 0) mStreamData.uLightLevel = llevel / 255.f;
else mStreamData.uLightLevel = -1.f;
if (blendfactor == 0) mSurfaceUniforms.uLightLevel = llevel / 255.f;
else mSurfaceUniforms.uLightLevel = -1.f;
}
void SetNoSoftLightLevel()
{
mStreamData.uLightLevel = -1.f;
mSurfaceUniforms.uLightLevel = -1.f;
}
void SetLightMode(int lightmode)
@ -475,59 +387,59 @@ public:
void SetGlowPlanes(const FVector4 &tp, const FVector4& bp)
{
mStreamData.uGlowTopPlane = tp;
mStreamData.uGlowBottomPlane = bp;
mSurfaceUniforms.uGlowTopPlane = tp;
mSurfaceUniforms.uGlowBottomPlane = bp;
}
void SetGradientPlanes(const FVector4& tp, const FVector4& bp)
{
mStreamData.uGradientTopPlane = tp;
mStreamData.uGradientBottomPlane = bp;
mSurfaceUniforms.uGradientTopPlane = tp;
mSurfaceUniforms.uGradientBottomPlane = bp;
}
void SetSplitPlanes(const FVector4& tp, const FVector4& bp)
{
mStreamData.uSplitTopPlane = tp;
mStreamData.uSplitBottomPlane = bp;
mSurfaceUniforms.uSplitTopPlane = tp;
mSurfaceUniforms.uSplitBottomPlane = bp;
}
void SetDetailParms(float xscale, float yscale, float bias)
{
mStreamData.uDetailParms = { xscale, yscale, bias, 0 };
mSurfaceUniforms.uDetailParms = { xscale, yscale, bias, 0 };
}
void SetDynLight(float r, float g, float b)
{
mStreamData.uDynLightColor.X = r;
mStreamData.uDynLightColor.Y = g;
mStreamData.uDynLightColor.Z = b;
mSurfaceUniforms.uDynLightColor.X = r;
mSurfaceUniforms.uDynLightColor.Y = g;
mSurfaceUniforms.uDynLightColor.Z = b;
}
void SetScreenFade(float f)
{
// This component is otherwise unused.
mStreamData.uDynLightColor.W = f;
mSurfaceUniforms.uDynLightColor.W = f;
}
void SetObjectColor(PalEntry pe)
{
mStreamData.uObjectColor = pe;
mSurfaceUniforms.uObjectColor = toFVector4(pe);
}
void SetObjectColor2(PalEntry pe)
{
mStreamData.uObjectColor2 = pe;
mSurfaceUniforms.uObjectColor2 = toFVector4(pe);
}
void SetAddColor(PalEntry pe)
{
mStreamData.uAddColor = pe;
mSurfaceUniforms.uAddColor = toFVector4(pe);
}
void SetNpotEmulation(float factor, float offset)
{
#ifdef NPOT_EMULATION
mStreamData.uNpotEmulation = { offset, factor, 0, 0 };
mSurfaceUniforms.uNpotEmulation = { offset, factor, 0, 0 };
#endif
}
@ -535,36 +447,37 @@ public:
{
if (!texfx || texfx->AddColor.a == 0)
{
mStreamData.uTextureAddColor.a = 0; // we only need to set the flags to 0
mSurfaceUniforms.uTextureAddColor.W = 0.0f; // we only need to set the flags to 0
}
else
{
// set up the whole thing
mStreamData.uTextureAddColor.SetIA(texfx->AddColor);
const float normScale = 1.0f / 255.0f;
mSurfaceUniforms.uTextureAddColor = FVector4(texfx->AddColor.r * normScale, texfx->AddColor.g * normScale, texfx->AddColor.b * normScale, texfx->AddColor.a);
auto pe = texfx->ModulateColor;
mStreamData.uTextureModulateColor.SetFlt(pe.r * pe.a / 255.f, pe.g * pe.a / 255.f, pe.b * pe.a / 255.f, texfx->DesaturationFactor);
mStreamData.uTextureBlendColor = texfx->BlendColor;
mSurfaceUniforms.uTextureModulateColor = FVector4(pe.r * pe.a / 255.f, pe.g * pe.a / 255.f, pe.b * pe.a / 255.f, texfx->DesaturationFactor);
mSurfaceUniforms.uTextureBlendColor = toFVector4(texfx->BlendColor);
}
}
void SetTextureColors(float* modColor, float* addColor, float* blendColor)
{
mStreamData.uTextureAddColor.SetFlt(addColor[0], addColor[1], addColor[2], addColor[3]);
mStreamData.uTextureModulateColor.SetFlt(modColor[0], modColor[1], modColor[2], modColor[3]);
mStreamData.uTextureBlendColor.SetFlt(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
mSurfaceUniforms.uTextureAddColor = FVector4(addColor[0], addColor[1], addColor[2], addColor[3]);
mSurfaceUniforms.uTextureModulateColor = FVector4(modColor[0], modColor[1], modColor[2], modColor[3]);
mSurfaceUniforms.uTextureBlendColor = FVector4(blendColor[0], blendColor[1], blendColor[2], blendColor[3]);
}
void SetFog(PalEntry c, float d)
{
const float LOG2E = 1.442692f; // = 1/log(2)
mFogColor = c;
mStreamData.uFogColor = mFogColor;
if (d >= 0.0f) mStreamData.uFogDensity = d * (-LOG2E / 64000.f);
mSurfaceUniforms.uFogColor = toFVector4(mFogColor);
if (d >= 0.0f) mSurfaceUniforms.uFogDensity = d * (-LOG2E / 64000.f);
}
void SetLightParms(float f, float d)
{
mStreamData.uLightFactor = f;
mStreamData.uLightDist = d;
mSurfaceUniforms.uLightFactor = f;
mSurfaceUniforms.uLightDist = d;
}
PalEntry GetFogColor() const
@ -574,8 +487,8 @@ public:
void AlphaFunc(int func, float thresh)
{
if (func == Alpha_Greater) mStreamData.uAlphaThreshold = thresh;
else mStreamData.uAlphaThreshold = thresh - 0.001f;
if (func == Alpha_Greater) mSurfaceUniforms.uAlphaThreshold = thresh;
else mSurfaceUniforms.uAlphaThreshold = thresh - 0.001f;
}
void SetLightIndex(int index)
@ -637,7 +550,7 @@ private:
mMaterial.mChanged = true;
mTextureModeFlags = mat->GetLayerFlags();
auto scale = mat->GetDetailScale();
mStreamData.uDetailParms = { scale.X, scale.Y, 2, 0 };
mSurfaceUniforms.uDetailParms = { scale.X, scale.Y, 2, 0 };
}
public:
@ -655,26 +568,26 @@ public:
void SetClipSplit(float bottom, float top)
{
mStreamData.uClipSplit.X = bottom;
mStreamData.uClipSplit.Y = top;
mSurfaceUniforms.uClipSplit.X = bottom;
mSurfaceUniforms.uClipSplit.Y = top;
}
void SetClipSplit(float *vals)
{
mStreamData.uClipSplit.X = vals[0];
mStreamData.uClipSplit.Y = vals[1];
mSurfaceUniforms.uClipSplit.X = vals[0];
mSurfaceUniforms.uClipSplit.Y = vals[1];
}
void GetClipSplit(float *out)
{
out[0] = mStreamData.uClipSplit.X;
out[1] = mStreamData.uClipSplit.Y;
out[0] = mSurfaceUniforms.uClipSplit.X;
out[1] = mSurfaceUniforms.uClipSplit.Y;
}
void ClearClipSplit()
{
mStreamData.uClipSplit.X = -1000000.f;
mStreamData.uClipSplit.Y = 1000000.f;
mSurfaceUniforms.uClipSplit.X = -1000000.f;
mSurfaceUniforms.uClipSplit.Y = 1000000.f;
}
void SetVertexBuffer(IBuffer* vb, int offset0 = 0, int offset1 = 0)
@ -697,12 +610,12 @@ public:
void SetInterpolationFactor(float fac)
{
mStreamData.uInterpolationFactor = fac;
mSurfaceUniforms.uInterpolationFactor = fac;
}
float GetInterpolationFactor()
{
return mStreamData.uInterpolationFactor;
return mSurfaceUniforms.uInterpolationFactor;
}
void EnableDrawBufferAttachments(bool on) // Used by fog boundary drawer

View file

@ -57,7 +57,7 @@ VkRSBuffers::VkRSBuffers(VulkanRenderDevice* fb)
.Create(fb->GetDevice());
MatrixBuffer = std::make_unique<VkMatrixBufferWriter>(fb);
StreamBuffer = std::make_unique<VkStreamBufferWriter>(fb);
SurfaceUniformsBuffer = std::make_unique<VkSurfaceUniformsBufferWriter>(fb);
Viewpoint.BlockAlign = (sizeof(HWViewpointUniforms) + fb->uniformblockalignment - 1) / fb->uniformblockalignment * fb->uniformblockalignment;
@ -166,30 +166,30 @@ uint32_t VkStreamBuffer::NextStreamDataBlock()
/////////////////////////////////////////////////////////////////////////////
VkStreamBufferWriter::VkStreamBufferWriter(VulkanRenderDevice* fb)
VkSurfaceUniformsBufferWriter::VkSurfaceUniformsBufferWriter(VulkanRenderDevice* fb)
{
mBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(StreamUBO), 300);
mBuffer = std::make_unique<VkStreamBuffer>(fb, sizeof(SurfaceUniformsUBO), 300);
}
bool VkStreamBufferWriter::Write(const StreamData& data)
bool VkSurfaceUniformsBufferWriter::Write(const SurfaceUniforms& data)
{
mDataIndex++;
if (mDataIndex == MAX_STREAM_DATA)
if (mDataIndex == MAX_SURFACE_UNIFORMS)
{
mDataIndex = 0;
mStreamDataOffset = mBuffer->NextStreamDataBlock();
if (mStreamDataOffset == 0xffffffff)
mOffset = mBuffer->NextStreamDataBlock();
if (mOffset == 0xffffffff)
return false;
}
uint8_t* ptr = (uint8_t*)mBuffer->Data;
memcpy(ptr + mStreamDataOffset + sizeof(StreamData) * mDataIndex, &data, sizeof(StreamData));
memcpy(ptr + mOffset + sizeof(SurfaceUniforms) * mDataIndex, &data, sizeof(SurfaceUniforms));
return true;
}
void VkStreamBufferWriter::Reset()
void VkSurfaceUniformsBufferWriter::Reset()
{
mDataIndex = MAX_STREAM_DATA - 1;
mStreamDataOffset = 0;
mDataIndex = MAX_SURFACE_UNIFORMS - 1;
mOffset = 0;
mBuffer->Reset();
}

View file

@ -5,7 +5,7 @@
#include "vulkan/shaders/vk_shader.h"
class VkMatrixBufferWriter;
class VkStreamBufferWriter;
class VkSurfaceUniformsBufferWriter;
struct FFlatVertex;
class VkRSBuffers
@ -60,7 +60,7 @@ public:
} Fogballbuffer;
std::unique_ptr<VkMatrixBufferWriter> MatrixBuffer;
std::unique_ptr<VkStreamBufferWriter> StreamBuffer;
std::unique_ptr<VkSurfaceUniformsBufferWriter> SurfaceUniformsBuffer;
};
class VkStreamBuffer
@ -80,23 +80,23 @@ private:
uint32_t mStreamDataOffset = 0;
};
class VkStreamBufferWriter
class VkSurfaceUniformsBufferWriter
{
public:
VkStreamBufferWriter(VulkanRenderDevice* fb);
VkSurfaceUniformsBufferWriter(VulkanRenderDevice* fb);
bool Write(const StreamData& data);
bool Write(const SurfaceUniforms& data);
void Reset();
uint32_t DataIndex() const { return mDataIndex; }
uint32_t Offset() const { return mStreamDataOffset; }
uint32_t Offset() const { return mOffset; }
VulkanBuffer* UBO() const { return mBuffer->UBO.get(); }
private:
std::unique_ptr<VkStreamBuffer> mBuffer;
uint32_t mDataIndex = MAX_STREAM_DATA - 1;
uint32_t mStreamDataOffset = 0;
uint32_t mDataIndex = MAX_SURFACE_UNIFORMS - 1;
uint32_t mOffset = 0;
};
class VkMatrixBufferWriter

View file

@ -63,7 +63,7 @@ void VkDescriptorSetManager::Init()
WriteDescriptors()
.AddBuffer(rsbufferset.get(), 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Viewpoint.UBO.get(), 0, sizeof(HWViewpointUniforms))
.AddBuffer(rsbufferset.get(), 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->MatrixBuffer->UBO(), 0, sizeof(MatricesUBO))
.AddBuffer(rsbufferset.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->StreamBuffer->UBO(), 0, sizeof(StreamUBO))
.AddBuffer(rsbufferset.get(), 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->SurfaceUniformsBuffer->UBO(), 0, sizeof(SurfaceUniformsUBO))
.AddBuffer(rsbufferset.get(), 3, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Lightbuffer.UBO.get(), 0, sizeof(LightBufferUBO))
.AddBuffer(rsbufferset.get(), 4, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, rsbuffers->Fogballbuffer.UBO.get(), 0, sizeof(FogballBufferUBO))
.AddBuffer(rsbufferset.get(), 5, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, rsbuffers->Bonebuffer.SSO.get())

View file

@ -132,7 +132,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
{
FString definesBlock;
definesBlock << defines;
definesBlock << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
definesBlock << "\n#define MAX_SURFACE_UNIFORMS " << std::to_string(MAX_SURFACE_UNIFORMS).c_str() << "\n";
definesBlock << "#define MAX_LIGHT_DATA " << std::to_string(MAX_LIGHT_DATA).c_str() << "\n";
definesBlock << "#define MAX_FOGBALL_DATA " << std::to_string(MAX_FOGBALL_DATA).c_str() << "\n";
#ifdef NPOT_EMULATION
@ -170,7 +170,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
FString definesBlock;
if (fb->GetDevice()->SupportsExtension(VK_KHR_RAY_QUERY_EXTENSION_NAME) && fb->GetDevice()->PhysicalDevice.Features.RayQuery.rayQuery) definesBlock << "\n#define SUPPORTS_RAYQUERY\n";
definesBlock << defines;
definesBlock << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n";
definesBlock << "\n#define MAX_SURFACE_UNIFORMS " << std::to_string(MAX_SURFACE_UNIFORMS).c_str() << "\n";
definesBlock << "#define MAX_LIGHT_DATA " << std::to_string(MAX_LIGHT_DATA).c_str() << "\n";
definesBlock << "#define MAX_FOGBALL_DATA " << std::to_string(MAX_FOGBALL_DATA).c_str() << "\n";
#ifdef NPOT_EMULATION

View file

@ -26,11 +26,11 @@ struct MatricesUBO
VSMatrix TextureMatrix;
};
#define MAX_STREAM_DATA ((int)(65536 / sizeof(StreamData)))
#define MAX_SURFACE_UNIFORMS ((int)(65536 / sizeof(SurfaceUniforms)))
struct StreamUBO
struct SurfaceUniformsUBO
{
StreamData data[MAX_STREAM_DATA];
SurfaceUniforms data[MAX_SURFACE_UNIFORMS];
};
#define MAX_LIGHT_DATA ((int)(65536 / sizeof(FVector4)))

View file

@ -700,39 +700,39 @@ void VulkanRenderDevice::DrawLevelMesh(const HWViewpointUniforms& viewpoint)
memcpy(((char*)rsbuffers->Viewpoint.Data) + rsbuffers->Viewpoint.UploadIndex * rsbuffers->Viewpoint.BlockAlign, &viewpoint, sizeof(HWViewpointUniforms));
int viewpointIndex = rsbuffers->Viewpoint.UploadIndex++;
StreamData streamdata = {};
streamdata.uFogColor = 0xffffffff;
streamdata.uDesaturationFactor = 0.0f;
streamdata.uAlphaThreshold = 0.5f;
streamdata.uAddColor = 0;
streamdata.uObjectColor = 0xffffffff;
streamdata.uObjectColor2 = 0;
streamdata.uTextureBlendColor = 0;
streamdata.uTextureAddColor = 0;
streamdata.uTextureModulateColor = 0;
streamdata.uLightDist = 0.0f;
streamdata.uLightFactor = 0.0f;
streamdata.uFogDensity = 0.0f;
streamdata.uLightLevel = 255.0f;// -1.0f;
streamdata.uInterpolationFactor = 0;
streamdata.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
streamdata.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uGlowTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uGlowBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uGradientTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uGradientBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
streamdata.uDynLightColor = { 0.0f, 0.0f, 0.0f, 1.0f };
streamdata.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
SurfaceUniforms surfaceUniforms = {};
surfaceUniforms.uFogColor = toFVector4(PalEntry(0xffffffff));
surfaceUniforms.uDesaturationFactor = 0.0f;
surfaceUniforms.uAlphaThreshold = 0.5f;
surfaceUniforms.uAddColor = toFVector4(PalEntry(0));
surfaceUniforms.uObjectColor = toFVector4(PalEntry(0xffffffff));
surfaceUniforms.uObjectColor2 = toFVector4(PalEntry(0));
surfaceUniforms.uTextureBlendColor = toFVector4(PalEntry(0));
surfaceUniforms.uTextureAddColor = toFVector4(PalEntry(0));
surfaceUniforms.uTextureModulateColor = toFVector4(PalEntry(0));
surfaceUniforms.uLightDist = 0.0f;
surfaceUniforms.uLightFactor = 0.0f;
surfaceUniforms.uFogDensity = 0.0f;
surfaceUniforms.uLightLevel = 255.0f;// -1.0f;
surfaceUniforms.uInterpolationFactor = 0;
surfaceUniforms.uVertexColor = { 1.0f, 1.0f, 1.0f, 1.0f };
surfaceUniforms.uGlowTopColor = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uGlowBottomColor = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uGlowTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uGlowBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uGradientTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uGradientBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f };
surfaceUniforms.uDynLightColor = { 0.0f, 0.0f, 0.0f, 1.0f };
surfaceUniforms.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f };
#ifdef NPOT_EMULATION
streamdata.uNpotEmulation = { 0,0,0,0 };
surfaceUniforms.uNpotEmulation = { 0,0,0,0 };
#endif
streamdata.uClipSplit.X = -1000000.f;
streamdata.uClipSplit.Y = 1000000.f;
surfaceUniforms.uClipSplit.X = -1000000.f;
surfaceUniforms.uClipSplit.Y = 1000000.f;
rsbuffers->StreamBuffer->Write(streamdata);
rsbuffers->SurfaceUniformsBuffer->Write(surfaceUniforms);
MatricesUBO matrices = {};
matrices.ModelMatrix.loadIdentity();
@ -742,15 +742,15 @@ void VulkanRenderDevice::DrawLevelMesh(const HWViewpointUniforms& viewpoint)
uint32_t viewpointOffset = viewpointIndex * rsbuffers->Viewpoint.BlockAlign;
uint32_t matrixOffset = rsbuffers->MatrixBuffer->Offset();
uint32_t streamDataOffset = rsbuffers->StreamBuffer->Offset();
uint32_t surfaceUniformsOffset = rsbuffers->SurfaceUniformsBuffer->Offset();
uint32_t lightsOffset = 0;
uint32_t offsets[4] = { viewpointOffset, matrixOffset, streamDataOffset, lightsOffset };
uint32_t offsets[4] = { viewpointOffset, matrixOffset, surfaceUniformsOffset, lightsOffset };
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptors->GetFixedDescriptorSet());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 1, descriptors->GetRSBufferDescriptorSet(), 4, offsets);
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 2, descriptors->GetNullTextureDescriptorSet());
PushConstants pushConstants = {};
pushConstants.uDataIndex = rsbuffers->StreamBuffer->DataIndex();
pushConstants.uDataIndex = rsbuffers->SurfaceUniformsBuffer->DataIndex();
pushConstants.uLightIndex = -1;
pushConstants.uBoneIndexBase = -1;
cmdbuffer->pushConstants(layout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, (uint32_t)sizeof(PushConstants), &pushConstants);

View file

@ -194,7 +194,7 @@ void VkRenderState::Apply(int dt)
mApplyCount = 0;
}
ApplyStreamData();
ApplySurfaceUniforms();
ApplyMatrices();
ApplyRenderPass(dt);
ApplyScissor();
@ -250,7 +250,7 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ShaderKey.EffectState = mTextureEnabled ? effectState : SHADER_NoTexture;
if (r_skipmats && pipelineKey.ShaderKey.EffectState >= 3 && pipelineKey.ShaderKey.EffectState <= 4)
pipelineKey.ShaderKey.EffectState = 0;
pipelineKey.ShaderKey.AlphaTest = mStreamData.uAlphaThreshold >= 0.f;
pipelineKey.ShaderKey.AlphaTest = mSurfaceUniforms.uAlphaThreshold >= 0.f;
}
int uTextureMode = GetTextureModeAndFlags((mMaterial.mMaterial && mMaterial.mMaterial->Source()->isHardwareCanvas()) ? TM_OPAQUE : TM_NORMAL);
@ -285,7 +285,7 @@ void VkRenderState::ApplyRenderPass(int dt)
pipelineKey.ShaderKey.SWLightBanded = false; // gl_bandedswlight;
pipelineKey.ShaderKey.FogBalls = mFogballIndex >= 0;
float lightlevel = mStreamData.uLightLevel;
float lightlevel = mSurfaceUniforms.uLightLevel;
if (lightlevel < 0.0)
{
pipelineKey.ShaderKey.LightMode = 0; // Default
@ -392,33 +392,33 @@ void VkRenderState::ApplyViewport()
}
}
void VkRenderState::ApplyStreamData()
void VkRenderState::ApplySurfaceUniforms()
{
auto passManager = fb->GetRenderPassManager();
mStreamData.useVertexData = mVertexBuffer ? passManager->GetVertexFormat(static_cast<VkHardwareVertexBuffer*>(mVertexBuffer)->VertexFormat)->UseVertexData : 0;
mSurfaceUniforms.useVertexData = mVertexBuffer ? passManager->GetVertexFormat(static_cast<VkHardwareVertexBuffer*>(mVertexBuffer)->VertexFormat)->UseVertexData : 0;
if (mMaterial.mMaterial && mMaterial.mMaterial->Source())
mStreamData.timer = static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->GetShaderSpeed() / 1000.);
mSurfaceUniforms.timer = static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->GetShaderSpeed() / 1000.);
else
mStreamData.timer = 0.0f;
mSurfaceUniforms.timer = 0.0f;
if (mMaterial.mMaterial)
{
auto source = mMaterial.mMaterial->Source();
mStreamData.uSpecularMaterial = { source->GetGlossiness(), source->GetSpecularLevel() };
mSurfaceUniforms.uSpecularMaterial = { source->GetGlossiness(), source->GetSpecularLevel() };
}
if (!mRSBuffers->StreamBuffer->Write(mStreamData))
if (!mRSBuffers->SurfaceUniformsBuffer->Write(mSurfaceUniforms))
{
WaitForStreamBuffers();
mRSBuffers->StreamBuffer->Write(mStreamData);
mRSBuffers->SurfaceUniformsBuffer->Write(mSurfaceUniforms);
}
}
void VkRenderState::ApplyPushConstants()
{
mPushConstants.uDataIndex = mRSBuffers->StreamBuffer->DataIndex();
mPushConstants.uDataIndex = mRSBuffers->SurfaceUniformsBuffer->DataIndex();
mPushConstants.uLightIndex = mLightIndex >= 0 ? (mLightIndex % MAX_LIGHT_DATA) : -1;
mPushConstants.uBoneIndexBase = mBoneIndexBase;
mPushConstants.uFogballIndex = mFogballIndex >= 0 ? (mFogballIndex % MAX_FOGBALL_DATA) : -1;
@ -500,21 +500,21 @@ void VkRenderState::ApplyMaterial()
void VkRenderState::ApplyBufferSets()
{
uint32_t matrixOffset = mRSBuffers->MatrixBuffer->Offset();
uint32_t streamDataOffset = mRSBuffers->StreamBuffer->Offset();
uint32_t surfaceUniformsOffset = mRSBuffers->SurfaceUniformsBuffer->Offset();
uint32_t lightsOffset = mLightIndex >= 0 ? (uint32_t)(mLightIndex / MAX_LIGHT_DATA) * sizeof(LightBufferUBO) : mLastLightsOffset;
uint32_t fogballsOffset = mFogballIndex >= 0 ? (uint32_t)(mFogballIndex / MAX_FOGBALL_DATA) * sizeof(FogballBufferUBO) : mLastFogballsOffset;
if (mViewpointOffset != mLastViewpointOffset || matrixOffset != mLastMatricesOffset || streamDataOffset != mLastStreamDataOffset || lightsOffset != mLastLightsOffset || fogballsOffset != mLastFogballsOffset)
if (mViewpointOffset != mLastViewpointOffset || matrixOffset != mLastMatricesOffset || surfaceUniformsOffset != mLastSurfaceUniformsOffset || lightsOffset != mLastLightsOffset || fogballsOffset != mLastFogballsOffset)
{
auto descriptors = fb->GetDescriptorSetManager();
VulkanPipelineLayout* layout = fb->GetRenderPassManager()->GetPipelineLayout(mPipelineKey.NumTextureLayers);
uint32_t offsets[5] = { mViewpointOffset, matrixOffset, streamDataOffset, lightsOffset, fogballsOffset };
uint32_t offsets[5] = { mViewpointOffset, matrixOffset, surfaceUniformsOffset, lightsOffset, fogballsOffset };
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptors->GetFixedDescriptorSet());
mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 1, descriptors->GetRSBufferDescriptorSet(), 5, offsets);
mLastViewpointOffset = mViewpointOffset;
mLastMatricesOffset = matrixOffset;
mLastStreamDataOffset = streamDataOffset;
mLastSurfaceUniformsOffset = surfaceUniformsOffset;
mLastLightsOffset = lightsOffset;
mLastFogballsOffset = fogballsOffset;
}
@ -524,7 +524,7 @@ void VkRenderState::WaitForStreamBuffers()
{
fb->WaitForCommands(false);
mApplyCount = 0;
mRSBuffers->StreamBuffer->Reset();
mRSBuffers->SurfaceUniformsBuffer->Reset();
mRSBuffers->MatrixBuffer->Reset();
}
@ -758,7 +758,7 @@ void VkRenderState::EndRenderPass()
void VkRenderState::EndFrame()
{
mRSBuffers->MatrixBuffer->Reset();
mRSBuffers->StreamBuffer->Reset();
mRSBuffers->SurfaceUniformsBuffer->Reset();
}
void VkRenderState::EnableDrawBuffers(int count, bool apply)

View file

@ -71,7 +71,7 @@ protected:
void ApplyDepthBias();
void ApplyScissor();
void ApplyViewport();
void ApplyStreamData();
void ApplySurfaceUniforms();
void ApplyMatrices();
void ApplyPushConstants();
void ApplyBufferSets();
@ -113,7 +113,7 @@ protected:
uint32_t mLastViewpointOffset = 0xffffffff;
uint32_t mLastMatricesOffset = 0xffffffff;
uint32_t mLastStreamDataOffset = 0xffffffff;
uint32_t mLastSurfaceUniformsOffset = 0xffffffff;
uint32_t mLastLightsOffset = 0;
uint32_t mLastFogballsOffset = 0;
uint32_t mViewpointOffset = 0;

View file

@ -26,8 +26,8 @@ layout(set = 1, binding = 1, std140) uniform MatricesUBO
mat4 TextureMatrix;
};
// This must match the StreamData struct
struct StreamData
// This must match the SurfaceUniforms struct
struct SurfaceUniforms
{
vec4 uObjectColor;
vec4 uObjectColor2;
@ -67,14 +67,14 @@ struct StreamData
float uLightDist;
float uAlphaThreshold;
float padding1;
int uTextureIndex;
float padding2;
float padding3;
};
layout(set = 1, binding = 2, std140) uniform StreamUBO
{
StreamData data[MAX_STREAM_DATA];
SurfaceUniforms data[MAX_SURFACE_UNIFORMS];
};
// light buffers

View file

@ -64,6 +64,7 @@ layout(push_constant) uniform PushConstants
#define uLightFactor data[uDataIndex].uLightFactor
#define uLightDist data[uDataIndex].uLightDist
#define uAlphaThreshold data[uDataIndex].uAlphaThreshold
#define uTextureIndex data[uDataIndex].uTextureIndex
#define VULKAN_COORDINATE_SYSTEM
#define HAS_UNIFORM_VERTEX_DATA