-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
114f513
commit 95df561
Showing
3 changed files
with
360 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<shader> | ||
{ | ||
"name" : "TransFeedback_P1", | ||
"useModalMat4" : false, | ||
"useUBOTransform" : true, | ||
"uniforms" : ["u_time","float"], | ||
"transFeedback" : [ "o_offset", "o_velocity", "o_age", "o_ageNorm" ] | ||
} | ||
</shader>,"o_ageNorm" | ||
|
||
<materials>[ { "name":"MatTransFeedback_P1" } ]</materials> | ||
|
||
<vertex> | ||
#version 300 es | ||
layout(location=0) in vec3 a_offset; | ||
layout(location=1) in vec3 a_velocity; | ||
layout(location=2) in float a_age; | ||
layout(location=3) in float a_ageNorm; | ||
layout(location=4) in float a_life; | ||
|
||
out vec3 o_offset; | ||
out vec3 o_velocity; | ||
out float o_age; | ||
out float o_ageNorm; | ||
|
||
highp float random(vec2 co){ | ||
highp float a = 12.9898; | ||
highp float b = 78.233; | ||
highp float c = 43758.5453; | ||
highp float dt = dot(co.xy ,vec2(a,b)); | ||
highp float sn = mod(dt,3.14); | ||
return fract(sin(sn) * c); | ||
} | ||
|
||
uniform UBOTransform{ | ||
mat4 matProjection; | ||
mat4 matCameraView; | ||
vec3 posCamera; | ||
}; | ||
|
||
uniform float u_time; | ||
|
||
void main(void){ | ||
float age = u_time - a_age; | ||
if(age > a_life){ | ||
//float r = random(vec2(gl_VertexID,u_time)); | ||
float r = random(vec2(1,u_time)); | ||
|
||
float ra = 6.283 * r; //PI*2*Rand | ||
float rx = r * 2.0 * cos(ra); | ||
float rz = r * 2.0 * sin(ra); | ||
|
||
// Generate a new particle | ||
o_offset = vec3(0.0, 0.0, 0.0); | ||
o_velocity = vec3(rx,(6.0 * r) + 2.0,rz); | ||
o_age = u_time; | ||
o_ageNorm = 0.0; | ||
}else{ | ||
o_velocity = a_velocity - vec3(0.0,0.05,0.0); //Apply Gravity to Velocity | ||
o_offset = a_offset + 0.01 * o_velocity; | ||
o_age = a_age; | ||
o_ageNorm = age / a_life; | ||
} | ||
} | ||
</vertex> | ||
<fragment> | ||
#version 300 es | ||
void main(void){ } | ||
</fragment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<shader> | ||
{ | ||
"name" : "TransFeedback_P2", | ||
"useModalMat4" : true, | ||
"useUBOTransform" : true | ||
} | ||
</shader>, | ||
"uniforms" : ["u_time","float"] | ||
|
||
<materials>[ { "name":"MatTransFeedback_P2","useBlending":false,"useSampleAlphaCoverage":true } ]</materials> | ||
|
||
<vertex> | ||
#version 300 es | ||
layout(location=0) in vec3 a_position; | ||
layout(location=1) in vec2 a_uv; | ||
layout(location=2) in vec3 a_offset; | ||
layout(location=3) in float a_ageNorm; | ||
|
||
uniform UBOTransform{ | ||
mat4 matProjection; | ||
mat4 matCameraView; | ||
vec3 posCamera; | ||
}; | ||
|
||
uniform mat4 uModalMatrix; | ||
|
||
out vec2 v_uv; | ||
out float v_age; | ||
|
||
void main(void){ | ||
v_uv = a_uv; | ||
v_age = a_ageNorm; | ||
|
||
vec3 pos = a_position;// * (1.0-v_age); | ||
|
||
gl_Position = matProjection * matCameraView * uModalMatrix * vec4(a_offset + pos, 1.0); | ||
} | ||
</vertex> | ||
|
||
<fragment> | ||
#version 300 es | ||
precision mediump float; | ||
|
||
in vec2 v_uv; | ||
in float v_age; | ||
|
||
out vec4 outColor; | ||
|
||
void main(void){ | ||
//outColor = vec4(0.0,0.0,0.0,1.0); | ||
|
||
/* */ | ||
vec2 delta = v_uv - vec2(0.5,0.5);//Distance from center | ||
float lenSqr = abs(dot(delta,delta)); //Length Squared (avoiding square roots) | ||
float a = smoothstep(0.25,0.23,lenSqr); //Center, so 0.5*0.5 = 0.25, the squared len from center, avoid roots. | ||
|
||
a -= v_age; | ||
//if(a < 0.1) discard; | ||
outColor = vec4(0.0,0.0,0.0,a); | ||
//outColor = vec4(a,0.0,0.0,a); | ||
} | ||
</fragment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters