Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44,818 changes: 42,852 additions & 1,966 deletions Assets/UnitSphere/sphere.obj

Large diffs are not rendered by default.

1,970 changes: 1,970 additions & 0 deletions Assets/UnitSphere/sphere_old.obj

Large diffs are not rendered by default.

79 changes: 41 additions & 38 deletions Game/GameMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,49 +112,26 @@ INPUT_CALLBACK(RaytraceTestCallback)
Platform::PrintDebugString("...Done.\n");
}

const int32 width = 8;
const int32 height = 8;
uint32 instanceIDs[width][height];
static void InitDemo()
{
// Init scene
Init(&MainScene, MAX_INSTANCES_PER_SCENE, &g_InputManager);

// Init view
ShaderDescriptors::InstanceData_Basic data;
data.ModelMatrix = m4f(1.0f);

MainView.Init();
uint32 instanceID;
instanceID = CreateInstance(&MainScene, 0);
data.ModelMatrix[3][0] = -8.0f;
SetInstanceData(&MainScene, instanceID, &data);

instanceID = CreateInstance(&MainScene, 1);
data.ModelMatrix[3][0] = -2.5f;
SetInstanceData(&MainScene, instanceID, &data);

instanceID = CreateInstance(&MainScene, 2);
data.ModelMatrix = m4f(0.5f);
data.ModelMatrix[3][3] = 1.0f;
data.ModelMatrix[3][0] = 8.0f;
SetInstanceData(&MainScene, instanceID, &data);

instanceID = CreateInstance(&MainScene, 2);
data.ModelMatrix = m4f(0.25f);
data.ModelMatrix[3][3] = 1.0f;
data.ModelMatrix[3][0] = 8.0f;
data.ModelMatrix[3][2] = 6.0f;
SetInstanceData(&MainScene, instanceID, &data);

instanceID = CreateInstance(&MainScene, 3);
data.ModelMatrix = m4f(7.0f);
data.ModelMatrix[3][3] = 1.0f;
data.ModelMatrix[3][1] = 8.0f;
SetInstanceData(&MainScene, instanceID, &data);

instanceID = CreateInstance(&MainScene, 3);
data.ModelMatrix = m4f(7.0f);
data.ModelMatrix[3][3] = 1.0f;
data.ModelMatrix[3][1] = 10.0f;
SetInstanceData(&MainScene, instanceID, &data);

for (int32 i = 0; i < width; i++)
{
for (int32 j = 0; j < height; j++)
{
uint32 index1D = i + width * j;
uint32 rotatingAssetID = 0;
instanceIDs[i][j] = CreateInstance(&MainScene, rotatingAssetID);
}
}

// Procedural geometry
CreateAnimatedPoly(&gameGraphicsData.m_animatedPolygon);
Expand Down Expand Up @@ -362,8 +339,8 @@ static uint32 GameInit(uint32 windowWidth, uint32 windowHeight)
// Hotkeys
g_InputManager.BindKeycodeCallback_KeyDown(Platform::Keycode::eF9, RaytraceTestCallback);

g_gameCamera.m_ref = v3f(0.0f, 0.0f, 0.0f);
g_gameCamera.m_eye = v3f(27.0f, 27.0f, 27.0f);
g_gameCamera.m_ref = v3f(0.0f, 0.0f, 2.0f);
g_gameCamera.m_eye = v3f(-1.0f, -1.0f, 1.0f) * 7.0f;
g_projMat = PerspectiveProjectionMatrix((float)currentWindowWidth / currentWindowHeight);

// Init network connection if multiplayer
Expand Down Expand Up @@ -451,11 +428,36 @@ GAME_UPDATE(GameUpdate)
{
// TODO: put this in View::Update() and write to the data repository from there
alignas(16) m4f viewProj = g_projMat * CameraViewMatrix(&g_gameCamera);
v4f camPosition = v4f(g_gameCamera.m_eye, 1.0f);
uint32 firstGlobalDataByteOffset = BindlessSystem::PushStructIntoConstantBuffer(&viewProj, sizeof(viewProj), alignof(m4f));
BindlessSystem::PushStructIntoConstantBuffer(&camPosition, sizeof(camPosition), alignof(v4f));
TINKER_ASSERT(firstGlobalDataByteOffset == 0);
(void)firstGlobalDataByteOffset;
}

// Update asset matrices here for now
{
ShaderDescriptors::InstanceData_Basic data;
data.ModelMatrix = m4f(1.0f);

static uint32 frameCtr = 0;
++frameCtr;
for (int32 i = 0; i < width; i++)
{
for (int32 j = 0; j < height; j++)
{
m4f rotMat = Core::RotationMatrix_AxisAngle(v3f(0, 0, 1), ( frameCtr + (i + width * j)) * 0.015f);

m4f transMat = m4f(1.0f);
transMat[3][0] = i * 3.0f;
transMat[3][1] = j * 3.0f;
transMat[3][2] = 0.0f;// cosf((frameCtr + (i + width * j) * 928) * 0.015f);
data.ModelMatrix = transMat;// *rotMat;
SetInstanceData(&MainScene, instanceIDs[i][j], &data);
}
}
}

// Update bindless resource descriptors
RegisterActiveTextures(); // TODO: this will eventually be automatically managed by some material system (maybe even tracks what's currently in the scene)

Expand Down Expand Up @@ -563,6 +565,7 @@ GAME_WINDOW_RESIZE(GameWindowResize)

CreateGameRenderingResources(newWindowWidth, newWindowHeight);
WriteToneMappingResources();
WriteSwapChainCopyResources();
}
}

Expand Down
4 changes: 2 additions & 2 deletions Game/RenderPasses/ForwardRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace ForwardRenderPass
RENDER_PASS_EXEC_FUNC(Execute)
{
graphicsCommandStream->CmdLayoutTransition(renderPass->colorRTs[0], Tk::Graphics::ImageLayout::eUndefined, Tk::Graphics::ImageLayout::eTransferDst, "Transition main view color to transfer_dst");
graphicsCommandStream->CmdClear(renderPass->colorRTs[0], v4f(0.0f, 0.0f, 0.0f, 0.0f), "Clear main view color buffer");
graphicsCommandStream->CmdClear(renderPass->colorRTs[0], v4f(0.1f, 0.25f, 0.25f, 0.0f), "Clear main view color buffer");
graphicsCommandStream->CmdLayoutTransition(renderPass->colorRTs[0], Tk::Graphics::ImageLayout::eTransferDst, Tk::Graphics::ImageLayout::eRenderOptimal, "Transition main view color to render_optimal");

Tk::Graphics::DescriptorHandle descriptors[MAX_DESCRIPTOR_SETS_PER_SHADER];
Expand All @@ -30,7 +30,7 @@ namespace ForwardRenderPass

// TODO: handle this more elegantly
UpdateAnimatedPoly(&gameGraphicsData.m_animatedPolygon);
DrawAnimatedPoly(&gameGraphicsData.m_animatedPolygon, Tk::Graphics::SHADER_ID_ANIMATEDPOLY_MainView, Tk::Graphics::BlendState::eAlphaBlend, Tk::Graphics::DepthState::eTestOnWriteOn_CCW, graphicsCommandStream);
//DrawAnimatedPoly(&gameGraphicsData.m_animatedPolygon, Tk::Graphics::SHADER_ID_ANIMATEDPOLY_MainView, Tk::Graphics::BlendState::eAlphaBlend, Tk::Graphics::DepthState::eTestOnWriteOn_CCW, graphicsCommandStream);

EndRenderPass(renderPass, graphicsCommandStream);
}
Expand Down
1 change: 1 addition & 0 deletions Generated/ShaderDescriptors_Reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct PushConstantData
struct AllGlobals
{
alignas(16) m4f ViewProjMatrix;
v4f CamPosition;
};

struct InstanceData_Basic
Expand Down
4 changes: 2 additions & 2 deletions Scripts/build_benchmarks.bat
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set SourceListBenchmark=%SourceListBenchmark% ../Core/Utility/MemTracker.cpp
set SourceListBenchmark=%SourceListBenchmark% ../Benchmark/MathBenchmarks/VectorTypeBenchmarks.cpp
set SourceListBenchmark=%SourceListBenchmark% ../Benchmark/DataStructureBenchmarks/HashMapBenchmarks.cpp
set SourceListBenchmark=%SourceListBenchmark% ../Core/DataStructures/HashMap.cpp
set CompileDefines=/DENABLE_MEM_TRACKING
rem set CompileDefines=/DENABLE_MEM_TRACKING

if "%BuildConfig%" == "Debug" (
set DebugCompileFlagsBenchmark=/FdTinkerBenchmark.pdb
Expand All @@ -62,7 +62,7 @@ set CommonCompileFlags=%CommonCompileFlags% /Fo:%OBJDir%

echo.
echo Building TinkerBenchmark.exe...
cl %CommonCompileFlags% %CompileIncludePaths% %CompileDefines% %DebugCompileFlagsBenchmark% %SourceListBenchmark% /link %CommonLinkFlags% Winmm.lib %DebugLinkFlagsBenchmark% /out:TinkerBenchmark.exe
cl %CommonCompileFlags% %CompileIncludePaths% %CompileDefines% %DebugCompileFlagsBenchmark% %SourceListBenchmark% /link %CommonLinkFlags% Winmm.lib dbghelp.lib %DebugLinkFlagsBenchmark% /out:TinkerBenchmark.exe

:DoneBuild
popd
Expand Down
4 changes: 2 additions & 2 deletions Scripts/build_tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ set SourceListTest=%SourceListTest% ../Core/Utility/MemTracker.cpp
set SourceListTest=%SourceListTest% ../Core/DataStructures/Vector.cpp
set SourceListTest=%SourceListTest% ../Core/DataStructures/HashMap.cpp
set SourceListTest=%SourceListTest% ../Core/Mem.cpp
set CompileDefines=/DENABLE_MEM_TRACKING
rem set CompileDefines=/DENABLE_MEM_TRACKING

if "%BuildConfig%" == "Debug" (
set DebugCompileFlagsTest=/FdTinkerTest.pdb
Expand All @@ -61,7 +61,7 @@ set CommonCompileFlags=%CommonCompileFlags% /Fo:%OBJDir%

echo.
echo Building TinkerTest.exe...
cl %CommonCompileFlags% %CompileIncludePaths% %CompileDefines% %DebugCompileFlagsTest% %SourceListTest% /link %CommonLinkFlags% %DebugLinkFlagsTest% /out:TinkerTest.exe
cl %CommonCompileFlags% %CompileIncludePaths% %CompileDefines% %DebugCompileFlagsTest% %SourceListTest% /link dbghelp.lib %CommonLinkFlags% %DebugLinkFlagsTest% /out:TinkerTest.exe

:DoneBuild
popd
Expand Down
1 change: 1 addition & 0 deletions Shaders/hlsl/ShaderDescriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ PushConstantData PushConstants;
struct AllGlobals
{
float4x4 ViewProjMatrix;
float4 CamPosition;
};

struct InstanceData_Basic
Expand Down
87 changes: 79 additions & 8 deletions Shaders/hlsl/basic_PS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,89 @@ struct PSInput
[[vk::location(0)]] float4 Position : SV_POSITION;
[[vk::location(1)]] float2 UV : TEXCOORD0;
[[vk::location(2)]] float3 Normal : NORMAL;
[[vk::location(3)]] uint InstanceIndex : INSTANCEID;
[[vk::location(4)]] float3 WorldPos : WORLDPOS;
};

#define LIGHT_DIR normalize(float3(-1, -1, 1))
#define AMBIENT 0.05f
#define BASE_COLOR float3(0.7, 0.7, 0.7)
#define LIGHT_DIR normalize(float3(1, -1, -1))
#define LIGHT_INTENSITY 1.0
#define M_PI 3.14159265358979323846
#define ONE_OVER_PI (1.0 / M_PI)

float3 Schlick(float3 f0, float3 f90, float vDotH)
{
return f0 + (f90 - f0) * pow(clamp(1.0 - vDotH, 0.0, 1.0), 5.0);
}

float Schlick(float f0, float f90, float vDotH)
{
float x = clamp(1.0 - vDotH, 0.0, 1.0);
float x2 = x * x;
float x5 = x * x2 * x2;
return f0 + (f90 - f0) * x5;
}

float V_GGX(float NdotL, float NdotV, float alphaRoughness)
{
float alphaRoughnessSq = alphaRoughness * alphaRoughness;

float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);
float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq);

float GGX = GGXV + GGXL;
if (GGX > 0.0)
{
return 0.5 / GGX;
}
return 0.0;
}

float D_GGX(float NdotH, float alphaRoughness)
{
float alphaRoughnessSq = alphaRoughness * alphaRoughness;
float f = (NdotH * NdotH) * (alphaRoughnessSq - 1.0) + 1.0;
return alphaRoughnessSq / (M_PI * f * f);
}

float3 specGGX(float alphaRoughness, float NdotL, float NdotV, float NdotH)
{
float Vis = V_GGX(NdotL, NdotV, alphaRoughness);
float D = D_GGX(NdotH, alphaRoughness);

return float3(Vis * D, Vis * D, Vis * D);
}

float4 main(PSInput Input) : SV_Target0
{
float3 albedo0 = BindlessTextures[0].Sample(SamplerLinearWrap, Input.UV).rgb;
float3 albedo1 = BindlessTextures[1].Sample(SamplerLinearWrap, Input.UV).rgb;
float3 albedo = lerp(albedo0, albedo1, Input.Normal.x * 0.5 + 0.5);
float lambert = dot(LIGHT_DIR, normalize(Input.Normal));
float3 finalColor = clamp(BASE_COLOR * albedo * abs(lambert), AMBIENT, 1.0f);
//float3 albedo0 = BindlessTextures[0].Sample(SamplerLinearWrap, Input.UV).rgb;
//float3 albedo1 = BindlessTextures[1].Sample(SamplerLinearWrap, Input.UV).rgb;
//float3 albedo = lerp(albedo0, albedo1, Input.Normal.x * 0.5 + 0.5);
const float roughness = (Input.InstanceIndex / 8) / 7.0;
const float metallic = (Input.InstanceIndex % 8) / 7.0;

float3 albedo = float3(1, 1, 1);
float3 c_diff = albedo;// lerp(albedo, float3(0, 0, 0), metallic);
float3 l = -LIGHT_DIR;
float3 v = normalize(BindlessConstantBuffer.Load<AllGlobals>(PushConstants.InstanceOffsets[0]).CamPosition.xyz - Input.WorldPos);
float3 h = normalize(l + v);

float nDotL = saturate(dot(Input.Normal, l)); // Lambert's law
float nDotV = saturate(dot(Input.Normal, v));
float nDotH = saturate(dot(Input.Normal, h));
float absVdotH = abs(dot(v, h));
float3 brdfDiffuse = c_diff * ONE_OVER_PI; // energy conservation
float3 diffuseTerm = brdfDiffuse * LIGHT_INTENSITY * nDotL;

// Fresnel terms
float3 fresnelDielectric = 0.04 + (1 - 0.04) * pow((1 - absVdotH), 5.0);//Schlick(0.04, 1.0, absVdotH);
float3 fresnelMetal = albedo + (float3(1, 1, 1) - albedo) * pow((1 - absVdotH), 5.0); //Schlick(c_diff, float3(1.0, 1.0, 1.0), absVdotH);

// Assume non-aniso material for now
float3 brdfSpec = LIGHT_INTENSITY * nDotL * specGGX(roughness * roughness, nDotL, nDotV, nDotH);

float3 brdfMetal = brdfSpec * fresnelMetal;
float3 brdfDielectric = lerp(diffuseTerm, brdfSpec, fresnelDielectric);

float3 finalColor = lerp(brdfDielectric, brdfMetal, metallic);
return float4(finalColor, 1.0f);
}
8 changes: 6 additions & 2 deletions Shaders/hlsl/basic_VS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ struct VSOutput
[[vk::location(0)]] float4 Position : SV_POSITION;
[[vk::location(1)]] float2 UV : TEXCOORD0;
[[vk::location(2)]] float3 Normal : NORMAL;
[[vk::location(3)]] uint InstanceIndex : INSTANCEID;
[[vk::location(4)]] float3 WorldPos : WORLDPOS;
};

VSOutput main(uint VertexIndex : SV_VertexID, uint InstanceIndex : SV_InstanceID)
{
float4x4 ViewProjMat = BindlessConstantBuffer.Load<AllGlobals>(PushConstants.InstanceOffsets[0]).ViewProjMatrix;
float4x4 ModelMat = BindlessConstantBuffer.Load<InstanceData_Basic>(PushConstants.InstanceOffsets[1]).ModelMatrix;
float4x4 ModelMat = BindlessConstantBuffer.Load<InstanceData_Basic>(PushConstants.InstanceOffsets[1] + InstanceIndex * 64).ModelMatrix;

float4 ModelPos = float4(PositionData.Load(VertexIndex).xyz, 1.0f);
float2 UV = UVData.Load(VertexIndex);
Expand All @@ -27,6 +29,8 @@ VSOutput main(uint VertexIndex : SV_VertexID, uint InstanceIndex : SV_InstanceID
VSOutput Out;
Out.Position = mul(ViewProjMat, mul(ModelMat, ModelPos));
Out.UV = UV;
Out.Normal = Normal;
Out.Normal = normalize(ModelPos.xyz);// Normal;
Out.WorldPos = mul(ModelMat, ModelPos).xyz;
Out.InstanceIndex = InstanceIndex;
return Out;
}
2 changes: 1 addition & 1 deletion Shaders/hlsl/grayscale_CS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
void main(uint3 DispatchThreadID : SV_DispatchThreadID)
{
uint2 Coord = DispatchThreadID.xy;
Material_ComputeCopyImage2D Constants = BindlessConstantBuffer.Load<Material_ComputeCopyImage2D>(64 /*PushConstants.InstanceOffsets[2]*/);
Material_ComputeCopyImage2D Constants = BindlessConstantBuffer.Load<Material_ComputeCopyImage2D>(64 + 16 /*PushConstants.InstanceOffsets[2]*/);

if (Coord.x >= Constants.dims.x || Coord.y >= Constants.dims.y)
{
Expand Down
4 changes: 2 additions & 2 deletions Test/DataStructureTests/RingBufferTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void Test_RingBufferEnqueueOneDequeueOne()

void Test_RingBufferEnqueueManyDequeueMany()
{
RingBuffer<uint32, 3> buffer;
TINKER_TEST_ASSERT(buffer.Capacity() == 4);
RingBuffer<uint32, 4> buffer;
//TINKER_TEST_ASSERT(buffer.Capacity() == 4);

buffer.Enqueue(1);
TINKER_TEST_ASSERT(buffer.m_data[0] == 1);
Expand Down
Binary file modified ToolsBin/TinkerSC.exe
Binary file not shown.
Binary file modified ToolsBin/TinkerSC.pdb
Binary file not shown.