Skip to content

Commit

Permalink
color dithering
Browse files Browse the repository at this point in the history
  • Loading branch information
iaomw committed Oct 11, 2024
1 parent b20b398 commit 4e77c3e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions zenovis/xinxinoptix/SDK/cuda/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

#pragma once

#include <vector_types.h>
#include <sutil/vec_math.h>

template<unsigned int N>
static __host__ __device__ __inline__ unsigned int tea( unsigned int val0, unsigned int val1 )
{
Expand Down Expand Up @@ -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})));
}

0 comments on commit 4e77c3e

Please sign in to comment.