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

Add ambient diffuse colours

parent 4529b347
No related branches found
No related tags found
1 merge request!120Implements #188 normal shading
Pipeline #14883 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 &light, const float3 &diffuse, const float3 &ambient,
cudaStream_t stream);
void normal_filter(ftl::cuda::TextureObject<float4> &norm,
......
......@@ -90,14 +90,14 @@ 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 light) {
float3 direction, float3 diffuse, float3 ambient) {
const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
if(x >= norm.width() || y >= norm.height()) return;
output(x,y) = make_uchar4(0,0,0,0);
float3 ray = light; //pose.getFloat3x3() * camera.screenToCam(x,y,1.0f);
float3 ray = direction;
ray = ray / length(ray);
float3 n = make_float3(norm.tex2D((int)x,(int)y));
float l = length(n);
......@@ -105,22 +105,21 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm,
n /= l;
const float d = max(dot(ray, n), 0.0f);
output(x,y) = make_uchar4(200*d,200*d,200*d,255);
//if (d > 0.2f) {
// output(x,y) = d * 7.0f;
//}
output(x,y) = make_uchar4(
min(255.0f, diffuse.x*d + ambient.x),
min(255.0f, diffuse.y*d + ambient.y),
min(255.0f, diffuse.z*d + ambient.z), 255);
}
void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<float4> &norm,
ftl::cuda::TextureObject<uchar4> &output,
const float3 &light,
const float3 &light, const float3 &diffuse, const float3 &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);
const dim3 blockSize(T_PER_BLOCK, T_PER_BLOCK);
vis_normals_kernel<<<gridSize, blockSize, 0, stream>>>(norm, output, light);
vis_normals_kernel<<<gridSize, blockSize, 0, stream>>>(norm, output, light, diffuse, ambient);
cudaSafeCall( cudaGetLastError() );
#ifdef _DEBUG
......
......@@ -323,7 +323,10 @@ 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), stream);
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);
// 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