Skip to content

Commit

Permalink
General improvements (tippesi#34)
Browse files Browse the repository at this point in the history
* Vertex color support

* Changed caustics and ocean a bit

* Fixed issues

* Fixed heap corruption issues

* Fixed some issues with clouds

* Working on pixel depth offset for impostors

* Better impostors

* Slight performance improvements

* Small fix

* Working on specular probe prefiltering

* Improved the probe filtering further

* Some further fixes

* Small fixes

* Got vegetation rendering to work again

* Update build.yml

* Update build.yml

* Small fixes

* Improved some stuff

* Working on cloud shadows

* Continue to work on cloud shadows

* More widely available cloud shadows

* Also commiting shader changes

* Fixed impostor pixel-depth offset

* Improved terrain rendering performance

* More advanced shader hot reload

* Fixed a few issues

* Starting to fix Vulkan synchonization issues

* Fixed remaining open world Vulkan synchronization issues

* Fixed remaining synchonization issues

* Fixed some shaders

* Fixed up further

* New descriptor set caching

* Sharpen changes

* Normal encoding to reduce bandwith usage

* Added film grain

* Fixed issues

* Fixed normal encoding

---------

Co-authored-by: Simon Tippe <tippex97@gmail.com>
  • Loading branch information
tippesi and Simon Tippe authored Aug 29, 2023
1 parent efefdb8 commit b45bb09
Show file tree
Hide file tree
Showing 169 changed files with 3,155 additions and 1,609 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-components: Vulkan-Headers
vulkan-use-cache: true

- name: Run scripts
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-components: Vulkan-Headers
vulkan-use-cache: true

- name: Run scripts
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-components: Vulkan-Headers
vulkan-use-cache: true

- name: Run scripts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-components: Vulkan-Headers
vulkan-use-cache: true

- name: Run scripts
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
uses: humbletim/setup-vulkan-sdk@v1.2.0
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-components: Vulkan-Headers
vulkan-use-cache: true

- name: Run scripts
Expand Down
59 changes: 28 additions & 31 deletions data/chromesphere.gltf

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion data/shader/ao/rtao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <../common/random.hsh>
#include <../common/flatten.hsh>
#include <../common/convert.hsh>
#include <../common/normalencode.hsh>
#include <../common/bluenoise.hsh>
#include <../brdf/brdfSample.hsh>

Expand Down Expand Up @@ -63,7 +64,7 @@ void main() {

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 worldNorm = normalize(vec3(globalData.ivMatrix * vec4(2.0 * textureLod(normalTexture, texCoord, 0).rgb - 1.0, 0.0)));
vec3 worldNorm = normalize(vec3(globalData.ivMatrix * vec4(DecodeNormal(textureLod(normalTexture, texCoord, 0).rg), 0.0)));

float ao = 0.0;

Expand Down
8 changes: 5 additions & 3 deletions data/shader/ao/ssao.csh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ layout (local_size_x = 8, local_size_y = 8) in;
#include <../common/utility.hsh>
#include <../common/flatten.hsh>
#include <../common/random.hsh>
#include <../common/normalencode.hsh>

layout (set = 3, binding = 0, r16f) writeonly uniform image2D textureOut;
layout(set = 3, binding = 1) uniform sampler2D normalTexture;
Expand Down Expand Up @@ -38,10 +39,11 @@ void main() {
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);
vec3 norm = DecodeNormal(textureLod(normalTexture, texCoord, 0).rg);

ivec2 randomPixel = pixel + Unflatten2D(uniforms.frameCount % 16, ivec2(4));
vec3 randomVec = vec3(2.0 * texelFetch(randomTexture, randomPixel % ivec2(4), 0).xy - 1.0, 0.0);

//Create TBN matrix
vec3 tang = normalize(randomVec - norm * dot(randomVec, norm));
Expand Down
5 changes: 3 additions & 2 deletions data/shader/ao/temporal.csh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <../common/stencil.hsh>
#include <../common/flatten.hsh>
#include <../common/random.hsh>
#include <../common/normalencode.hsh>

layout (local_size_x = 16, local_size_y = 16) in;

Expand Down Expand Up @@ -166,7 +167,7 @@ bool SampleHistory(ivec2 pixel, vec2 historyPixel, out float history, out float
float weights[4] = { (1 - x) * (1 - y), x * (1 - y), (1 - x) * y, x * y };

uint materialIdx = texelFetch(materialIdxTexture, pixel, 0).r;
vec3 normal = 2.0 * texelFetch(normalTexture, pixel, 0).rgb - 1.0;
vec3 normal = DecodeNormal(texelFetch(normalTexture, pixel, 0).rg);
float depth = texelFetch(depthTexture, pixel, 0).r;

float linearDepth = ConvertDepthToViewSpaceDepth(depth);
Expand All @@ -180,7 +181,7 @@ bool SampleHistory(ivec2 pixel, vec2 historyPixel, out float history, out float
uint historyMaterialIdx = texelFetch(historyMaterialIdxTexture, offsetPixel, 0).r;
confidence *= historyMaterialIdx != materialIdx ? 0.0 : 1.0;

vec3 historyNormal = 2.0 * texelFetch(historyNormalTexture, offsetPixel, 0).rgb - 1.0;
vec3 historyNormal = DecodeNormal(texelFetch(historyNormalTexture, offsetPixel, 0).rg);
confidence *= pow(abs(dot(historyNormal, normal)), 2.0);

float historyDepth = texelFetch(historyDepthTexture, offsetPixel, 0).r;
Expand Down
2 changes: 1 addition & 1 deletion data/shader/atmosphere.csh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void main() {
if (LdotV > sunAngle) {
float sunDisk = clamp(0.5 * (LdotV - sunAngle) / (1.0 - sunAngle), 0.0, 1.0);
color += uniforms.sunIntensity * sunDisk;
color += uniforms.sunIntensity * sunDisk * 5.0;
}
#ifndef ENVIRONMENT_PROBE
Expand Down
5 changes: 3 additions & 2 deletions data/shader/bilateralBlur.csh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// NOTE: The kernel is limited to a total size of 65 (2 * 32 + 1).
#include <common/utility.hsh>
#include <common/convert.hsh>
#include <common/normalencode.hsh>

#ifdef HORIZONTAL
layout (local_size_x = 256, local_size_y = 1) in;
Expand Down Expand Up @@ -30,7 +31,7 @@ layout(set = 3, binding = 4, std140) uniform WeightBuffer {
} weights;

const float normalPhi = 32.0;
const float depthPhi = 1.0;
const float depthPhi = 0.5;

#ifdef BLUR_RGB
shared vec3 inputs[320];
Expand Down Expand Up @@ -77,7 +78,7 @@ void LoadGroupSharedData() {
depths[i] = ConvertDepthToViewSpaceDepth(localDepth);
#endif
#ifdef NORMAL_WEIGHT
vec3 localNormal = 2.0 * texelFetch(normalTexture, localOffset, 0).rgb - 1.0;
vec3 localNormal = DecodeNormal(texelFetch(normalTexture, localOffset, 0).rg);
normals[i] = localNormal;
#endif
}
Expand Down
101 changes: 80 additions & 21 deletions data/shader/brdf/filterProbe.csh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#include <../globals.hsh>
#include <../common/random.hsh>
#include <brdf.hsh>
#include <preintegrate.hsh>
#include <filtering.hsh>

layout (local_size_x = 8, local_size_y = 8) in;

layout(set = 3, binding = 0, rgba16f) uniform imageCube filteredCubeMap;
layout(set = 3, binding = 1) uniform samplerCube cubeMap;

layout(push_constant) uniform constants {
int cubeMapMipLevels;
float roughness;
uint mipLevel;
} pushConstants;

vec3 FilterDiffuse(vec3 worldDirection, ivec2 cubeMapSize);
vec3 FilterSpecular(vec3 worldDirection, ivec2 cubeMapSize);

vec3 CubeCoordToWorld(ivec3 cubeCoord, vec2 cubemapSize) {
vec2 texCoord = (vec2(cubeCoord.xy) + 0.5) / cubemapSize;
texCoord = texCoord * 2.0 - 1.0;
Expand All @@ -31,19 +42,29 @@ void main() {
vec3 worldDirection = CubeCoordToWorld(ivec3(gl_GlobalInvocationID),
vec2(imageSize(filteredCubeMap).xy));

uint sampleCount = 256u;
vec4 acc = vec4(0.0);

ivec2 size = textureSize(cubeMap, 0);
vec3 N = normalize(worldDirection);
for (uint i = 0u; i < sampleCount; i++) {
float raySeed = float(gl_LocalInvocationIndex);
float curSeed = float(i);
float u0 = random(raySeed, curSeed);
curSeed += 0.5;
float u1 = random(raySeed, curSeed);

vec2 Xi = vec2(u0, u1);
#ifdef FILTER_DIFFUSE
vec3 color = FilterDiffuse(worldDirection, size);
#else
vec3 color = FilterSpecular(worldDirection, size);
#endif

imageStore(filteredCubeMap, ivec3(gl_GlobalInvocationID), vec4(color, 0.0));

}

vec3 FilterDiffuse(vec3 worldDirection, ivec2 cubeMapSize) {

const uint sampleCount = 256u;

vec4 color = vec4(0.0);

vec3 N = normalize(worldDirection);

for (uint i = 0u; i < sampleCount; i++) {
vec2 Xi = Hammersley(i, sampleCount);

vec3 L;
float NdotL;
Expand All @@ -52,23 +73,61 @@ void main() {

NdotL = saturate(NdotL);
if (NdotL > 0.0) {
/*
// Only works for specular
// https://developer.nvidia.com/gpugems/gpugems3/part-iii-rendering/chapter-20-gpu-based-importance-sampling
float pdf = max(0.0, dot(N, L) / PI);
color.xyz += min(textureLod(cubeMap, L, 5.0).rgb, 5.0);
color.w += 1.0;
}

}

return color.rgb / color.a;

}

vec3 FilterSpecular(vec3 worldDirection, ivec2 cubeMapSize) {

const uint maxSampleCount = 256u;

uint sampleCount = uint(mix(16.0, float(maxSampleCount), pushConstants.roughness));
sampleCount = pushConstants.mipLevel == 0u ? 1u : sampleCount;

vec4 color = vec4(0.0);

vec3 N = normalize(worldDirection);
vec3 V = N;

for (uint i = 0u; i < sampleCount; i++) {
vec2 Xi = Hammersley(i, sampleCount);

vec3 L;
float NdotL;
float pdf;
float alpha = sqr(pushConstants.roughness);
ImportanceSampleGGX(Xi, N, V, alpha, L, pdf);

NdotL = dot(N, L);
vec3 H = normalize(L + V);
NdotL = saturate(NdotL);

if (NdotL > 0.0) {
float NdotH = saturate(dot(N, H));
float LdotH = saturate(dot(L, H));

pdf = DistributionGGX(NdotH, alpha) / 4.0;

float solidAngleTexel = 4.0 * PI / (6.0 * float(size.x * size.y));
float solidAngleTexel = 4.0 * PI / (6.0 * float(cubeMapSize.x * cubeMapSize.y));
float solidAngleSample = 1.0 / (float(sampleCount) * pdf);
float lod = clamp(0.5 * log2(float(solidAngleSample / solidAngleTexel)), 0.0, 7.0);
*/
float lod = clamp(0.5 * log2(float(solidAngleSample / solidAngleTexel)) + 1.0,
0.0, float(pushConstants.cubeMapMipLevels - 1.0));

lod = pushConstants.mipLevel == 0u ? 0.0 : lod;

color.xyz += clamp(textureLod(cubeMap, L, lod).rgb, vec3(0.0), vec3(5.0)) * NdotL;
color.w += NdotL;

acc.xyz += min(textureLod(cubeMap, L, 5.0).rgb, 1.0);
}

}

vec4 color = acc / float(sampleCount);

imageStore(filteredCubeMap, ivec3(gl_GlobalInvocationID), color);
return color.rgb / color.a;

}
2 changes: 1 addition & 1 deletion data/shader/brdf/importanceSample.hsh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ vec3 ImportanceSampleGGXVNDF(vec2 Xi, vec3 V, float roughness) {
}

void ImportanceSampleGGXVNDF(vec2 Xi, vec3 N, vec3 V, float roughness,
out vec3 L, out float pdf) {
out vec3 L, out float pdf) {

vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
vec3 tangent = normalize(cross(up, N));
Expand Down
Loading

0 comments on commit b45bb09

Please sign in to comment.