1111Ray ray_to_camera (
1212 const __global int * projectorType ,
1313 const __global float * cameraSettings ,
14- const __global int * width ,
15- const __global int * height ,
14+ const __global int * canvasConfig ,
1615 int gid ,
1716 Random random
1817) {
@@ -23,10 +22,17 @@ Ray ray_to_camera(
2322 float3 m2s = vload3 (2 , cameraSettings );
2423 float3 m3s = vload3 (3 , cameraSettings );
2524
26- float halfWidth = (* width ) / (2.0 * (* height ));
27- float invHeight = 1.0 / (* height );
28- float x = - halfWidth + ((gid % (* width )) + Random_nextFloat (random )) * invHeight ;
29- float y = -0.5 + ((gid / (* width )) + Random_nextFloat (random )) * invHeight ;
25+ int width = canvasConfig [0 ];
26+ int height = canvasConfig [1 ];
27+ int fullWidth = canvasConfig [2 ];
28+ int fullHeight = canvasConfig [3 ];
29+ int cropX = canvasConfig [4 ];
30+ int cropY = canvasConfig [5 ];
31+
32+ float halfWidth = fullWidth / (2.0 * fullHeight );
33+ float invHeight = 1.0 / fullHeight ;
34+ float x = - halfWidth + ((gid % width ) + Random_nextFloat (random ) + cropX ) * invHeight ;
35+ float y = -0.5 + ((gid / width ) + Random_nextFloat (random ) + cropY ) * invHeight ;
3036
3137 switch (* projectorType ) {
3238 case 0 :
@@ -76,8 +82,7 @@ __kernel void render(
7682
7783 __global const int * randomSeed ,
7884 __global const int * bufferSpp ,
79- __global const int * width ,
80- __global const int * height ,
85+ __global const int * canvasConfig ,
8186 __global const int * rayDepth ,
8287 __global float * res
8388
@@ -97,7 +102,7 @@ __kernel void render(
97102 unsigned int randomState = * randomSeed + gid ;
98103 Random random = & randomState ;
99104 Random_nextState (random );
100- Ray ray = ray_to_camera (projectorType , cameraSettings , width , height , gid , random );
105+ Ray ray = ray_to_camera (projectorType , cameraSettings , canvasConfig , gid , random );
101106
102107 ray .material = 0 ;
103108 ray .flags = 0 ;
@@ -158,17 +163,17 @@ __kernel void preview(
158163 __global const float * skyIntensity ,
159164 __global const int * sunData ,
160165
161- __global const int * width ,
162- __global const int * height ,
166+ __global const int * canvasConfig ,
163167 __global int * res
164168) {
165169 int gid = get_global_id (0 );
166- int px = gid % * width ;
167- int py = gid / * width ;
170+
171+ int px = gid % canvasConfig [0 ] + canvasConfig [4 ];
172+ int py = gid / canvasConfig [0 ] + canvasConfig [5 ];
168173
169174 // Crosshairs?
170- if ((px == * width / 2 && (py >= * height / 2 - 5 && py <= * height / 2 + 5 )) ||
171- (py == * height / 2 && (px >= * width / 2 - 5 && px <= * width / 2 + 5 ))) {
175+ if ((px == canvasConfig [ 2 ] / 2 && (py >= canvasConfig [ 3 ] / 2 - 5 && py <= canvasConfig [ 3 ] / 2 + 5 )) ||
176+ (py == canvasConfig [ 3 ] / 2 && (px >= canvasConfig [ 2 ] / 2 - 5 && px <= canvasConfig [ 2 ] / 2 + 5 ))) {
172177 res [gid ] = 0xFFFFFFFF ;
173178 return ;
174179 }
@@ -187,7 +192,7 @@ __kernel void preview(
187192 Random random = & randomState ;
188193 Random_nextState (random );
189194
190- Ray ray = ray_to_camera (projectorType , cameraSettings , width , height , gid , random );
195+ Ray ray = ray_to_camera (projectorType , cameraSettings , canvasConfig , gid , random );
191196
192197 IntersectionRecord record = IntersectionRecord_new ();
193198 MaterialSample sample ;
0 commit comments