From 4e77c3e8416af113cc244389bc1a7f848c2f6250 Mon Sep 17 00:00:00 2001 From: iaomw Date: Fri, 11 Oct 2024 05:52:05 -0700 Subject: [PATCH] color dithering --- zenovis/xinxinoptix/PTKernel.cu | 8 +++++++- zenovis/xinxinoptix/SDK/cuda/random.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/zenovis/xinxinoptix/PTKernel.cu b/zenovis/xinxinoptix/PTKernel.cu index 8141e41c5b..a199625b08 100644 --- a/zenovis/xinxinoptix/PTKernel.cu +++ b/zenovis/xinxinoptix/PTKernel.cu @@ -434,10 +434,16 @@ extern "C" __global__ void __raygen__rg() params.accum_buffer_S[ image_index ] = make_float3( accum_color_s.x,accum_color_s.y, accum_color_s.z); params.accum_buffer_T[ image_index ] = make_float3( accum_color_t.x,accum_color_t.y,accum_color_t.z); params.accum_buffer_B[ image_index ] = float_to_half(accum_color_b.x); - params.frame_buffer[ image_index ] = make_color ( accum_color ); + params.frame_buffer_M[ image_index ] = float3_to_half3(accum_mask); params.frame_buffer_P[ image_index ] = float3_to_half3(click_pos); + auto uv = float2{idx.x+0.5f, idx.y+0.5f}; + auto dither = InterleavedGradientNoise(uv); + + dither = (dither-0.5f)/255; + params.frame_buffer[ image_index ] = make_color( accum_color + dither); + if (params.denoise) { params.albedo_buffer[ image_index ] = tmp_albedo; params.normal_buffer[ image_index ] = tmp_normal; diff --git a/zenovis/xinxinoptix/SDK/cuda/random.h b/zenovis/xinxinoptix/SDK/cuda/random.h index ce6784de0f..550f37f6f9 100644 --- a/zenovis/xinxinoptix/SDK/cuda/random.h +++ b/zenovis/xinxinoptix/SDK/cuda/random.h @@ -28,6 +28,9 @@ #pragma once +#include +#include + template static __host__ __device__ __inline__ unsigned int tea( unsigned int val0, unsigned int val1 ) { @@ -150,3 +153,15 @@ float2 sobolRnd2(unsigned int & seed) //return make_float2(rnd(seed), rnd(seed)); } + +__forceinline__ __device__ float fractf(float x) +{ + return x - floorf(x); +} + +/* Gradient noise from Jorge Jimenez's presentation: */ +/* http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare */ +__forceinline__ __device__ float InterleavedGradientNoise(float2 uv) +{ + return fractf(52.9829189 * fractf(dot(uv, float2{0.06711056, 0.00583715}))); +} \ No newline at end of file