Skip to content

Commit

Permalink
updated formatting and fixed minors issues (JeanPhilippeKernel#412)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanPhilippeKernel authored Jan 6, 2025
1 parent c327fb0 commit d08d098
Show file tree
Hide file tree
Showing 154 changed files with 1,967 additions and 2,916 deletions.
33 changes: 26 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,40 @@ Language: Cpp
BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: true # Only available in clang-format-10
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
BracedInitializerIndentWidth: 0
AlignConsecutiveMacros: # Only available in clang-format-10
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignConsecutiveAssignments:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
AlignCompound: true
# AlignFunctionDeclarations: true
# AlignFunctionPointers: true
PadOperators: true
AlignConsecutiveDeclarations:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
# AlignFunctionDeclarations: true
# AlignFunctionPointers: true
PadOperators: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
# AlignArrayOfStructures: Left
AlignEscapedNewlinesLeft: false
# AlignConsecutiveFields: true
AlignArrayOfStructures: Right

# AllowAllArgumentsOnNextLine: true # Only available in clang-format-10
AllowAllConstructorInitializersOnNextLine: false # Only available in clang-format-10
AllowAllParametersOfDeclarationOnNextLine: false # Only available in clang-format-10
AllowShortBlocksOnASingleLine: Empty # Only available in clang-format-10
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty # Only available in clang-format-10
AllowShortLambdasOnASingleLine: All # Only available in clang-format-10
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
Expand Down Expand Up @@ -50,7 +70,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 180
ColumnLimit: 570
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down Expand Up @@ -122,4 +142,3 @@ SpacesInSquareBrackets: false
Standard: c++20
TabWidth: 4
UseTab: Never

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ To only build the Launcher only, you can specify `-LauncherOnly` which will skip
### Important Notes:
- Setting `-RunBuilds` to `$false` will result to *only* generate the build directory.
- Omitting `-Configuration` will result to generate and build for both `Debug` and `Release` versions.
- Specifying `-ForceShaderRebuild` option will force the engine's shaders rebuilding.

## Dependencies

Expand Down
130 changes: 65 additions & 65 deletions Resources/Shaders/deferred_lighting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,98 @@
#extension GL_GOOGLE_include_directive : require
#include "fragment_common.glsl"

layout (location = 0) in vec2 TexCoord;
layout (location = 1) in vec4 ViewPos;
layout(location = 0) in vec2 TexCoord;
layout(location = 1) in vec4 ViewPos;

layout (std140, set = 0, binding = 6) readonly buffer DirectionalLightSB
layout(std140, set = 0, binding = 6) readonly buffer DirectionalLightSB
{
uint Count;
uint Count;
DirectionalLight Data[];
} DirectionalLightBuffer;
}
DirectionalLightBuffer;

layout (std140, set = 0, binding = 7) readonly buffer PointLightSB
layout(std140, set = 0, binding = 7) readonly buffer PointLightSB
{
uint Count;
uint Count;
PointLight Data[];
} PointLightBuffer;
}
PointLightBuffer;

layout (std140, set = 0, binding = 8) readonly buffer SpotLightSB
layout(std140, set = 0, binding = 8) readonly buffer SpotLightSB
{
uint Count;
uint Count;
SpotLight Data[];
} SpotLightBuffer;

layout (set = 0, binding = 10) uniform sampler2D AlbedoSampler;
layout (set = 0, binding = 11) uniform sampler2D PositionSampler;
layout (set = 0, binding = 12) uniform sampler2D NormalSampler;
layout (set = 0, binding = 13) uniform sampler2D SpecularSampler;

}
SpotLightBuffer;

layout (location = 0) out vec4 OutColor;
layout(set = 0, binding = 10) uniform sampler2D AlbedoSampler;
layout(set = 0, binding = 11) uniform sampler2D PositionSampler;
layout(set = 0, binding = 12) uniform sampler2D NormalSampler;
layout(set = 0, binding = 13) uniform sampler2D SpecularSampler;

layout(location = 0) out vec4 OutColor;

vec3 ComputeDirectionalLight(DirectionalLight light, vec3 normal, vec3 viewDir, vec3 albedoMap, vec3 specularMap)
{
vec3 direction = light.Direction.xyz;
vec3 direction = light.Direction.xyz;

vec3 lightDir = normalize(direction);
vec3 ambient = light.Ambient.xyz * albedoMap;
vec3 lightDir = normalize(direction);
vec3 ambient = light.Ambient.xyz * albedoMap;

float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;

vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16);
vec3 specular = spec * light.Specular.xyz * specularMap;
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16);
vec3 specular = spec * light.Specular.xyz * specularMap;

return vec3(ambient + diffuse + specular);
}

vec3 ComputePointLight(PointLight light, vec3 normal, vec3 viewDir, vec4 fragPos, vec3 albedoMap, vec3 specularMap)
{
float dist = length(light.Position.xyz - fragPos.xyz);
float attenuation = 1.0 / ( light.Constant + (light.Linear * dist) + (light.Quadratic * (dist * dist)) );
float dist = length(light.Position.xyz - fragPos.xyz);
float attenuation = 1.0 / (light.Constant + (light.Linear * dist) + (light.Quadratic * (dist * dist)));

vec3 lightDir = normalize(light.Position.xyz - fragPos.xyz);
vec3 ambient = light.Ambient.xyz * albedoMap;
vec3 lightDir = normalize(light.Position.xyz - fragPos.xyz);
vec3 ambient = light.Ambient.xyz * albedoMap;

float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;

vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16); // todo : 16 should be replaced by material.shininess
vec3 specular = spec * light.Specular.xyz * specularMap;
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16); // todo : 16 should be replaced by material.shininess
vec3 specular = spec * light.Specular.xyz * specularMap;

ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;

return vec3(ambient + diffuse + specular);
}

vec3 ComputeSpotLight(SpotLight light, vec3 normal, vec3 viewDir, vec3 fragPos, vec3 albedoMap, vec3 specularMap)
{
vec3 lightDir = normalize(light.Position.xyz - fragPos);
vec3 direction = normalize(light.Direction.xyz);
float theta = dot(lightDir, direction); // check if lighting is inside the spotlight cone
vec3 lightDir = normalize(light.Position.xyz - fragPos);
vec3 direction = normalize(light.Direction.xyz);
float theta = dot(lightDir, direction); // check if lighting is inside the spotlight cone

if(theta > light.CutOff)
if (theta > light.CutOff)
{
vec3 ambient = light.Ambient.xyz * albedoMap;
vec3 ambient = light.Ambient.xyz * albedoMap;

float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;
float diff = max(dot(normal, lightDir), 0.0);
vec3 diffuse = diff * light.Diffuse.xyz * albedoMap;

vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16); // todo : 16 should be replaced by material.shininess
vec3 specular = spec * light.Specular.xyz * specularMap;
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 16); // todo : 16 should be replaced by material.shininess
vec3 specular = spec * light.Specular.xyz * specularMap;

float dist = length(light.Position.xyz - fragPos);
float attenuation = 1.0 / ( light.Constant + (light.Linear * dist) + (light.Quadratic * (dist * dist)) );
float dist = length(light.Position.xyz - fragPos);
float attenuation = 1.0 / (light.Constant + (light.Linear * dist) + (light.Quadratic * (dist * dist)));

diffuse *= attenuation;
specular *= attenuation;
diffuse *= attenuation;
specular *= attenuation;

return vec3(ambient + diffuse + specular);
}
Expand All @@ -102,33 +103,32 @@ vec3 ComputeSpotLight(SpotLight light, vec3 normal, vec3 viewDir, vec3 fragPos,
}
}


void main()
{
vec3 norm = texture( NormalSampler, TexCoord ).rgb;
vec4 fragPos = texture( PositionSampler, TexCoord );
vec3 albedo = texture( AlbedoSampler, TexCoord ).rgb;
vec3 specular = texture( SpecularSampler, TexCoord ).rgb;
vec3 norm = texture(NormalSampler, TexCoord).rgb;
vec4 fragPos = texture(PositionSampler, TexCoord);
vec3 albedo = texture(AlbedoSampler, TexCoord).rgb;
vec3 specular = texture(SpecularSampler, TexCoord).rgb;

vec3 viewDir = normalize( ViewPos.xyz - fragPos.xyz);
vec3 viewDir = normalize(ViewPos.xyz - fragPos.xyz);

vec3 lighting = vec3(0.0);
for (uint i = 0; i < DirectionalLightBuffer.Count; ++i)
for (uint i = 0; i < DirectionalLightBuffer.Count; ++i)
{
DirectionalLight directionalLight = DirectionalLightBuffer.Data[i];
lighting += ComputeDirectionalLight(directionalLight, norm, viewDir, albedo, specular);
DirectionalLight directionalLight = DirectionalLightBuffer.Data[i];
lighting += ComputeDirectionalLight(directionalLight, norm, viewDir, albedo, specular);
}

for (uint i = 0; i < PointLightBuffer.Count; ++i)
{
PointLight pointLight = PointLightBuffer.Data[i];
lighting += ComputePointLight(pointLight, norm, viewDir, fragPos, albedo, specular);
PointLight pointLight = PointLightBuffer.Data[i];
lighting += ComputePointLight(pointLight, norm, viewDir, fragPos, albedo, specular);
}

for (uint i = 0; i < SpotLightBuffer.Count; ++i)
{
SpotLight spotLight = SpotLightBuffer.Data[i];
lighting += ComputeSpotLight(spotLight, norm, viewDir, fragPos.xyz, albedo, specular);
SpotLight spotLight = SpotLightBuffer.Data[i];
lighting += ComputeSpotLight(spotLight, norm, viewDir, fragPos.xyz, albedo, specular);
}

OutColor = vec4(lighting, 1.0);
Expand Down
12 changes: 6 additions & 6 deletions Resources/Shaders/deferred_lighting.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#extension GL_GOOGLE_include_directive : require
#include "vertex_common.glsl"

layout (location = 0) out vec2 TexCoord;
layout (location = 1) out vec4 ViewPos;
layout(location = 0) out vec2 TexCoord;
layout(location = 1) out vec4 ViewPos;

void main()
{
DrawDataView dataView = GetDrawDataView();

vec4 worldPos = dataView.Transform * dataView.Vertex;
ViewPos = Camera.Position;
gl_Position = Camera.Projection * Camera.View * worldPos;
vec4 worldPos = dataView.Transform * dataView.Vertex;
ViewPos = Camera.Position;
gl_Position = Camera.Projection * Camera.View * worldPos;
// Convert gl_Position from NDC [-1, 1] to texture coordinates [0, 1]
TexCoord = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5;
TexCoord = (gl_Position.xy / gl_Position.w) * 0.5 + 0.5;
}
6 changes: 3 additions & 3 deletions Resources/Shaders/depth_prepass_scene.vert
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

void main()
{
DrawDataView dataView = GetDrawDataView();
vec4 worldPosition = dataView.Transform * dataView.Vertex;
gl_Position = Camera.Projection * Camera.View * worldPosition;
DrawDataView dataView = GetDrawDataView();
vec4 worldPosition = dataView.Transform * dataView.Vertex;
gl_Position = Camera.Projection * Camera.View * worldPosition;
}
56 changes: 0 additions & 56 deletions Resources/Shaders/final_color.frag.txt

This file was deleted.

21 changes: 0 additions & 21 deletions Resources/Shaders/final_color.vert.txt

This file was deleted.

Loading

0 comments on commit d08d098

Please sign in to comment.