Skip to content

Commit

Permalink
Improve handling of SMAA textures
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyr committed Sep 28, 2019
1 parent 95b3a32 commit f854a27
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
4 changes: 2 additions & 2 deletions resource/blink/SMAABlend.blk
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ kernel SMAABlend : ImageComputationKernel<ePixelWise>
coords += float2(0.5f, 0.5f);

SampleType(area_tex) in_area = bilinear(area_tex, coords[0], coords[1]);
return float2(in_area[0], in_area[1]);
return float2(in_area[0]/255, in_area[1]/255);
}

/**
Expand All @@ -341,7 +341,7 @@ kernel SMAABlend : ImageComputationKernel<ePixelWise>
coords.x += 80.0f;

SampleType(area_tex) in_area = bilinear(area_tex, coords[0], coords[1]);
return float2(in_area[0], in_area[1]);
return float2(in_area[0]/255, in_area[1]/255);
}

/**
Expand Down
36 changes: 32 additions & 4 deletions source/Smaa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ Smaa::Smaa(Node* node)
, _blend_program(SMAABlend)
, _neighborhood_program(SMAANeighborhood)
{
convert_texture(
searchTexBytes, _search_texture,
SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, 1
);
convert_texture(
areaTexBytes, _area_texture,
AREATEX_WIDTH, AREATEX_HEIGHT, 2
);
}

void Smaa::knobs(DD::Image::Knob_Closure &f)
Expand Down Expand Up @@ -249,8 +257,12 @@ Blink::Image Smaa::create_search_texture(Blink::ComputeDevice device) {
Blink::ImageInfo imageInfo(rect, pixelInfo);

Blink::Image image = Blink::Image(imageInfo, device);
Blink::BufferDesc bufferDesc(1, SEARCHTEX_PITCH, 1);
image.copyFromBuffer(searchTexBytes, bufferDesc);
Blink::BufferDesc bufferDesc(
sizeof(float),
sizeof(float) * SEARCHTEX_WIDTH,
sizeof(float)
);
image.copyFromBuffer(_search_texture.data(), bufferDesc);
return image;
}

Expand All @@ -260,9 +272,25 @@ Blink::Image Smaa::create_area_texture(Blink::ComputeDevice device) {
Blink::ImageInfo imageInfo(rect, pixelInfo);

Blink::Image image = Blink::Image(imageInfo, device);
Blink::BufferDesc bufferDesc(2, AREATEX_PITCH, 1);
image.copyFromBuffer(areaTexBytes, bufferDesc);
Blink::BufferDesc bufferDesc(
sizeof(float) * 2,
sizeof(float) * AREATEX_WIDTH,
sizeof(float)
);
image.copyFromBuffer(_area_texture.data(), bufferDesc);
return image;
}

void Smaa::convert_texture(
const unsigned char* source, std::vector<float>& destination,
int width, int height, int channelNumber
) {
const int size = width * height * channelNumber;
destination.reserve(size);

for (int index = 0; index < size; index++) {
destination.push_back((float) source[index]);
}
}

} // namespace Nuke
13 changes: 11 additions & 2 deletions source/Smaa.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ class Smaa : public DD::Image::PlanarIop
const Blink::Image& output
);

static Blink::Image create_search_texture(Blink::ComputeDevice device);
static Blink::Image create_area_texture(Blink::ComputeDevice device);
Blink::Image create_search_texture(Blink::ComputeDevice device);
Blink::Image create_area_texture(Blink::ComputeDevice device);

// Convert texture from unsigned char to float array.
static void convert_texture(
const unsigned char* source, std::vector<float>& destination,
int width, int height, int channelNumber
);

private:
Blink::ComputeDevice _gpu_device;
Expand All @@ -73,6 +79,9 @@ class Smaa : public DD::Image::PlanarIop
Blink::ProgramSource _edges_program;
Blink::ProgramSource _blend_program;
Blink::ProgramSource _neighborhood_program;

std::vector<float> _search_texture;
std::vector<float> _area_texture;
};

} // namespace Nuke
Expand Down

0 comments on commit f854a27

Please sign in to comment.