Skip to content

Commit

Permalink
Basic app window with win32 & rendering with d3d11
Browse files Browse the repository at this point in the history
In this branch I'm rewriting Nanoforge in the programming language called Beef. C++ is just becoming too much of a hassle to work with. Beef has what I like about C++ & fixes the things I dislike about it. It should be a much nicer development experience, have quicker iteration time, and less bugs & memory leaks. A lot of old code needs to be rewritten anyway since it hasn't held up to changes in the projects scope & overall goals. So the rewrite isn't as much of a time cost as it might've been.

I copied over some code from a closed source project of mine so there might be some comments that don't make sense in the context of Nanoforge. The existing code has a nice way of adding new per-frame systems & specifying when in the frame + which app states they should run in. Also has a state stack, resource system, event system, and built in profiling. There's lots of ways this can be improved, but this is a good start.

Next up I'll get dear imgui working along with a basic dockspace & main menu bar. After that I'll have to figure out what the order of rewrite will be and which systems should be redesigned instead of just porting the old code to Beef. Some systems were written back when Nanoforge was just a simple zone viewer. Now that the scope of the project is much larger they aren't sufficient. A lot of code also needs to be updated to use the editor data model. I think the syntax improvements & features Beef has also open up some possibilities that weren't feasible in C++.

Some features won't immediately come to the rewrite. This time around I'll be prioritizing the map editor first and expanding out from there with other features in mind.
  • Loading branch information
Moneyl committed Jul 17, 2022
1 parent dfa15f4 commit d59f12a
Show file tree
Hide file tree
Showing 238 changed files with 28,941 additions and 19,252 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,9 @@ Project26CppCheck-cppcheck-build-dir/
Project26CppCheck.cppcheck

StructLayoutSettings.json

recovery/

build/

BeefSpace_User.toml
36 changes: 3 additions & 33 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
[submodule "Dependencies/RfgToolsPlusPlus"]
path = Dependencies/RfgToolsPlusPlus
url = https://github.com/Moneyl/RfgToolsPlusPlus.git
[submodule "Dependencies/imgui"]
path = Dependencies/imgui
url = https://github.com/ocornut/imgui.git
[submodule "Dependencies/IconFontCppHeaders"]
path = Dependencies/IconFontCppHeaders
url = https://github.com/juliettef/IconFontCppHeaders.git
[submodule "Dependencies/tinyxml2"]
path = Dependencies/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
[submodule "Dependencies/spdlog"]
path = Dependencies/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "Dependencies/imnodes"]
path = Dependencies/imnodes
url = https://github.com/Nelarius/imnodes.git
[submodule "Dependencies/DirectXTex"]
path = Dependencies/DirectXTex
url = https://github.com/microsoft/DirectXTex.git
[submodule "lib"]
path = lib
url = https://github.com/Moneyl/RF-Viewer-Lib.git
[submodule "Dependencies/nativefiledialog"]
path = Dependencies/nativefiledialog
url = https://github.com/mlabbe/nativefiledialog.git
[submodule "Dependencies/imgui_markdown"]
path = Dependencies/imgui_markdown
url = https://github.com/juliettef/imgui_markdown.git
[submodule "Dependencies/tracy"]
path = Dependencies/tracy
url = https://github.com/wolfpld/tracy.git
[submodule "Dependencies/imgui-beef"]
path = Dependencies/imgui-beef
url = https://github.com/RogueMacro/imgui-beef.git
395 changes: 395 additions & 0 deletions Assets/fonts/Codicon_License.txt

Large diffs are not rendered by default.

Binary file added Assets/fonts/codicon.ttf
Binary file not shown.
Binary file modified Assets/fonts/fa-solid-900.ttf
Binary file not shown.
29 changes: 29 additions & 0 deletions Assets/shaders/Constants.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//Constant buffers used by all shaders

cbuffer cbPerObject
{
float4x4 WVP;
float4x4 Rotation;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
28 changes: 1 addition & 27 deletions Assets/shaders/Linelist.hlsl
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
#include "Constants.hlsl"

#define thickness 3.0f
#define kAntialiasing 2.0f //Disabled by default. Must uncomment code in pixel shader to enable (line 94)

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
Expand Down
28 changes: 1 addition & 27 deletions Assets/shaders/LitTriList.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand Down
28 changes: 1 addition & 27 deletions Assets/shaders/Pixlit.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand Down
28 changes: 1 addition & 27 deletions Assets/shaders/Pixlit1Uv.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand Down
35 changes: 5 additions & 30 deletions Assets/shaders/Pixlit1UvNmap.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand All @@ -49,8 +23,9 @@ VS_OUTPUT VS(float4 inPos : POSITION, float4 inNormal : NORMAL, float4 inTangent
//Adjust range from [0, 1] to [-1, 1]
output.Normal = normalize(inNormal * 2.0f - 1.0f);
output.Normal.w = 1.0f;
output.Normal = mul(Rotation, output.Normal);

output.Tangent = mul(inTangent, WVP);
output.Tangent = mul(Rotation, inTangent * 2.0f - 1.0f);

//Divide by 1024 to normalize
output.Uv = float2(inUv.x, inUv.y) / 1024.0f;
Expand All @@ -61,7 +36,7 @@ VS_OUTPUT VS(float4 inPos : POSITION, float4 inNormal : NORMAL, float4 inTangent
float4 PS(VS_OUTPUT input) : SV_TARGET
{
float4 color = DiffuseTexture.Sample(DiffuseSampler, input.Uv);
float4 normal = normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv) * 2.0f - 1.0f));
float4 normal = input.Normal;//normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv) * 2.0f - 1.0f));
float4 specularStrength = SpecularTexture.Sample(SpecularSampler, input.Uv);

//Ambient light
Expand All @@ -85,5 +60,5 @@ float4 PS(VS_OUTPUT input) : SV_TARGET
float3 specular = spec * specularStrength;

//Final output
return float4(ambient + diffuse + specular, 1.0f);
return float4(ambient + diffuse, 1.0f);
}
35 changes: 5 additions & 30 deletions Assets/shaders/Pixlit1UvNmapCa.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand Down Expand Up @@ -52,8 +26,9 @@ VS_OUTPUT VS(float4 inPos : POSITION, float4 inNormal : NORMAL, float4 inTangent
//Adjust range from [0, 1] to [-1, 1]
output.Normal = normalize(inNormal * 2.0f - 1.0f);
output.Normal.w = 1.0f;
output.Normal = mul(Rotation, output.Normal);

output.Tangent = mul(inTangent, WVP);
output.Tangent = mul(Rotation, inTangent * 2.0f - 1.0f);

//Divide by 1024 to normalize
output.Uv = float2(inUv.x, inUv.y) / 1024.0f;
Expand All @@ -64,7 +39,7 @@ VS_OUTPUT VS(float4 inPos : POSITION, float4 inNormal : NORMAL, float4 inTangent
float4 PS(VS_OUTPUT input) : SV_TARGET
{
float4 color = DiffuseTexture.Sample(DiffuseSampler, input.Uv);
float4 normal = normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv) * 2.0 - 1.0));
float4 normal = input.Normal; //normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv) * 2.0 - 1.0));
float4 specularStrength = SpecularTexture.Sample(SpecularSampler, input.Uv);

//Ambient light
Expand All @@ -88,5 +63,5 @@ float4 PS(VS_OUTPUT input) : SV_TARGET
float3 specular = spec * specularStrength;

//Final output
return float4(ambient + diffuse + specular, 1.0f);
return float4(ambient + diffuse, 1.0f);
}
35 changes: 5 additions & 30 deletions Assets/shaders/Pixlit2UvNmap.hlsl
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@

cbuffer cbPerObject
{
float4x4 WVP;
float4 WorldPosition;
};

cbuffer cbPerFrame
{
//Position of the camera
float3 ViewPos;
int Padding0; //Padding since DirectX::XMVector is really 16 bytes

//Color of the diffuse light
float3 DiffuseColor;
int Padding1; //Padding since DirectX::XMVector is really 16 bytes

//Intensity of diffuse light
float DiffuseIntensity;
//Bias of elevation coloring in ShadeMode 1. If 0 elevation won't effect color
float ElevationFactorBias;
//Shade mode 0: Color terrain only by elevation
//Shade mode 1: Color terrain with basic lighting + option elevation coloring
int ShadeMode;
float Time;
float2 ViewportDimensions;
};
#include "Constants.hlsl"

struct VS_OUTPUT
{
Expand All @@ -50,8 +24,9 @@ VS_OUTPUT VS(float4 inPos : POSITION, float4 inNormal : NORMAL, float4 inTangent
//Adjust range from [0, 1] to [-1, 1]
output.Normal = normalize(inNormal * 2.0f - 1.0f);
output.Normal.w = 1.0f;
output.Normal = mul(Rotation, output.Normal);

output.Tangent = mul(inTangent, WVP);
output.Tangent = mul(Rotation, inTangent * 2.0f - 1.0f);

//Divide by 1024 to normalize
output.Uv0 = float2(inUv0.x, inUv0.y) / 1024.0f;
Expand All @@ -64,7 +39,7 @@ float4 PS(VS_OUTPUT input) : SV_TARGET
{
//Todo: Figure out how second UV should be used. All textures look wrong when sampled with it
float4 color = DiffuseTexture.Sample(DiffuseSampler, input.Uv0);
float4 normal = normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv0) * 2.0 - 1.0));
float4 normal = input.Normal;//normalize(input.Normal + (NormalTexture.Sample(NormalSampler, input.Uv0) * 2.0 - 1.0));
float4 specularStrength = SpecularTexture.Sample(SpecularSampler, input.Uv0);

//Ambient light
Expand All @@ -88,5 +63,5 @@ float4 PS(VS_OUTPUT input) : SV_TARGET
float3 specular = spec * specularStrength;

//Final output
return float4(ambient + diffuse + specular, 1.0f);
return float4(ambient + diffuse, 1.0f);
}
Loading

0 comments on commit d59f12a

Please sign in to comment.