Skip to content

Commit

Permalink
document that particles2d requires a blend mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmaclarty committed Jan 15, 2017
1 parent e48b2e6 commit a2084df
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
27 changes: 25 additions & 2 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<li><a href="#am.use_program">am.use_program(program)</a></li>
<li><a href="#am.bind">am.bind(bindings)</a></li>
<li><a href="#am.draw">am.draw(primitive [, elements] [, first [, count]])</a></li>
<li><a href="#am.blendmode">am.blend(mode)</a></li>
<li><a href="#am.blend">am.blend(mode)</a></li>
<li><a href="#am.color_maskred-green-blue-alpha">am.color_mask(red, green, blue, alpha)</a></li>
<li><a href="#am.cull_faceface">am.cull_face(face)</a></li>
<li><a href="#am.depth_test">am.depth_test(test [, mask])</a></li>
Expand Down Expand Up @@ -2094,6 +2094,29 @@ <h3 id="am.particles2d" class="func-def">am.particles2d(settings)</h3>
</ul>
<p>In the table the <code>_var</code> fields are an amount that is added to and subtracted from the corresponding field (the one without the <code>_var</code> suffix) to get the range of values from which one is randomly chosen. For example if <code>source_pos</code> is <code>vec2(1, 0)</code> and <code>source_pos_var</code> is <code>vec2(3, 2)</code>, then source positions will be chosen in the range <code>vec2(-2, -2)</code> to <code>vec2(4, 2)</code>.</p>
<p>All of the sprite settings are exposed as updatable fields on the particles node.</p>
<p>Note that no blending is applied to the particles, so if you want alpha on your particles, then you need to add a <a href="#am.blend"><code>am.blend</code></a> node. For example:</p>
<div class="sourceCode"><pre class="sourceCode lua"><code class="sourceCode lua"><span class="kw">local</span> node <span class="ot">=</span> am<span class="ot">.</span>blend<span class="ot">(</span><span class="st">&quot;add_alpha&quot;</span><span class="ot">)</span>
<span class="ot">^</span> am<span class="ot">.</span>particles2d<span class="ot">{</span>
source_pos <span class="ot">=</span> win:mouse_position<span class="ot">(),</span>
source_pos_var <span class="ot">=</span> vec2<span class="ot">(</span><span class="dv">20</span><span class="ot">),</span>
max_particles <span class="ot">=</span> <span class="dv">1000</span><span class="ot">,</span>
emission_rate <span class="ot">=</span> <span class="dv">500</span><span class="ot">,</span>
start_particles <span class="ot">=</span> <span class="dv">0</span><span class="ot">,</span>
life <span class="ot">=</span> <span class="dv">0.4</span><span class="ot">,</span>
life_var <span class="ot">=</span> <span class="dv">0.1</span><span class="ot">,</span>
angle <span class="ot">=</span> <span class="fu">math.rad</span><span class="ot">(</span><span class="dv">90</span><span class="ot">),</span>
angle_var <span class="ot">=</span> <span class="fu">math.rad</span><span class="ot">(</span><span class="dv">180</span><span class="ot">),</span>
speed <span class="ot">=</span> <span class="dv">200</span><span class="ot">,</span>
start_color <span class="ot">=</span> vec4<span class="ot">(</span><span class="dv">1</span><span class="ot">,</span> <span class="dv">0.3</span><span class="ot">,</span> <span class="dv">0.01</span><span class="ot">,</span> <span class="dv">0.5</span><span class="ot">),</span>
start_color_var <span class="ot">=</span> vec4<span class="ot">(</span><span class="dv">0.1</span><span class="ot">,</span> <span class="dv">0.05</span><span class="ot">,</span> <span class="dv">0.0</span><span class="ot">,</span> <span class="dv">0.1</span><span class="ot">),</span>
end_color <span class="ot">=</span> vec4<span class="ot">(</span><span class="dv">0.5</span><span class="ot">,</span> <span class="dv">0.8</span><span class="ot">,</span> <span class="dv">1</span><span class="ot">,</span> <span class="dv">1</span><span class="ot">),</span>
end_color_var <span class="ot">=</span> vec4<span class="ot">(</span><span class="dv">0.1</span><span class="ot">),</span>
start_size <span class="ot">=</span> <span class="dv">30</span><span class="ot">,</span>
start_size_var <span class="ot">=</span> <span class="dv">10</span><span class="ot">,</span>
end_size <span class="ot">=</span> <span class="dv">2</span><span class="ot">,</span>
end_size_var <span class="ot">=</span> <span class="dv">2</span><span class="ot">,</span>
gravity <span class="ot">=</span> vec2<span class="ot">(</span><span class="dv">0</span><span class="ot">,</span> <span class="dv">2000</span><span class="ot">),</span>
<span class="ot">}</span></code></pre></div>
<p>Methods:</p>
<ul>
<li><code>reset()</code>: resets the particles as if they had just been created with their current settings.</li>
Expand Down Expand Up @@ -2315,7 +2338,7 @@ <h3 id="am.draw" class="func-def">am.draw(primitive [, elements] [, first [, cou
<img src="images/rgb_triangle.png" />

</div>
<h3 id="am.blendmode" class="func-def">am.blend(mode)</h3>
<h3 id="am.blend" class="func-def">am.blend(mode)</h3>
<p>Set the blending mode.</p>
<p>The possible values for <code>mode</code> are:</p>
<ul>
Expand Down
30 changes: 29 additions & 1 deletion doc/scene_nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,34 @@ range `vec2(-2, -2)` to `vec2(4, 2)`.
All of the sprite settings are exposed as updatable fields on
the particles node.

Note that no blending is applied to the particles, so if you want alpha on your
particles, then you need to add a [`am.blend`](#am.blend) node. For example:

~~~ {.lua}
local node = am.blend("add_alpha")
^ am.particles2d{
source_pos = win:mouse_position(),
source_pos_var = vec2(20),
max_particles = 1000,
emission_rate = 500,
start_particles = 0,
life = 0.4,
life_var = 0.1,
angle = math.rad(90),
angle_var = math.rad(180),
speed = 200,
start_color = vec4(1, 0.3, 0.01, 0.5),
start_color_var = vec4(0.1, 0.05, 0.0, 0.1),
end_color = vec4(0.5, 0.8, 1, 1),
end_color_var = vec4(0.1),
start_size = 30,
start_size_var = 10,
end_size = 2,
end_size_var = 2,
gravity = vec2(0, 2000),
}
~~~

Methods:

- `reset()`: resets the particles as if they had just been created with their
Expand Down Expand Up @@ -789,7 +817,7 @@ The resulting image looks like this:

![](images/rgb_triangle.png)

### am.blend(mode) {.func-def}
### am.blend(mode) {#am.blend .func-def}

Set the blending mode.

Expand Down

0 comments on commit a2084df

Please sign in to comment.