OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
spawn.cs
Go to the documentation of this file.
1 #version 310 es
2 
3 /* Copyright (c) 2014-2017, ARM Limited and Contributors
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 float noise1f(int x)
24 {
25  x = (x<<13) ^ x;
26  return ( 1.0 - float((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
27 }
28 
29 float snoise(float x)
30 {
31  int xi = int(floor(x));
32  float xf = x - float(xi);
33 
34  float h0 = noise1f(xi);
35  float h1 = noise1f(xi + 1);
36 
37  // Smoothly nterpolate between noise values
38  float t = smoothstep(0.0, 1.0, xf);
39  return h0 + (h1 - h0) * t;
40 }
41 
42 layout (local_size_x = 64) in;
43 
44 layout (std140, binding = 0) buffer SpawnBuffer {
45  vec4 SpawnInfo[];
46 };
47 
50 uniform float time;
51 
52 void main()
53 {
55 
56  vec3 p;
57 
58  // Random offset
59  float seed = float(index) * 100.0 * time;
60  p.x = snoise(seed);
61  p.z = snoise(seed + 13.0);
62  p.y = snoise(seed + 127.0);
63 
64  // Normalize to get sphere distribution
65  p = (0.06 + 0.04 * snoise(seed + 491.0)) * normalize(p);
66 
67  // Particle respawns at emitter
68  p += emitterPos;
69 
70  // New lifetime with slight variation
71  float newLifetime = (1.0 + 0.25 * snoise(seed)) * particleLifetime;
72 
73  SpawnInfo[index] = vec4(p, newLifetime);
74 }
Definition: matrix.h:51
precision highp int
Definition: hiz_cull.cs:38
uniform vec3 emitterPos
Definition: spawn.cs:46
float noise1f(int x)
Definition: spawn.cs:23
Definition: matrix.h:75
GLuint index
Definition: gl2ext.h:300
static vec3 normalize(const vec3 &v)
Definition: matrix.h:154
float snoise(float x)
Definition: spawn.cs:29
uniform vec3 seed
Definition: update.cs:33
void uniform(string name, const mat4 &v)
Definition: glutil.cpp:97
GLint GLint GLint GLint GLint x
Definition: gl2ext.h:574
layout(local_size_x=64) in
void main()
Definition: spawn.cs:52
static float smoothstep(float edge0, float edge1, float t)
Definition: matrix.h:154
GLenum GLuint buffer
Definition: gl2ext.h:628
precision highp float
Definition: hiz_cull.cs:37
uniform float particleLifetime
Definition: spawn.cs:49
uniform float time
Definition: spawn.cs:50