- Pass vertex color and normal via uniform buffer when the attribute isn't available

This commit is contained in:
Magnus Norddahl 2019-03-02 01:56:08 +01:00
parent 1430d9012e
commit 05a6896d4f
8 changed files with 38 additions and 14 deletions

View File

@ -18,8 +18,6 @@ struct HWViewpointUniforms
float mClipHeightDirection = 0.f;
int mShadowmapFilter = 1;
float timer = 0.0f;
void CalcDependencies()
{
mNormalViewMatrix.computeNormalMatrix(mViewMatrix);

View File

@ -89,8 +89,13 @@ int VkRenderPassManager::GetVertexFormat(int numBindingPoints, int numAttributes
VkVertexFormat fmt;
fmt.NumBindingPoints = numBindingPoints;
fmt.Stride = stride;
fmt.UseVertexData = false;
for (int j = 0; j < numAttributes; j++)
{
if (attrs[j].location == VATTR_COLOR)
fmt.UseVertexData = true;
fmt.Attrs.push_back(attrs[j]);
}
VertexFormats.push_back(fmt);
return (int)VertexFormats.size() - 1;
}

View File

@ -47,6 +47,7 @@ public:
int NumBindingPoints;
size_t Stride;
std::vector<FVertexBufferAttribute> Attrs;
bool UseVertexData;
};
class VkRenderPassManager

View File

@ -62,6 +62,7 @@ bool VkRenderState::SetDepthClamp(bool on)
void VkRenderState::SetDepthMask(bool on)
{
mDepthWrite = on;
}
void VkRenderState::SetDepthFunc(int func)
@ -181,7 +182,6 @@ void VkRenderState::SetViewport(int x, int y, int w, int h)
void VkRenderState::EnableDepthTest(bool on)
{
mDepthTest = on;
mDepthWrite = on;
}
void VkRenderState::EnableMultisampling(bool on)
@ -301,9 +301,6 @@ void VkRenderState::Apply(int dt)
const float normScale = 1.0f / 255.0f;
//glVertexAttrib4fv(VATTR_COLOR, mColor.vec);
//glVertexAttrib4fv(VATTR_NORMAL, mNormal.vec);
int fogset = 0;
if (mFogEnabled)
@ -329,7 +326,11 @@ void VkRenderState::Apply(int dt)
mColors.uDynLightColor = mDynColor.vec;
mColors.uInterpolationFactor = mInterpolationFactor;
//activeShader->muTimer.Set((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
mColors.useVertexData = passManager->VertexFormats[static_cast<VKVertexBuffer*>(mVertexBuffer)->VertexFormat].UseVertexData;
mColors.uVertexColor = mColor.vec;
mColors.uVertexNormal = mNormal.vec;
mColors.timer = 0.0f; // static_cast<float>((double)(screen->FrameTime - firstFrame) * (double)mShaderTimer / 1000.);
int tempTM = TM_NORMAL;
if (mMaterial.mMaterial && mMaterial.mMaterial->tex->isHardwareCanvas())

View File

@ -95,8 +95,6 @@ static const char *shaderBindings = R"(
float uClipHeight;
float uClipHeightDirection;
int uShadowmapFilter;
float timer; // timer data for material shaders
};
// light buffers
@ -119,7 +117,10 @@ static const char *shaderBindings = R"(
vec4 uFogColor;
float uDesaturationFactor;
float uInterpolationFactor;
float padding0, padding1;
float timer; // timer data for material shaders
int useVertexData;
vec4 uVertexColor;
vec4 uVertexNormal;
};
layout(set = 0, binding = 4, std140) uniform GlowingWallsUBO {
@ -182,6 +183,7 @@ static const char *shaderBindings = R"(
// #define SUPPORTS_SHADOWMAPS
#define VULKAN_COORDINATE_SYSTEM
#define HAS_UNIFORM_VERTEX_DATA
)";
std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername, const char *vert_lump, const char *defines)

View File

@ -27,7 +27,10 @@ struct ColorsUBO
FVector4 uFogColor;
float uDesaturationFactor;
float uInterpolationFactor;
float padding0, padding1;
float timer;
int useVertexData;
FVector4 uVertexColor;
FVector4 uVertexNormal;
};
struct GlowingWallsUBO

View File

@ -662,7 +662,7 @@ inline GraphicsPipelineBuilder::GraphicsPipelineBuilder()
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS;
depthStencil.depthCompareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
depthStencil.depthBoundsTestEnable = VK_FALSE;
depthStencil.minDepthBounds = 0.0f;
depthStencil.maxDepthBounds = 1.0f;

View File

@ -34,7 +34,14 @@ void main()
vec4 eyeCoordPos = ViewMatrix * worldcoord;
vColor = aColor;
#ifdef HAS_UNIFORM_VERTEX_DATA
if (useVertexData == 0)
vColor = uVertexColor;
else
vColor = aColor;
#else
vColor = aColor;
#endif
#ifndef SIMPLE
pixelpos.xyz = worldcoord.xyz;
@ -64,7 +71,14 @@ void main()
gl_ClipDistance[4] = worldcoord.y - ((uSplitBottomPlane.w + uSplitBottomPlane.x * worldcoord.x + uSplitBottomPlane.y * worldcoord.z) * uSplitBottomPlane.z);
}
vWorldNormal = NormalModelMatrix * vec4(normalize(mix(aNormal.xyz, aNormal2.xyz, uInterpolationFactor)), 1.0);
#ifdef HAS_UNIFORM_VERTEX_DATA
if (useVertexData == 0)
vWorldNormal = NormalModelMatrix * vec4(uVertexNormal.xyz, 1.0);
else
vWorldNormal = NormalModelMatrix * vec4(normalize(mix(aNormal.xyz, aNormal2.xyz, uInterpolationFactor)), 1.0);
#else
vWorldNormal = NormalModelMatrix * vec4(normalize(mix(aNormal.xyz, aNormal2.xyz, uInterpolationFactor)), 1.0);
#endif
vEyeNormal = NormalViewMatrix * vWorldNormal;
#endif