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

Allow light source location

parent 9bd5ba87
No related branches found
No related tags found
1 merge request!120Implements #188 normal shading
This commit is part of merge request !120. Comments created here will be created in the context of that merge request.
...@@ -14,7 +14,7 @@ void normals(ftl::cuda::TextureObject<float4> &output, ...@@ -14,7 +14,7 @@ void normals(ftl::cuda::TextureObject<float4> &output,
void normal_visualise(ftl::cuda::TextureObject<float4> &norm, void normal_visualise(ftl::cuda::TextureObject<float4> &norm,
ftl::cuda::TextureObject<float> &output, ftl::cuda::TextureObject<float> &output,
const ftl::rgbd::Camera &camera, const float4x4 &pose, const float3 &light,
cudaStream_t stream); cudaStream_t stream);
void normal_filter(ftl::cuda::TextureObject<float4> &norm, void normal_filter(ftl::cuda::TextureObject<float4> &norm,
......
...@@ -90,14 +90,14 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output, ...@@ -90,14 +90,14 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
__global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm, __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm,
ftl::cuda::TextureObject<float> output, ftl::cuda::TextureObject<float> output,
ftl::rgbd::Camera camera, float4x4 pose) { float3 light) {
const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y;
if(x >= norm.width() || y >= norm.height()) return; if(x >= norm.width() || y >= norm.height()) return;
output(x,y) = 0.0f; output(x,y) = 0.0f;
float3 ray = pose.getFloat3x3() * camera.screenToCam(x,y,1.0f); float3 ray = light; //pose.getFloat3x3() * camera.screenToCam(x,y,1.0f);
ray = ray / length(ray); ray = ray / length(ray);
float3 n = make_float3(norm.tex2D((int)x,(int)y)); float3 n = make_float3(norm.tex2D((int)x,(int)y));
float l = length(n); float l = length(n);
...@@ -114,13 +114,13 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm, ...@@ -114,13 +114,13 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<float4> norm,
void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<float4> &norm, void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<float4> &norm,
ftl::cuda::TextureObject<float> &output, ftl::cuda::TextureObject<float> &output,
const ftl::rgbd::Camera &camera, const float4x4 &pose, const float3 &light,
cudaStream_t stream) { 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 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); const dim3 blockSize(T_PER_BLOCK, T_PER_BLOCK);
vis_normals_kernel<<<gridSize, blockSize, 0, stream>>>(norm, output, camera, pose); vis_normals_kernel<<<gridSize, blockSize, 0, stream>>>(norm, output, light);
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
#ifdef _DEBUG #ifdef _DEBUG
......
...@@ -323,7 +323,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -323,7 +323,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
// Convert normal to single float value // Convert normal to single float value
temp_.create<GpuMat>(Channel::Contribution, Format<float>(camera.width, camera.height)); temp_.create<GpuMat>(Channel::Contribution, Format<float>(camera.width, camera.height));
ftl::cuda::normal_visualise(out.getTexture<float4>(Channel::Normals), temp_.createTexture<float>(Channel::Contribution), camera, params.m_viewMatrixInverse, stream); ftl::cuda::normal_visualise(out.getTexture<float4>(Channel::Normals), temp_.createTexture<float>(Channel::Contribution), make_float3(0.0f, 0.0f, 1.0f), stream);
// Put in output as single float // Put in output as single float
cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), out.create<GpuMat>(Channel::Normals)); cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), 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