Skip to content

Commit

Permalink
Fixed feature map generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismile committed Dec 1, 2023
1 parent 834249c commit b744227
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 55 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/build-brew.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ jobs:
fi
brew install gcc
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install llvm libomp pkg-config
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew update
#rm /usr/local/bin/2to3 || true
#rm /usr/local/bin/idle3 || true
#rm /usr/local/bin/pydoc3 || true
#rm /usr/local/bin/python3 || true
#rm /usr/local/bin/python3-config || true
brew install --force --overwrite llvm libomp pkg-config
else
echo "$RUNNER_OS is not supported."
exit 1
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/build-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,24 @@ jobs:
cd ~/VulkanSDK/$VULKAN_SDK_VERSION
sudo ./install_vulkan.py || true
sudo hdiutil unmount "${vulkan_dir}"
brew install llvm libomp pkg-config
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew update
#rm /usr/local/bin/2to3 || true
#rm /usr/local/bin/idle3 || true
#rm /usr/local/bin/pydoc3 || true
#rm /usr/local/bin/python3 || true
#rm /usr/local/bin/python3-config || true
brew install --force --overwrite llvm libomp pkg-config
else
echo "$RUNNER_OS is not supported."
exit 1
fi
- name: Setup vcpkg
uses: lukka/run-vcpkg@v10
uses: lukka/run-vcpkg@v11
with:
vcpkgGitCommitId: '4cac260c4b7331538d31886f57739fea0bffa27e'
#doNotCacheOnWorkflowFailure: true
doNotCacheOnWorkflowFailure: true

- name: Create custom vcpkg triplet
run: |
Expand Down
29 changes: 25 additions & 4 deletions Data/Shaders/VPT/Clouds.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ void pathTraceSample(int i, bool onlyFirstEvent, out ScatterEvent firstEvent){
#endif

if (!onlyFirstEvent) {
#ifdef WRITE_CLOUDONLY_MAP
// Accumulate cloudOnly
vec4 cloudOnlyOld = frame == 0 ? vec4(0) : imageLoad(cloudOnlyImage, imageCoord);
vec4 cloudOnly = firstEvent.hasValue ? vec4(result, 1) : vec4(0);
cloudOnly = mix(cloudOnlyOld, cloudOnly, 1.0 / float(frame + 1));
imageStore(cloudOnlyImage, imageCoord, cloudOnly);
#endif

#ifdef WRITE_BACKGROUND_MAP
// Accumulate background
vec4 backgroundOld = frame == 0 ? vec4(0) : imageLoad(backgroundImage, imageCoord);
vec4 background = firstEvent.hasValue ? vec4(sampleSkybox(w), 1) : vec4(result, 1);
background = mix(backgroundOld, background, 1.0 / float(frame + 1));
imageStore(backgroundImage, imageCoord, background);

#endif

// Accumulate result
vec3 resultOld = frame == 0 ? vec3(0) : imageLoad(accImage, imageCoord).xyz;
Expand All @@ -116,44 +119,62 @@ void pathTraceSample(int i, bool onlyFirstEvent, out ScatterEvent firstEvent){
imageStore(resultImage, imageCoord, vec4(result, 1));
}

#ifdef WRITE_POSITION_MAP
vec4 positionOld = frame == 0 ? vec4(0) : imageLoad(firstX, imageCoord);
vec4 position = firstEvent.hasValue ? vec4(firstEvent.x, 1) : vec4(0);
position = mix(positionOld, position, 1.0 / float(frame + 1));
imageStore(firstX, imageCoord, position);
#endif

#ifdef WRITE_DEPTH_MAP
vec2 depthOld = frame == 0 ? vec2(0) : imageLoad(depthImage, imageCoord).xy;
depthOld.y = depthOld.y * depthOld.y + depthOld.x * depthOld.x;
vec2 depth = firstEvent.hasValue ? vec2(firstEvent.depth, firstEvent.depth * firstEvent.depth) : vec2(0);
depth = mix(depthOld, depth, 1.0 / float(frame + 1));
imageStore(depthImage, imageCoord, vec4(depth.x, sqrt(max(0.,depth.y - depth.x * depth.x)),0,0));
#endif

#ifdef WRITE_DENSITY_MAP
vec2 densityOld = frame == 0 ? vec2(0) : imageLoad(densityImage, imageCoord).xy;
densityOld.y = densityOld.y * densityOld.y + densityOld.x * densityOld.x;
vec2 density = firstEvent.hasValue ? vec2(firstEvent.density * .001, firstEvent.density * firstEvent.density * .001 * .001) : vec2(0);
density = mix(densityOld, density, 1.0 / float(frame + 1));
imageStore(densityImage, imageCoord, vec4(density.x, sqrt(max(0.,density.y - density.x * density.x)),0,0));
#endif

#ifdef WRITE_REPROJ_UV_MAP
vec2 oldReprojUV = frame == 0 ? vec2(-1,-1) : imageLoad(reprojUVImage, imageCoord).xy;
vec4 prevClip = (parameters.previousViewProjMatrix * vec4(firstEvent.x, 1));
vec2 reprojUV = prevClip.xy / prevClip.w;
reprojUV = reprojUV * .5 + .5;
reprojUV = firstEvent.hasValue? reprojUV : oldReprojUV;
reprojUV = firstEvent.hasValue ? reprojUV : oldReprojUV;
imageStore(reprojUVImage, imageCoord, vec4(reprojUV, 0, 0));
#endif

// Saving the first scatter position and direction
if (firstEvent.hasValue) {
vec3 diff = getCloudFiniteDifference(firstEvent.x);
//imageStore(firstX, imageCoord, vec4(firstEvent.x, firstEvent.pdf_x));

#ifdef WRITE_NORMAL_MAP
vec3 diff = getCloudFiniteDifference(firstEvent.x);
vec3 diffOld = frame == 0 ? vec3(0) : imageLoad(normalImage, imageCoord).xyz;
diff = mix(diffOld, diff, 1.0 / float(frame + 1));
imageStore(normalImage, imageCoord, vec4(diff,1));
#endif

//imageStore(firstX, imageCoord, vec4(firstEvent.x, firstEvent.pdf_x));
#ifdef WRITE_FIRST_W_MAP
imageStore(firstW, imageCoord, vec4(firstEvent.w, firstEvent.pdf_w));
#endif
} else {
//imageStore(firstX, imageCoord, vec4(0));

#ifdef WRITE_NORMAL_MAP
imageStore(normalImage, imageCoord, vec4(0));
#endif

#ifdef WRITE_FIRST_W_MAP
imageStore(firstW, imageCoord, vec4(0));
#endif
}

#ifdef COMPUTE_PRIMARY_RAY_ABSORPTION_MOMENTS
Expand Down
9 changes: 9 additions & 0 deletions Data/Shaders/VPT/DeltaTracking.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,15 @@ vec3 deltaTracking(
}

if (lastScalarSign != currentScalarSign) {
if (!firstEvent.hasValue) {
firstEvent.x = x;
firstEvent.pdf_x = 0;
firstEvent.w = vec3(0.);
firstEvent.pdf_w = 0;
firstEvent.hasValue = true;
firstEvent.density = parameters.extinction.x;
firstEvent.depth = tMax - d + t;
}
refineIsoSurfaceHit(x1, x0, currentScalarSign);
x = x1;
vec3 color = getIsoSurfaceHit(x, w);
Expand Down
21 changes: 21 additions & 0 deletions Data/Shaders/VPT/VptHeader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ layout (binding = 4) uniform FrameInfo {

layout (binding = 5, rgba32f) uniform image2D accImage;

#ifdef WRITE_POSITION_MAP
layout (binding = 6, rgba32f) uniform image2D firstX;
#endif

#ifdef WRITE_FIRST_W_MAP
layout (binding = 7, rgba32f) uniform image2D firstW;
#endif

#if !defined(USE_NANOVDB) && (defined(USE_RESIDUAL_RATIO_TRACKING) || defined(USE_DECOMPOSITION_TRACKING))
layout (binding = 8) uniform sampler3D superVoxelGridImage;
Expand All @@ -111,12 +115,29 @@ layout (binding = 12, r32f) uniform image2DArray primaryRayAbsorptionMomentsImag
layout (binding = 13, r32f) uniform image2DArray scatterRayAbsorptionMomentsImage;
#endif

#ifdef WRITE_CLOUDONLY_MAP
layout (binding = 14, rgba32f) uniform image2D cloudOnlyImage;
#endif

#ifdef WRITE_DEPTH_MAP
layout (binding = 15, rg32f) uniform image2D depthImage;
#endif

#ifdef WRITE_DENSITY_MAP
layout (binding = 16, rg32f) uniform image2D densityImage;
#endif

#ifdef WRITE_BACKGROUND_MAP
layout (binding = 17, rg32f) uniform image2D backgroundImage;
#endif

#ifdef WRITE_REPROJ_UV_MAP
layout (binding = 18, rg32f) uniform image2D reprojUVImage;
#endif

#ifdef WRITE_NORMAL_MAP
layout (binding = 19, rgba32f) uniform image2D normalImage;
#endif



Expand Down
36 changes: 31 additions & 5 deletions src/Denoiser/Denoiser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace sgl {
class PropertyEditor;
}


enum class DenoiserType {
NONE,
EAW,
Expand All @@ -62,20 +63,45 @@ const char* const DENOISER_NAMES[] = {
#endif
};


// enum type, name, num channels, num channels padded
#define FEATURE_MAPS \
FEATURE_MAP(COLOR, "Color", 4, 4) \
FEATURE_MAP(ALBEDO, "Albedo", 4, 4) \
FEATURE_MAP(FLOW, "Flow", 2, 2) \
FEATURE_MAP(POSITION, "Position", 3, 4) \
FEATURE_MAP(NORMAL, "Normal", 3, 4) \
FEATURE_MAP(CLOUDONLY, "CloudOnly", 4, 4) \
FEATURE_MAP(DEPTH, "Depth", 2, 2) \
FEATURE_MAP(DENSITY, "Density", 2, 2) \
FEATURE_MAP(BACKGROUND, "Background", 4, 4) \
FEATURE_MAP(REPROJ_UV, "Reproj_UV", 2, 2) \
FEATURE_MAP(UNUSED, "Unused", 1, 1) \

enum class FeatureMapType {
COLOR, ALBEDO, FLOW, POSITION, NORMAL, CLOUDONLY, DEPTH, DENSITY, BACKGROUND, REPROJ_UV
#define FEATURE_MAP(enum_name, _1, _2, _3) enum_name,
FEATURE_MAPS
#undef FEATURE_MAP
};

const char* const FEATURE_MAP_NAMES[] = {
"Color", "Albedo", "Flow", "Position", "Normal",
"CloudOnly", "Depth", "Density", "Background", "Reproj_UV"
#define FEATURE_MAP(_1, string_name, _2, _3) string_name,
FEATURE_MAPS
#undef FEATURE_MAP
};

const uint32_t FEATURE_MAP_NUM_CHANNELS[] = {
4, 4, 2, 3, 3, 4, 2, 2, 4, 2
#define FEATURE_MAP(_1, _2, num_channels, _3) num_channels,
FEATURE_MAPS
#undef FEATURE_MAP
};
const uint32_t FEATURE_MAP_NUM_CHANNELS_PADDED[] = {
4, 4, 2, 4, 4, 4, 2, 2, 4, 2
#define FEATURE_MAP(_1, _2, _3, num_channels_padded) num_channels_padded,
FEATURE_MAPS
#undef FEATURE_MAP
};


class Denoiser {
public:
virtual ~Denoiser() = default;
Expand Down
Loading

0 comments on commit b744227

Please sign in to comment.