Skip to content

Commit

Permalink
normal mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
PazerOP committed May 25, 2019
1 parent 59f2f83 commit 9b66b7a
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ IMesh* IShaderAPI_MeshManager::GetDynamicMeshEx(IMaterial* material, VertexForma
{
LOG_FUNC();

const VertexFormat fmt(vertexFormat);
assert(hwSkinBoneCount == 0);
assert(fmt.m_BoneWeightCount == 0);
assert(!(fmt.m_Flags & VertexFormatFlags::BoneIndex));
VertexFormat fmt(vertexFormat);
fmt.SetBoneWeightCount(hwSkinBoneCount);

return &m_DynamicMeshes.try_emplace(fmt, fmt, true).first->second;
}
Expand Down
33 changes: 32 additions & 1 deletion shaderapivulkan/src/TF2Vulkan/StateManagerVulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "interface/internal/IShaderInternal.h"
#include "shaders/VulkanShaderManager.h"
#include "VulkanFactories.h"
#include "TF2Vulkan/FormatInfo.h"

#include <TF2Vulkan/Util/AutoInit.h>
#include <TF2Vulkan/Util/Color.h>
Expand Down Expand Up @@ -693,6 +694,35 @@ static vk::CompareOp ConvertCompareOp(ShaderDepthFunc_t op)
}
}

static vk::Format ConvertVertexFormat(const ShaderReflection::VertexAttribute& var)
{
DataFormat componentType;
uint_fast8_t componentSize;

switch (var.m_Type)
{
default:
assert(!"Unknown/unexpected vertex attribute type");
case ShaderReflection::VariableType::Float:
componentType = DataFormat::SFloat;
componentSize = 4;
break;

case ShaderReflection::VariableType::Int:
componentType = DataFormat::SInt;
componentSize = 4;
break;

case ShaderReflection::VariableType::UInt:
case ShaderReflection::VariableType::Boolean:
componentType = DataFormat::UInt;
componentSize = 4;
break;
}

return FormatInfo::ConvertDataFormat(componentType, var.m_ComponentCount, componentSize);
}

Pipeline::Pipeline(const PipelineKey& key, const PipelineLayout& layout,
const RenderPass& renderPass) :
m_Layout(&layout),
Expand Down Expand Up @@ -763,7 +793,8 @@ Pipeline::Pipeline(const PipelineKey& key, const PipelineLayout& layout,
continue;

// Otherwise, insert an empty one
attrs.emplace_back(VIAD(input.m_Location, 1, vk::Format::eR32G32B32A32Sfloat));
//attrs.emplace_back(VIAD(input.m_Location, 1, vk::Format::eR32G32B32A32Sfloat));
attrs.emplace_back(VIAD(input.m_Location, 1, ConvertVertexFormat(input)));
}

auto & binds = m_VertexInputBindingDescriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ ShaderVariable::ShaderVariable(const spirv_cross::Compiler& comp, uint32_t id) :
const auto& type = comp.expression_type(id);
//assert(!type.pointer);
m_Type = ConvertVariableType(type.basetype);
m_ComponentCount = type.vecsize;
}

ShaderVariable::ShaderVariable(std::string&& name) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace TF2Vulkan

std::string m_Name;
VariableType m_Type;
uint_fast8_t m_ComponentCount; // vector size (1/2/3/4 elements)
};

struct SpecializationConstant final : ShaderVariable
Expand Down
2 changes: 2 additions & 0 deletions stdshader_vulkan/include/stdshader_vulkan/ShaderDataShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace TF2Vulkan{ namespace Shaders
static_assert(offsetof(LightInfo, OOdot) == 68); // 9
#endif

#if false
struct PixelShaderLightInfo
{
#ifdef __cplusplus
Expand All @@ -49,6 +50,7 @@ namespace TF2Vulkan{ namespace Shaders
float4 color;
float4 pos;
};
#endif

struct AmbientLightCube
{
Expand Down
9 changes: 7 additions & 2 deletions stdshader_vulkan/src/shaders/DebugNormalMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,18 @@ void Shader::OnInitShader(IShaderNextFactory& mgr)

void Shader::OnInitShaderParams(IMaterialVar** params, const char* materialName)
{
LOG_FUNC();
NOT_IMPLEMENTED_FUNC_NOBREAK();

#if false
SET_FLAGS2(MATERIAL_VAR2_SUPPORTS_HW_SKINNING);
#endif
}

void Shader::OnDrawElements(const OnDrawElementsParams& params)
{
LOG_FUNC();
NOT_IMPLEMENTED_FUNC_NOBREAK();

#if false

auto& shadow = params.shadow;
auto& dynamic = params.dynamic;
Expand All @@ -86,4 +90,5 @@ void Shader::OnDrawElements(const OnDrawElementsParams& params)
}

Draw();
#endif
}
39 changes: 38 additions & 1 deletion stdshader_vulkan/src/shaders/HLSL/common_fxc.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static const int BINDING_CBUF_SHADERCOMMON = 0;
static const int BINDING_CBUF_SHADERCUSTOM = 1;
static const int BINDING_CBUF_VSMODELMATRICES = 2;

static const float cOverbright = 2.0f;
static const float cOOOverbright = 1.0f / cOverbright;
static const float cOneThird = 1.0f / 3.0f;

[[vk::binding(BINDING_CBUF_SHADERCOMMON)]] cbuffer ShaderCommonConstants
Expand All @@ -42,7 +44,7 @@ static const float cOneThird = 1.0f / 3.0f;
float4x4 cViewProj;

float cOOGamma;
int g_nLightCountRegister;
uint g_nLightCountRegister;
bool4 g_bLightEnabled;

float3 cEyePos;
Expand All @@ -62,10 +64,17 @@ static const float cOneThird = 1.0f / 3.0f;
float4 cFlashlightScreenScale;
};

#define NUM_LIGHTS g_nLightCountRegister

#define g_FogType DOWATERFOG

// These cause bad codegen with glslangValidator
#define tex1D "FIXME"
#define tex2D "FIXME"
#define tex3D "FIXME"
#define sampler1D "FIXME"
#define sampler2D "FIXME"
#define sampler3D "FIXME"

// This just shouldn't be used anymore
#define D3DCOLORtoUBYTE4 "FIXME"
Expand Down Expand Up @@ -104,4 +113,32 @@ float4 GammaToLinear(const float4 gamma)
return float4(pow(gamma.xyz, 2.2f), gamma.w);
}

float3 Vec3WorldToTangent(float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal)
{
float3 vTangentVector;
vTangentVector.x = dot(iWorldVector.xyz, iWorldTangent.xyz);
vTangentVector.y = dot(iWorldVector.xyz, iWorldBinormal.xyz);
vTangentVector.z = dot(iWorldVector.xyz, iWorldNormal.xyz);
return vTangentVector.xyz; // Return without normalizing
}

float3 Vec3WorldToTangentNormalized(float3 iWorldVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal)
{
return normalize(Vec3WorldToTangent(iWorldVector, iWorldNormal, iWorldTangent, iWorldBinormal));
}

float3 Vec3TangentToWorld(float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal)
{
float3 vWorldVector;
vWorldVector.xyz = iTangentVector.x * iWorldTangent.xyz;
vWorldVector.xyz += iTangentVector.y * iWorldBinormal.xyz;
vWorldVector.xyz += iTangentVector.z * iWorldNormal.xyz;
return vWorldVector.xyz; // Return without normalizing
}

float3 Vec3TangentToWorldNormalized(float3 iTangentVector, float3 iWorldNormal, float3 iWorldTangent, float3 iWorldBinormal)
{
return normalize(Vec3TangentToWorld(iTangentVector, iWorldNormal, iWorldTangent, iWorldBinormal));
}

#endif // INCLUDE_GUARD_COMMON_FXC_HLSLI
15 changes: 12 additions & 3 deletions stdshader_vulkan/src/shaders/HLSL/common_vs_fxc.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
float4x3 cModel[53];
};

static const float cOverbright = 2.0f;
static const float cOOOverbright = 1.0f / cOverbright;

#define g_nLightCount g_nLightCountRegister.x

#define cFogEndOverFogRange cFogParams.endOverRange
Expand Down Expand Up @@ -631,4 +628,16 @@ float3 DoLighting(const float3 worldPos, const float3 worldNormal,
return linearColor;
}

// This routine uses booleans to do early-outs and is meant to be called by routines OUTSIDE of this file
float GetVertexAttenForLight(const float3 worldPos, uint lightNum)
{
float result = 0.0f;
if (g_bLightEnabled[lightNum])
{
result = VertexAttenInternal(worldPos, lightNum);
}

return result;
}

#endif // INCLUDE_GUARD_COMMON_VS_FXC_HLSLI
41 changes: 41 additions & 0 deletions stdshader_vulkan/src/shaders/HLSL/xlitgeneric.common.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,46 @@
float g_fVertexAlpha;
};

struct VS_TO_PS_INTERSTAGE_DATA
{
#ifdef VERTEX_SHADER
float4 projPos : SV_Position;
#endif

float4 color : COLOR0;
float fog : FOG;

float3 baseTexCoord : TEXCOORD0;
float3 detailTexCoord : TEXCOORD1;

float3 worldVertToEyeVector : TEXCOORD3;
float3 worldSpaceNormal : TEXCOORD4;
float4 worldSpaceTangent;
float3 worldSpaceBinormal;
float4 lightAtten;

float4 vProjPos : TEXCOORD6;
float4 worldPos_ProjPosZ : TEXCOORD7;

float3 SeamlessWeights : TEXCOORD8;
float4 fogFactorW : TEXCOORD9;

float3 boneWeightsOut : TEST_BONEWEIGHTSOUT;
};

#ifdef VERTEX_SHADER
#define VS_OUTPUT VS_TO_PS_INTERSTAGE_DATA
#elif defined(PIXEL_SHADER) || defined(FRAGMENT_SHADER)
#define PS_INPUT VS_TO_PS_INTERSTAGE_DATA
#else
#error "Either VERTEX_SHADER or PIXEL_SHADER must be defined"
#endif

static int SPEC_CONST_ID_NEXT = SPEC_CONST_ID_BASE + 1;
[[vk::constant_id(SPEC_CONST_ID_NEXT++)]] const bool AMBIENT_LIGHT = false;
[[vk::constant_id(SPEC_CONST_ID_BASE + 1)]] const bool TEXACTIVE_BASETEXTURE = false;
[[vk::constant_id(SPEC_CONST_ID_BASE + 2)]] const bool TEXACTIVE_BUMPMAP = false;
[[vk::constant_id(SPEC_CONST_ID_BASE + 3)]] const bool TEXACTIVE_LIGHTWARP = false;

#if false // TODO: Array-based textures
[[vk::constant_id(SPEC_CONST_ID_BASE + 3)]] const uint TEXTURE_COUNT = 1;
Expand All @@ -44,4 +82,7 @@
[[vk::binding(2)]] Texture2D morphTexture;
[[vk::binding(2)]] SamplerState morphSampler;

[[vk::binding(3)]] Texture2D LightWarpTexture;
[[vk::binding(3)]] SamplerState LightWarpTextureSampler;

#endif // XLITGENERIC_COMMON_HLSLI_INCLUDE_GUARD
Loading

0 comments on commit 9b66b7a

Please sign in to comment.