Skip to content

Commit

Permalink
Linux render fix (#102)
Browse files Browse the repository at this point in the history
* Fix alignment on the point and dir lights on linux

* Fix log issue on windows
  • Loading branch information
BenjaFriend authored and ArturoKuang committed Oct 31, 2019
1 parent 777a2b9 commit c59bde1
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 143 deletions.
153 changes: 63 additions & 90 deletions Assets/Levels/Level_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"value7": 2,
"value8": 1,
"value9": 0,
"value10": 12,
"value10": 8,
"value11": 0,
"value12": {
"POS_X": -2.0,
Expand Down Expand Up @@ -62,10 +62,10 @@
"value20": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"POS_Z": 1.0,
"SCALE_X": 0.10000000149011612,
"SCALE_Y": 0.10000000149011612,
"SCALE_Z": 0.10000000149011612,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
Expand All @@ -74,113 +74,86 @@
"value22": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"POS_Z": -1.0,
"SCALE_X": 0.10000000149011612,
"SCALE_Y": 0.10000000149011612,
"SCALE_Z": 0.10000000149011612,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
},
"value23": 6,
"value24": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Y": 1.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"SCALE_X": 0.10000000149011612,
"SCALE_Y": 0.10000000149011612,
"SCALE_Z": 0.10000000149011612,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
},
"value25": 7,
"value26": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Y": -1.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"SCALE_X": 0.10000000149011612,
"SCALE_Y": 0.10000000149011612,
"SCALE_Z": 0.10000000149011612,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
},
"value27": 4,
"value28": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
"value27": 8,
"value28": 0,
"value29": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Cobblestone.mat"
},
"value29": 5,
"value30": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
"value30": 1,
"value31": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Paint.mat"
},
"value31": 6,
"value32": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
"value32": 2,
"value33": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Bronze.mat"
},
"value33": 7,
"value34": {
"POS_X": 0.0,
"POS_Y": 0.0,
"POS_Z": 0.0,
"SCALE_X": 1.0,
"SCALE_Y": 1.0,
"SCALE_Z": 1.0,
"ROT_X": 0.0,
"ROT_Y": 0.0,
"ROT_Z": 0.0
"value34": 3,
"value35": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Cobblestone.mat"
},
"value35": 4,
"value36": 0,
"value36": 4,
"value37": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Cobblestone.mat"
"MATERIAL_NAME": "Materials/Default.mat"
},
"value38": 1,
"value38": 5,
"value39": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Paint.mat"
"MATERIAL_NAME": "Materials/Default.mat"
},
"value40": 2,
"value40": 6,
"value41": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Bronze.mat"
"MATERIAL_NAME": "Materials/Default.mat"
},
"value42": 3,
"value42": 7,
"value43": {
"MESH_NAME": "Models/sphere.obj",
"MATERIAL_NAME": "Materials/Cobblestone.mat"
"MATERIAL_NAME": "Materials/Default.mat"
},
"value44": 1,
"value45": 8,
"value46": {
"DIFFUSE_X": 1.0,
"DIFFUSE_Y": 1.0,
"DIFFUSE_Z": 1.0,
"DIFFUSE_W": 1.0,
"DIRECTION_X": 1.0,
"DIRECTION_Y": -1.0,
"DIRECTION_Z": -0.5,
Expand All @@ -189,35 +162,35 @@
"value47": 4,
"value48": 4,
"value49": {
"DIFFUSE_X": 0.6554765701293945,
"DIFFUSE_Y": 0.25879696011543276,
"DIFFUSE_Z": 0.0029908139258623125,
"RANGE": 30.0,
"INTENSITY": 10.0
"DIFFUSE_X": 1.0,
"DIFFUSE_Y": 0.0,
"DIFFUSE_Z": 0.0,
"RANGE": 20.0,
"INTENSITY": 5.0
},
"value50": 5,
"value51": {
"DIFFUSE_X": 0.6264839768409729,
"DIFFUSE_Y": 0.5919064879417419,
"DIFFUSE_Z": 0.40885648131370547,
"RANGE": 30.0,
"INTENSITY": 10.0
"DIFFUSE_X": 1.0,
"DIFFUSE_Y": 1.0,
"DIFFUSE_Z": 0.0,
"RANGE": 20.0,
"INTENSITY": 5.0
},
"value52": 6,
"value53": {
"DIFFUSE_X": 0.05688650161027908,
"DIFFUSE_Y": 0.42460402846336367,
"DIFFUSE_Z": 0.1903134286403656,
"RANGE": 30.0,
"INTENSITY": 10.0
"DIFFUSE_X": 0.0,
"DIFFUSE_Y": 1.0,
"DIFFUSE_Z": 1.0,
"RANGE": 20.0,
"INTENSITY": 5.0
},
"value54": 7,
"value55": {
"DIFFUSE_X": 0.5340433716773987,
"DIFFUSE_Y": 0.6538285613059998,
"DIFFUSE_Z": 0.3674733638763428,
"RANGE": 30.0,
"INTENSITY": 10.0
"DIFFUSE_X": 1.0,
"DIFFUSE_Y": 0.0,
"DIFFUSE_Z": 1.0,
"RANGE": 20.0,
"INTENSITY": 5.0
},
"value56": 0
}
12 changes: 6 additions & 6 deletions Assets/Shaders/PBRDefault.frag
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ layout (binding = 5) uniform sampler2D roughnessMap;

layout (binding = 6) uniform LightingData
{
int DirLightCount;
DirectionalLightData DirLights[32];
uint DirLightCount;
uint PointLightCount;

int PointLightCount;
DirectionalLightData DirLights[32];
PointLightData PointLights[32];
} lights;

Expand All @@ -47,7 +47,6 @@ layout (location = 0) in vec3 inWorldPos;
layout (location = 1) in vec2 inTexCoord;
layout (location = 2) in vec3 inTangent;
layout (location = 3) in vec3 inNormal;
layout (location = 4) in vec3 inCamPos;

// Outputs ------------
layout (location = 0) out vec4 outFragColor;
Expand Down Expand Up @@ -209,7 +208,7 @@ void main()
lights.DirLights[i],
normal,
inWorldPos,
inCamPos.xyz,
ubo.camPos.xyz,
roughness,
metal,
abledoColor.rgb,
Expand All @@ -218,13 +217,14 @@ void main()
}



for(int i = 0; i < lights.PointLightCount; i++)
{
LightColor += CalculatePointLight(
lights.PointLights[ i ],
normal,
inWorldPos,
inCamPos.xyz,
ubo.camPos.xyz,
roughness,
metal,
abledoColor.rgb,
Expand Down
19 changes: 1 addition & 18 deletions Assets/Shaders/PBRDefault.vert
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ layout (location = 0) out vec3 outWorldPos;
layout (location = 1) out vec2 outTextCoord; // AKA UV coordinate
layout (location = 2) out vec3 outTangent;
layout (location = 3) out vec3 outNormal;
layout (location = 4) out vec3 outCamPos;

out gl_PerVertex
{
Expand All @@ -39,22 +38,6 @@ void main()
outTextCoord.t = 1.0 - inTexCoord.t;
gl_Position = ubo.projection * ubo.view * vec4(outWorldPos, 1.0);


// How I was doing it before
// mat4 modelView = ubo.view * ubo.model;
// vec3 worldPos = vec3(modelView * vec4(inPosition, 1.0));
// gl_Position = ubo.projection * modelView * vec4(inPosition, 1.0);

// // World Pos ------
// outWorldPos = worldPos;
// // Tangent -----
// Tangent -----
outTangent = normalize( inTangent * mat3(ubo.model) );
// // Normal -----
// //outNormal = normalize( inNormal * mat3(ubo.model) );
// outNormal = inNormal;
// // Texture Coord -----
// outTextCoord = inTexCoord;
// // Subtract 1 from the texture coordinate if we need to for each texture
// outTextCoord.y = 1 - outTextCoord.y;
// outCamPos = ubo.camPos;
}
Binary file modified Assets/Shaders/PBRDefault_frag.spv
Binary file not shown.
Binary file modified Assets/Shaders/PBRDefault_vert.spv
Binary file not shown.
4 changes: 2 additions & 2 deletions Config/EngineConf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ WindowIconImage=FlingEngineLogo.png

; Graphics API Settings
[Vulkan]
#EnableValidationLayers=false
EnableValidationLayers=true
EnableValidationLayers=false
#EnableValidationLayers=true

[Camera]
MoveSpeed=10
Expand Down
13 changes: 4 additions & 9 deletions FlingEngine/Graphics/inc/Lighting/DirectionalLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Fling
{
/**
* @brief Simple representation of a directional light for Fling
*
* @brief Simple representation of a directional light for Fling. Needs to be 16 bytes aligned
* for Vulkan
*/
struct DirectionalLight
struct alignas(16) DirectionalLight
{
glm::vec4 DiffuseColor { 1.0f };
glm::vec4 Direction { 1.0f, -1.0f, -0.5f, 1.0f };
Expand All @@ -24,15 +24,10 @@ namespace Fling
void DirectionalLight::serialize(Archive & t_Archive)
{
t_Archive(
//cereal::make_nvp("AMBIENT_X", AmbientColor.x),
//cereal::make_nvp("AMBIENT_Y", AmbientColor.y),
//cereal::make_nvp("AMBIENT_Z", AmbientColor.z),
//cereal::make_nvp("AMBIENT_W", AmbientColor.w),

cereal::make_nvp("DIFFUSE_X", DiffuseColor.x),
cereal::make_nvp("DIFFUSE_Y", DiffuseColor.y),
cereal::make_nvp("DIFFUSE_Z", DiffuseColor.z),
//cereal::make_nvp("DIFFUSE_W", DiffuseColor.w),
cereal::make_nvp("DIFFUSE_W", DiffuseColor.w),

cereal::make_nvp("DIRECTION_X", Direction.x),
cereal::make_nvp("DIRECTION_Y", Direction.y),
Expand Down
11 changes: 6 additions & 5 deletions FlingEngine/Graphics/inc/Lighting/PointLight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
namespace Fling
{
/**
* @brief Simple representation of
* @brief Simple representation of a point light in Light Vox. The colors and position have
* to be glm::vec4's because of shader alignment things
*/
struct PointLight
struct alignas(16) PointLight
{
friend class Renderer;
public:
Expand All @@ -22,10 +23,10 @@ namespace Fling
/** The position of this point light will be set from it's Transform component.
* set per frame
*/
glm::vec4 Pos {};
glm::vec4 Pos { 0.0f };
public:
float Intensity = 10.0f;
float Range = 5.0f;
alignas(4) float Intensity = 10.0f;
alignas(4) float Range = 5.0f;

template<class Archive>
void serialize(Archive & t_Archive);
Expand Down
9 changes: 5 additions & 4 deletions FlingEngine/Graphics/inc/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,12 @@ namespace Fling
std::shared_ptr<Image> m_BRDFLookupTexture;
struct LightingUbo
{
UINT32 DirLightCount = 0;
DirectionalLight DirLightBuffer[Lighting::MaxDirectionalLights] = {};
alignas(4) UINT32 DirLightCount = 0;
alignas(4) UINT32 PointLightCount = 0;

UINT32 PointLightCount = 0;
PointLight PointLightBuffer[Lighting::MaxPointLights] = {};
alignas(16) DirectionalLight DirLightBuffer[Lighting::MaxDirectionalLights] = {};

alignas(16) PointLight PointLightBuffer[Lighting::MaxPointLights] = {};
};

LightingUbo m_LightingUBO = {};
Expand Down
Loading

0 comments on commit c59bde1

Please sign in to comment.