Skip to content

Commit

Permalink
Port open world features to Vulkan (tippesi#28)
Browse files Browse the repository at this point in the history
* Fixed many terrain loading issues

* Terrain rendering is working again

* Working on terrain shadows

* The ocean rendering (not simulation) is working again

* Fixed a few issues

* Working on caustics

* Fixes regarding Windows

* Working on ocean simulation

* Further work on ocean simulation

* Ocean simulation is working fully now

* Replace tabs with spaces

* Fix of shadow on caustics

* Improved upsampling for reflections and clouds

* Working on an improved impostor system

* Impostor generation is working again

* Continuing work on impostors

* Changes to shaders

* Impostor shadow rendering working again

* Fixing some issues

* Fixing remaining issues for PR

* More fixes
  • Loading branch information
tippesi authored Jun 13, 2023
1 parent ade9030 commit 39476a3
Show file tree
Hide file tree
Showing 419 changed files with 19,460 additions and 18,830 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,3 @@ jobs:
-DATLAS_DEMO=ON -G Ninja
parallel: 16
build-type: ${{ matrix.build-type }}

code-quality:
runs-on: ubuntu-latest
name: Check code quality
needs: [windows-build, linux-build, macos-build]

steps:
- name: Check code meets quality standards
id: codiga
uses: codiga/github-action@master
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
codiga_api_token: ${{ secrets.CODIGA_API_TOKEN }}
force_ref: 'none'
min_quality_grade: 'GOOD'
min_quality_score: '85'
max_defects_rate: '0.01'
max_complex_functions_rate: '0.03'
max_long_functions_rate: '0.2'
project_name: 'Atlas-Engine'
max_timeout_sec: '1200'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ cmake_minimum_required(VERSION 3.7)
# Only 64 bit is supported
###################################################################
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "32 bit isn't supported")
message(FATAL_ERROR "32 bit isn't supported")
endif()

# Options and compiler settings ###################################################################
Expand Down
20 changes: 10 additions & 10 deletions data/shader/ao/rtao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,27 @@ void main() {
ivec2 groupOffset = (tileBaseOffset + tileGroupOffset) * ivec2(gl_WorkGroupSize);
ivec2 pixel = ivec2(gl_LocalInvocationID.xy) + groupOffset;
if (int(pixel.x) < resolution.x &&
int(pixel.y) < resolution.y) {
if (int(pixel.x) < resolution.x &&
int(pixel.y) < resolution.y) {
vec2 texCoord = (vec2(pixel) + vec2(0.5)) / vec2(resolution);
vec2 texCoord = (vec2(pixel) + vec2(0.5)) / vec2(resolution);

float depth = texelFetch(shadowMap, pixel, 0).r;
int offsetIdx = texelFetch(offsetTexture, pixel, 0).r;
ivec2 offset = offsets[offsetIdx];

vec2 recontructTexCoord = (2.0 * vec2(pixel) + offset + vec2(0.5)) / (2.0 * vec2(resolution));
vec3 worldPos = vec3(globalData.ivMatrix * vec4(ConvertDepthToViewSpace(depth, recontructTexCoord), 1.0));
vec3 worldPos = vec3(globalData.ivMatrix * vec4(ConvertDepthToViewSpace(depth, recontructTexCoord), 1.0));
vec3 worldNorm = normalize(vec3(globalData.ivMatrix * vec4(2.0 * textureLod(normalTexture, texCoord, 0).rgb - 1.0, 0.0)));

float ao = 0.0;

int sampleIdx = int(uniforms.frameSeed);
vec2 blueNoiseVec = vec2(
SampleBlueNoise(pixel, sampleIdx, 0, scramblingRankingTexture, sobolSequenceTexture),
SampleBlueNoise(pixel, sampleIdx, 1, scramblingRankingTexture, sobolSequenceTexture)
);
vec2 blueNoiseVec = vec2(
SampleBlueNoise(pixel, sampleIdx, 0, scramblingRankingTexture, sobolSequenceTexture),
SampleBlueNoise(pixel, sampleIdx, 1, scramblingRankingTexture, sobolSequenceTexture)
);

const int sampleCount = 1;
for (uint i = 0; i < sampleCount; i++) {
Expand All @@ -97,6 +97,6 @@ void main() {
float result = 1.0 - (ao / float(sampleCount));

imageStore(rtaoImage, pixel, vec4(result, 0.0, 0.0, 0.0));
}
}

}
30 changes: 15 additions & 15 deletions data/shader/ao/ssao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ void main() {
if (pixel.x >= int(resolution.x) || pixel.y >= int(resolution.y)) return;

vec2 texCoord = (vec2(pixel) + 0.5) / resolution;
// tile noise texture over screen based on screen dimensions divided by noise size
vec2 noiseScale = vec2(resolution.x / 4.0, resolution.y / 4.0);
// tile noise texture over screen based on screen dimensions divided by noise size
vec2 noiseScale = vec2(resolution.x / 4.0, resolution.y / 4.0);

float depth = texelFetch(shadowMap, pixel, 0).r;
// Early exit, also prevents halo
vec3 fragPos = ConvertDepthToViewSpace(depth, texCoord);
float depth = texelFetch(shadowMap, pixel, 0).r;
// Early exit, also prevents halo
vec3 fragPos = ConvertDepthToViewSpace(depth, texCoord);
vec3 norm = 2.0 * textureLod(normalTexture, texCoord, 0).rgb - 1.0;
vec3 randomVec = vec3(2.0 * texelFetch(randomTexture, pixel % ivec2(4), 0).xy - 1.0, 0.0);
//Create TBN matrix
vec3 tang = normalize(randomVec - norm * dot(randomVec, norm));
vec3 bitang = normalize(cross(norm, tang));
mat3 TBN = mat3(tang, bitang, norm);
//Calculate occlusion factor
float occlusion = 0.0;
float seed = float(uniforms.frameCount);
Expand All @@ -64,14 +64,14 @@ void main() {
offset.xyz = offset.xyz * 0.5 + 0.5; // transform to range 0.0 - 1.0

// get sample depth
vec3 samplePos = ConvertDepthToViewSpace(textureLod(shadowMap, offset.xy, 0).r, offset.xy);
vec3 samplePos = ConvertDepthToViewSpace(textureLod(shadowMap, offset.xy, 0).r, offset.xy);

float rangeCheck = abs(fragPos.z - samplePos.z) < uniforms.radius ? 1.0 : 0.0;
float delta = samplePos.z - ssaoSample.z;
float rangeCheck = abs(fragPos.z - samplePos.z) < uniforms.radius ? 1.0 : 0.0;
float delta = samplePos.z - ssaoSample.z;
occlusion += (delta > 0.0 ? 1.0 : 0.0) * rangeCheck;
}
float result = pow(1.0 - (occlusion / float(uniforms.sampleCount)), 2.0);
result = depth == 1.0 ? 0.0 : result;
imageStore(textureOut, pixel, vec4(result, 0.0, 0.0, 0.0));
Expand Down
10 changes: 5 additions & 5 deletions data/shader/ao/temporal.csh
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ const ivec2 pixelOffsets[4] = ivec2[4](
);

float FetchTexel(ivec2 texel) {
float value = max(texelFetch(currentTexture, texel, 0).r, 0);
return value;
float value = max(texelFetch(currentTexture, texel, 0).r, 0);
return value;

}

void LoadGroupSharedData() {

ivec2 workGroupOffset = ivec2(gl_WorkGroupID) * ivec2(gl_WorkGroupSize) - ivec2(kernelRadius);
ivec2 workGroupOffset = ivec2(gl_WorkGroupID) * ivec2(gl_WorkGroupSize) - ivec2(kernelRadius);

uint workGroupSize = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
uint workGroupSize = gl_WorkGroupSize.x * gl_WorkGroupSize.y;
for(uint i = gl_LocalInvocationIndex; i < sharedDataSize; i += workGroupSize) {
ivec2 localOffset = Unflatten2D(int(i), unflattenedSharedDataSize);
ivec2 texel = localOffset + workGroupOffset;
Expand Down
2 changes: 1 addition & 1 deletion data/shader/atmosphere.csh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void main() {
vec2 texCoord = (vec2(pixel) + 0.5) / resolution;

// Don't use the global inverse matrices here, since we also render the cubemap with this shader
vec3 viewPos = ConvertDepthToViewSpace(depth, texCoord, uniforms.ipMatrix);
vec3 viewPos = ConvertDepthToViewSpace(depth, texCoord, uniforms.ipMatrix);
#ifndef ENVIRONMENT_PROBE
vec3 worldPos = vec3(uniforms.ivMatrix * vec4(viewPos, 1.0));
#else
Expand Down
8 changes: 4 additions & 4 deletions data/shader/bilateralBlur.csh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ layout(set = 3, binding = 3) uniform sampler2D normalTexture;
#endif

layout(push_constant) uniform constants {
int kernelSize;
int kernelSize;
} pushConstants;

layout(set = 3, binding = 4, std140) uniform WeightBuffer {
vec4 data[32];
vec4 data[32];
} weights;

const float normalPhi = 32.0;
Expand Down Expand Up @@ -124,7 +124,7 @@ void main() {

float depthDiff = abs(centerDepth - depth);
float depthWeight = min(exp(-depthDiff / depthPhi), 1.0);
weight *= depthWeight;
weight *= depthWeight;
#endif
#ifdef NORMAL_WEIGHT
vec3 normal = normals[sharedDataOffset - i];
Expand All @@ -145,7 +145,7 @@ void main() {

float depthDiff = abs(centerDepth - depth);
float depthWeight = min(exp(-depthDiff / depthPhi), 1.0);
weight *= depthWeight;
weight *= depthWeight;
#endif
#ifdef NORMAL_WEIGHT
vec3 normal = normals[sharedDataOffset + i];
Expand Down
12 changes: 6 additions & 6 deletions data/shader/bloom
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ uniform bool bloom;

vec3 CalculateBloom(vec3 color) {

if(bloom) {
float brightness = dot(color, vec3(1.0f));
return max(color * (brightness), 0.0f);
}
if(bloom) {
float brightness = dot(color, vec3(1.0f));
return max(color * (brightness), 0.0f);
}

}
12 changes: 6 additions & 6 deletions data/shader/bloom.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ uniform float bloomPower;
out vec3 color;

void main() {
vec3 fragColor = texture(diffuseMap, fTexCoord).rgb;
float bloomBrightness = pow(dot(fragColor.xyz, bloomThreshold.xyz), bloomPower);
color = fragColor.xyz * bloomBrightness;
vec3 fragColor = texture(diffuseMap, fTexCoord).rgb;
float bloomBrightness = pow(dot(fragColor.xyz, bloomThreshold.xyz), bloomPower);
color = fragColor.xyz * bloomBrightness;
}
6 changes: 3 additions & 3 deletions data/shader/bloom.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ layout(location=0)in vec2 vPosition;
out vec2 fTexCoord;

void main() {
fTexCoord = (vPosition + 1.0) / 2.0;
gl_Position = vec4(vPosition, 0.0, 1.0);
fTexCoord = (vPosition + 1.0) / 2.0;
gl_Position = vec4(vPosition, 0.0, 1.0);

}
42 changes: 21 additions & 21 deletions data/shader/brdf/brdf.hsh
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
#include <../common/PI.hsh>

struct BRDFSample {
vec3 reflectance;
vec3 L;
float pdf;
vec3 reflectance;
vec3 L;
float pdf;
};

vec3 FresnelSchlick(vec3 F0, float F90, float CosTheta) {

return F0 + (vec3(F90) - F0) * pow(1.0 - CosTheta, 5.0);
return F0 + (vec3(F90) - F0) * pow(1.0 - CosTheta, 5.0);

}

float RenormalizedDisneyDiffuse(float NdotV, float NdotL, float LdotH, float linearRoughness) {

float energyBias = mix(0.0, 0.5, linearRoughness);
float energyFactor = mix(1.0, 1.0 / 1.51, linearRoughness);
float FD90 = energyBias + 2.0 * LdotH * LdotH * linearRoughness;
float lightScatter = FresnelSchlick(vec3(1.0), FD90, NdotL).r;
float viewScatter = FresnelSchlick(vec3(1.0), FD90, NdotV).r;
float energyBias = mix(0.0, 0.5, linearRoughness);
float energyFactor = mix(1.0, 1.0 / 1.51, linearRoughness);
float FD90 = energyBias + 2.0 * LdotH * LdotH * linearRoughness;
float lightScatter = FresnelSchlick(vec3(1.0), FD90, NdotL).r;
float viewScatter = FresnelSchlick(vec3(1.0), FD90, NdotV).r;

return lightScatter * viewScatter * energyFactor;
return lightScatter * viewScatter * energyFactor;

}

float VisibilitySmithGGXSeparable(float CosTheta, float alpha) {

float alpha2 = alpha * alpha;
return 2.0 / (1.0 + sqrt(alpha2 + (1 - alpha2) * CosTheta * CosTheta));
float alpha2 = alpha * alpha;
return 2.0 / (1.0 + sqrt(alpha2 + (1 - alpha2) * CosTheta * CosTheta));

}

float VisibilitySmithGGXCorrelated(float NdotL, float NdotV, float alpha) {

float alpha2 = alpha * alpha;
float GGXL = NdotV * sqrt((-NdotL * alpha2 + NdotL) * NdotL + alpha2);
float GGXV = NdotL * sqrt((-NdotV * alpha2 + NdotV) * NdotV + alpha2);
float alpha2 = alpha * alpha;
float GGXL = NdotV * sqrt((-NdotL * alpha2 + NdotL) * NdotL + alpha2);
float GGXV = NdotL * sqrt((-NdotV * alpha2 + NdotV) * NdotV + alpha2);

// Avoid NaN
return 0.5 / (GGXL + GGXV + 0.0000001);
// Avoid NaN
return 0.5 / (GGXL + GGXV + 0.0000001);

}

float DistributionGGX(float NdotH, float alpha) {

float alpha2 = alpha * alpha;
float f = (NdotH * alpha2 - NdotH) * NdotH + 1.0;
float alpha2 = alpha * alpha;
float f = (NdotH * alpha2 - NdotH) * NdotH + 1.0;

// Avoid NaN
return alpha2 / (f * f + 0.0000001) * INV_PI;
// Avoid NaN
return alpha2 / (f * f + 0.0000001) * INV_PI;

}
22 changes: 11 additions & 11 deletions data/shader/brdf/brdfEval.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

vec3 EvaluateDiffuseBRDF(Surface surface) {

// Perceptual roughness to roughness
float roughness = max(sqr(surface.material.roughness), 0.00001);
// Perceptual roughness to roughness
float roughness = max(sqr(surface.material.roughness), 0.00001);

float disneyDiffuse = RenormalizedDisneyDiffuse(surface.NdotV,
surface.NdotL, surface.LdotH, roughness);
float disneyDiffuse = RenormalizedDisneyDiffuse(surface.NdotV,
surface.NdotL, surface.LdotH, roughness);

return (1.0 - surface.material.metalness) * surface.material.baseColor *
disneyDiffuse * INV_PI;
return (1.0 - surface.material.metalness) * surface.material.baseColor *
disneyDiffuse * INV_PI;

}

vec3 EvaluateSpecularBRDF(Surface surface) {

// Perceptual roughness to roughness
float roughness = max(sqr(surface.material.roughness), 0.00001);
float roughness = max(sqr(surface.material.roughness), 0.00001);

vec3 F = FresnelSchlick(surface.F0, surface.F90, surface.LdotH);
float G = VisibilitySmithGGXCorrelated(surface.NdotV, surface.NdotL, roughness);
float D = DistributionGGX(surface.NdotH, roughness);
return F * D * G;
float G = VisibilitySmithGGXCorrelated(surface.NdotV, surface.NdotL, roughness);
float D = DistributionGGX(surface.NdotH, roughness);
return F * D * G;

}

Expand Down
6 changes: 3 additions & 3 deletions data/shader/brdf/createProbeFace.csh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ void main() {

ivec2 size = textureSize(lightIn, 0);
ivec2 coord = ivec2(gl_GlobalInvocationID);
if (coord.x < size.x &&
coord.y < size.y) {
if (coord.x < size.x &&
coord.y < size.y) {

// Needed for irradiance integration and sky visibility
vec3 light = texelFetch(lightIn, coord, 0).rgb;
Expand Down
Loading

0 comments on commit 39476a3

Please sign in to comment.