<p>I wrote a program that displays points expressed in 3D in a 2D canvas, using perspective projection. The aim is to display a cube. Each face of the cube is drawn by linearly interpolating the points that define it. My cube can be translated, scaled and rotated thanks to transformation matrices.</p>

<p>For the moment, my program is not paralelized at all and uses CPU to make the various computations (e.g. : projection of 3D points into the 2D canvas using perspective projection, matrices computations, product of a point by a matrix, drawing cube's faces with linear interpolation).</p>

<p>There is a speed problem. I described it below :</p>

<ol>
<li><p>Linear interpolation as I wrote it, which never calculates duplicates, costs a lot of accesses to RAM. Applied to each face, it requires also a lot of computations.</p></li>
<li><p>My cube's faces should be drawn thanks to a linear interpolation with a very very small step (e.g. : <code>0.001</code>) to be beautiful. However, it's simply a utopia. It would require too many computations and accesses to RAM. My program would freeze.</p></li>
<li><p>A given transformation matrice is multiplied by point N°<code>1</code>, then by N°<code>2</code>, then by N°<code>k</code>, then by N°<code>8</code>. Obviously, the matrices are not multiplied by the interpolated points ! (it implies a gain in computation speed).</p></li>
</ol>

<h1>Questions</h1>

<p>Without using any API :</p>

<ol>
<li><p>Are GPU util to paralelize linear interpolations ? If I remember well my courses, yes. So : <strong><em>how could I send my points and my linear interpolation function to GPU ?</em></strong> Note that I would be disapointed if I must use linear interpolation program of the GPU (if it exists) instead of mine.</p></li>
<li><p>How could I draw beautiful cube's faces without using a linear interpolation's step of <code>0.001</code> ?</p></li>
<li><p>Less important : is it possible to increase computation speed in making the product of a sequence of points with a matrice ?</p></li>
</ol>

CC BY-SA 4.0
2018-06-03T12:41:37.873Z
What you are doing is what a GPU as a graphics processor is designed to do. Is it a requirement to do it in Scala or can you use a graphics API such as openGL or DirectX?
Nadir
CC BY-SA 4.0
2018-06-03T19:19:28.770Z
Yes, I wanted to know about the geometric mechanisms involved in perspective projection and in filling a face with interpolation. The best solution would consist in executing parts of my code (e.g. : interpolation between the 4 points of my face) by the GPU and not the CPU. Perhaps GPGPU could be useful for me ?
JarsOfJam-Scheduler
<gpu><performance><perspective><interpolation><gpgpu>
Using GPU instead of CPU in Scala
JarsOfJam-Scheduler
# Using GPU instead of CPU in Scala

(Asked by: username_0 on 2018-06-02)

I wrote a program that displays points expressed in 3D in a 2D canvas, using perspective projection. The aim is to display a cube. Each face of the cube is drawn by linearly interpolating the points that define it. My cube can be translated, scaled and rotated thanks to transformation matrices.

For the moment, my program is not paralelized at all and uses CPU to make the various computations (e.g. : projection of 3D points into the 2D canvas using perspective projection, matrices computations, product of a point by a matrix, drawing cube's faces with linear interpolation).

There is a speed problem. I described it below :

1. Linear interpolation as I wrote it, which never calculates duplicates, costs a lot of accesses to RAM. Applied to each face, it requires also a lot of computations.
2. My cube's faces should be drawn thanks to a linear interpolation with a very very small step (e.g. : `0.001`) to be beautiful. However, it's simply a utopia. It would require too many computations and accesses to RAM. My program would freeze.
3. A given transformation matrice is multiplied by point N°`1`, then by N°`2`, then by N°`k`, then by N°`8`. Obviously, the matrices are not multiplied by the interpolated points ! (it implies a gain in computation speed).

# Questions

Without using any API :

1. Are GPU util to paralelize linear interpolations ? If I remember well my courses, yes. So : ***how could I send my points and my linear interpolation function to GPU ?*** Note that I would be disapointed if I must use linear interpolation program of the GPU (if it exists) instead of mine.
2. How could I draw beautiful cube's faces without using a linear interpolation's step of `0.001` ?
3. Less important : is it possible to increase computation speed in making the product of a sequence of points with a matrice ?

**Tags:** gpu, performance, perspective, interpolation, gpgpu

> **Comments:**
> **username_1**: What you are doing is what a GPU as a graphics processor is designed to do. Is it a requirement to do it in Scala or can you use a graphics API such as openGL or DirectX?  
> **username_0**: Yes, I wanted to know about the geometric mechanisms involved in perspective projection and in filling a face with interpolation. The best solution would consist in executing parts of my code (e.g. : interpolation between the 4 points of my face) by the GPU and not the CPU. Perhaps GPGPU could be useful for me ?  

---

## 0 answers

