<p>I'm drawing a contour map representing gravity. </p>

<p>The algorithm is:</p>

<p>For each point on the screen (1 pixel per point) I calculate the gravitational pull for each object and combine (using Newtons law of universal gravitation) where M1 is a unit point mass.</p>

<p>Next I get the min and max values and create a palette of 10 colors scaled over this range.</p>

<p>I then generate a texture from this data.</p>

<p>For resolutions such as 1024 * 768 or greater this is expensive (takes > 1sec)</p>

<p>I'd like to be able to move the masses and see the contour map change in real time.</p>

<p>Any suggestions on how to optimise?</p>

CC BY-SA 3.0
2016-01-22T16:39:56.777Z
You may need to add relevant code but this should be pretty easy to paralellisize and use the GPU for calculation. How many objects are we talking about.
joojaa
CC BY-SA 3.0
2016-01-22T19:26:54.350Z
Welcome to Computer Graphics Stack Exchange. As joojaa already said, it's quite hard to help you to improve your code without seeing it. Please edit your question and add relevant parts of your code. Additionally, a screenshot of the result then also helps understanding what your code does.
Nero
CC BY-SA 3.0
2016-01-22T19:39:39.613Z
Off the cuff, I'd say render the objects in a floating-point texture using additive blending to accumulate their [gravitational potential](https://en.wikipedia.org/wiki/Gravitational_potential). Then use a second pass to convert the texture into a color map.
Nathan Reed
CC BY-SA 3.0
2016-01-23T07:57:50.153Z
@NathanReed Right my thoughts exactly...
joojaa
CC BY-SA 3.0
2016-01-31T20:33:44.037Z
I'd still have to calculate for each point gravity for each object. This seems to be the expensive part
iasksillyquestions
<optimisation>
Optimise drawing contour maps representing gravity
iasksillyquestions
# Optimise drawing contour maps representing gravity

(Asked by: username_0 on 2016-01-22)

I'm drawing a contour map representing gravity.

The algorithm is:

For each point on the screen (1 pixel per point) I calculate the gravitational pull for each object and combine (using Newtons law of universal gravitation) where M1 is a unit point mass.

Next I get the min and max values and create a palette of 10 colors scaled over this range.

I then generate a texture from this data.

For resolutions such as 1024 \* 768 or greater this is expensive (takes > 1sec)

I'd like to be able to move the masses and see the contour map change in real time.

Any suggestions on how to optimise?

**Tags:** optimisation

> **Comments:**
> **username_1**: You may need to add relevant code but this should be pretty easy to paralellisize and use the GPU for calculation. How many objects are we talking about.  
> **username_2**: Welcome to Computer Graphics Stack Exchange. As username_1 already said, it's quite hard to help you to improve your code without seeing it. Please edit your question and add relevant parts of your code. Additionally, a screenshot of the result then also helps understanding what your code does.  
> **username_3**: Off the cuff, I'd say render the objects in a floating-point texture using additive blending to accumulate their [gravitational potential](https://en.wikipedia.org/wiki/Gravitational_potential). Then use a second pass to convert the texture into a color map.  
> **username_1**: @username_3 Right my thoughts exactly...  
> **username_0**: I'd still have to calculate for each point gravity for each object. This seems to be the expensive part  

---

## 0 answers

