Skip to content
Snippets Groups Projects
Commit f79acf61 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Colours from config

parent 76e05930
No related branches found
No related tags found
1 merge request!120Implements #188 normal shading
Pipeline #14887 passed
......@@ -14,7 +14,7 @@ void normals(ftl::cuda::TextureObject<float4> &output,
void normal_visualise(ftl::cuda::TextureObject<float4> &norm,
ftl::cuda::TextureObject<uchar4> &output,
const float3 &light, const float3 &diffuse, const float3 &ambient,
const float3 &light, const uchar4 &diffuse, const uchar4 &ambient,
cudaStream_t stream);
void normal_filter(ftl::cuda::TextureObject<float4> &norm,
......
......@@ -47,6 +47,9 @@ class Splatter : public ftl::render::Renderer {
bool backcull_;
cv::Scalar background_;
bool splat_;
float3 light_dir_;
uchar4 light_diffuse_;
uchar4 light_ambient_;
};
}
......
......@@ -90,7 +90,7 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
__global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm,
ftl::cuda::TextureObject<uchar4> output,
float3 direction, float3 diffuse, float3 ambient) {
float3 direction, uchar4 diffuse, uchar4 ambient) {
const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
......@@ -113,7 +113,7 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm,
void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<float4> &norm,
ftl::cuda::TextureObject<uchar4> &output,
const float3 &light, const float3 &diffuse, const float3 &ambient,
const float3 &light, const uchar4 &diffuse, const uchar4 &ambient,
cudaStream_t stream) {
const dim3 gridSize((norm.width() + T_PER_BLOCK - 1)/T_PER_BLOCK, (norm.height() + T_PER_BLOCK - 1)/T_PER_BLOCK);
......
......@@ -25,7 +25,10 @@ static Eigen::Affine3d create_rotation_matrix(float ax, float ay, float az) {
return rz * rx * ry;
}
static cv::Scalar parseColour(const std::string &colour) {
/*
* Parse a CSS style colour string into a scalar.
*/
static cv::Scalar parseCVColour(const std::string &colour) {
std::string c = colour;
if (c[0] == '#') {
c.erase(0, 1);
......@@ -41,6 +44,25 @@ static cv::Scalar parseColour(const std::string &colour) {
return cv::Scalar(0,0,0,0);
}
/*
* Parse a CSS style colour string into a scalar.
*/
static uchar4 parseCUDAColour(const std::string &colour) {
std::string c = colour;
if (c[0] == '#') {
c.erase(0, 1);
unsigned long value = stoul(c.c_str(), nullptr, 16);
return make_uchar4(
(value >> 0) & 0xff,
(value >> 8) & 0xff,
(value >> 16) & 0xff,
(value >> 24) & 0xff
);
}
return make_uchar4(0,0,0,0);
}
Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::render::Renderer(config), scene_(fs) {
if (config["clipping"].is_object()) {
auto &c = config["clipping"];
......@@ -84,9 +106,19 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende
splat_ = value("splatting", true);
});
background_ = parseColour(value("background", std::string("#e0e0e0")));
background_ = parseCVColour(value("background", std::string("#4c4c4c")));
on("background", [this](const ftl::config::Event &e) {
background_ = parseColour(value("background", std::string("#e0e0e0")));
background_ = parseCVColour(value("background", std::string("#4c4c4c")));
});
light_diffuse_ = parseCUDAColour(value("diffuse", std::string("#e0e0e0")));
on("diffuse", [this](const ftl::config::Event &e) {
light_diffuse_ = parseCUDAColour(value("diffuse", std::string("#e0e0e0")));
});
light_ambient_ = parseCUDAColour(value("ambient", std::string("#0e0e0e")));
on("ambient", [this](const ftl::config::Event &e) {
light_ambient_ = parseCUDAColour(value("ambient", std::string("#0e0e0e")));
});
}
......@@ -324,9 +356,9 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
// Convert normal to single float value
temp_.create<GpuMat>(Channel::Colour, Format<uchar4>(camera.width, camera.height));
ftl::cuda::normal_visualise(out.getTexture<float4>(Channel::Normals), temp_.createTexture<uchar4>(Channel::Colour),
make_float3(0.0f, 0.0f, 1.0f),
make_float3(220,220,220),
make_float3(30,30,30), stream);
make_float3(-0.3f, 0.2f, 1.0f),
light_diffuse_,
light_ambient_, stream);
// Put in output as single float
cv::cuda::swap(temp_.get<GpuMat>(Channel::Colour), out.create<GpuMat>(Channel::Normals));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment