From 26e4e3c800edc83c00e1aeaeea12cfaf0dda55d3 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 2 Oct 2019 09:14:47 +0300
Subject: [PATCH] Correct comp problems

---
 components/renderers/cpp/include/ftl/cuda/normals.hpp |  2 +-
 components/renderers/cpp/src/normals.cu               | 11 ++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/components/renderers/cpp/include/ftl/cuda/normals.hpp b/components/renderers/cpp/include/ftl/cuda/normals.hpp
index 85620ff28..4cbd760a1 100644
--- a/components/renderers/cpp/include/ftl/cuda/normals.hpp
+++ b/components/renderers/cpp/include/ftl/cuda/normals.hpp
@@ -6,7 +6,7 @@
 namespace ftl {
 namespace cuda {
 
-void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
+void normals(ftl::cuda::TextureObject<float4> &output,
         ftl::cuda::TextureObject<float4> &input, cudaStream_t stream);
 
 }
diff --git a/components/renderers/cpp/src/normals.cu b/components/renderers/cpp/src/normals.cu
index 813f1aab5..7ed9bb681 100644
--- a/components/renderers/cpp/src/normals.cu
+++ b/components/renderers/cpp/src/normals.cu
@@ -1,6 +1,7 @@
 #include <ftl/cuda/normals.hpp>
 
 #define T_PER_BLOCK 16
+#define MINF __int_as_float(0xff800000)
 
 __global__ void computeNormals_kernel(ftl::cuda::TextureObject<float4> output,
         ftl::cuda::TextureObject<float4> input) {
@@ -12,11 +13,11 @@ __global__ void computeNormals_kernel(ftl::cuda::TextureObject<float4> output,
 	output(x,y) = make_float4(MINF, MINF, MINF, MINF);
 
 	if(x > 0 && x < input.width()-1 && y > 0 && y < input.height()-1) {
-		const float3 CC = make_float3(input.tex2D(x+0, y+0)); //[(y+0)*width+(x+0)];
-		const float3 PC = make_float3(input.tex2D(x+0, y+1)); //[(y+1)*width+(x+0)];
-		const float3 CP = make_float3(input.tex2D(x+1, y+0)); //[(y+0)*width+(x+1)];
-		const float3 MC = make_float3(input.tex2D(x+0, y-1)); //[(y-1)*width+(x+0)];
-		const float3 CM = make_float3(input.tex2D(x-1, y+0)); //[(y+0)*width+(x-1)];
+		const float3 CC = make_float3(input.tex2D((int)x+0, (int)y+0)); //[(y+0)*width+(x+0)];
+		const float3 PC = make_float3(input.tex2D((int)x+0, (int)y+1)); //[(y+1)*width+(x+0)];
+		const float3 CP = make_float3(input.tex2D((int)x+1, (int)y+0)); //[(y+0)*width+(x+1)];
+		const float3 MC = make_float3(input.tex2D((int)x+0, (int)y-1)); //[(y-1)*width+(x+0)];
+		const float3 CM = make_float3(input.tex2D((int)x-1, (int)y+0)); //[(y+0)*width+(x-1)];
 
 		if(CC.x != MINF && PC.x != MINF && CP.x != MINF && MC.x != MINF && CM.x != MINF) {
 			const float3 n = cross(PC-MC, CP-CM);
-- 
GitLab