Skip to content

Commit

Permalink
Revert "albedo normal buffer half3"
Browse files Browse the repository at this point in the history
This reverts commit f39e944.
  • Loading branch information
zhouhang95 committed Jun 24, 2024
1 parent cbf633e commit 28d5df2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
8 changes: 4 additions & 4 deletions zenovis/xinxinoptix/PTKernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ extern "C" __global__ void __raygen__rg()

if (params.denoise) {

const float3 accum_albedo_prev = half3_to_float3(params.albedo_buffer[ image_index ]);
const float3 accum_albedo_prev = params.albedo_buffer[ image_index ];
tmp_albedo = lerp(accum_albedo_prev, tmp_albedo, a);

const float3 accum_normal_prev = half3_to_float3(params.normal_buffer[ image_index ]);
const float3 accum_normal_prev = params.normal_buffer[ image_index ];
tmp_normal = lerp(accum_normal_prev, tmp_normal, a);
}
}
Expand All @@ -435,8 +435,8 @@ extern "C" __global__ void __raygen__rg()
params.frame_buffer_M[ image_index ] = float3_to_half3(accum_mask);

if (params.denoise) {
params.albedo_buffer[ image_index ] = float3_to_half3(tmp_albedo);
params.normal_buffer[ image_index ] = float3_to_half3(tmp_normal);
params.albedo_buffer[ image_index ] = tmp_albedo;
params.normal_buffer[ image_index ] = tmp_normal;
}
}

Expand Down
31 changes: 12 additions & 19 deletions zenovis/xinxinoptix/optixPathTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,15 @@ static void initLaunchParams( PathTracerState& state )

CUDA_CHECK( cudaMallocManaged(
reinterpret_cast<void**>( &state.albedo_buffer_p.reset()),
params.width * params.height * sizeof( ushort3 )
params.width * params.height * sizeof( float3 )
) );
state.params.albedo_buffer = (ushort3*)(CUdeviceptr)state.albedo_buffer_p;
state.params.albedo_buffer = (float3*)(CUdeviceptr)state.albedo_buffer_p;

CUDA_CHECK( cudaMallocManaged(
reinterpret_cast<void**>( &state.normal_buffer_p.reset()),
params.width * params.height * sizeof( ushort3 )
params.width * params.height * sizeof( float3 )
) );
state.params.normal_buffer = (ushort3*)(CUdeviceptr)state.normal_buffer_p;
state.params.normal_buffer = (float3*)(CUdeviceptr)state.normal_buffer_p;

state.params.frame_buffer = nullptr; // Will be set when output buffer is mapped

Expand Down Expand Up @@ -643,15 +643,15 @@ static void handleResize( sutil::CUDAOutputBuffer<uchar4>& output_buffer, Params

CUDA_CHECK( cudaMallocManaged(
reinterpret_cast<void**>( &state.albedo_buffer_p.reset()),
params.width * params.height * sizeof( ushort3 )
params.width * params.height * sizeof( float3 )
) );
state.params.albedo_buffer = (ushort3*)(CUdeviceptr)state.albedo_buffer_p;
state.params.albedo_buffer = (float3*)(CUdeviceptr)state.albedo_buffer_p;

CUDA_CHECK( cudaMallocManaged(
reinterpret_cast<void**>( &state.normal_buffer_p.reset()),
params.width * params.height * sizeof( ushort3 )
params.width * params.height * sizeof( float3 )
) );
state.params.normal_buffer = (ushort3*)(CUdeviceptr)state.normal_buffer_p;
state.params.normal_buffer = (float3*)(CUdeviceptr)state.normal_buffer_p;

state.params.accum_buffer_D = (float3*)(CUdeviceptr)state.accum_buffer_d;
state.params.accum_buffer_S = (float3*)(CUdeviceptr)state.accum_buffer_s;
Expand Down Expand Up @@ -3867,24 +3867,17 @@ void optixrender(int fbo, int samples, bool denoise, bool simpleRender) {
std::string jpg_native_path = zeno::create_directories_when_write_file(path);
stbi_write_jpg(jpg_native_path.c_str(), w, h, 4, p, 100);
if (denoise) {
std::vector<float3> temp_buffer(w * h);
const ushort3* _albedo_buffer = reinterpret_cast<ushort3 *>(state.albedo_buffer_p.handle);
for (auto i = 0; i < w * h; i++) {
temp_buffer[i] = toFloat(_albedo_buffer[i]);
}
const float* _albedo_buffer = reinterpret_cast<float*>(state.albedo_buffer_p.handle);
//SaveEXR(_albedo_buffer, w, h, 4, 0, (path+".albedo.exr").c_str(), nullptr);
auto a_path = path + ".albedo.pfm";
std::string native_a_path = zeno::create_directories_when_write_file(a_path);
zeno::write_pfm(native_a_path.c_str(), w, h, (float*)temp_buffer.data());
zeno::write_pfm(native_a_path.c_str(), w, h, _albedo_buffer);

const ushort3* _normal_buffer = reinterpret_cast<ushort3*>(state.normal_buffer_p.handle);
for (auto i = 0; i < w * h; i++) {
temp_buffer[i] = toFloat(_normal_buffer[i]);
}
const float* _normal_buffer = reinterpret_cast<float*>(state.normal_buffer_p.handle);
//SaveEXR(_normal_buffer, w, h, 4, 0, (path+".normal.exr").c_str(), nullptr);
auto n_path = path + ".normal.pfm";
std::string native_n_path = zeno::create_directories_when_write_file(n_path);
zeno::write_pfm(native_n_path.c_str(), w, h, (float*)temp_buffer.data());
zeno::write_pfm(native_n_path.c_str(), w, h, _normal_buffer);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions zenovis/xinxinoptix/optixPathTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ struct Params
ushort3* frame_buffer_M;

float3* debug_buffer;
ushort3* albedo_buffer;
ushort3* normal_buffer;
float3* albedo_buffer;
float3* normal_buffer;

unsigned int width;
unsigned int height;
Expand Down

0 comments on commit 28d5df2

Please sign in to comment.