Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support trail effects (#1251) #1431

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/core/src/shader/ShaderPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import blinnPhongFs from "../shaderlib/extra/blinn-phong.fs.glsl";
import blinnPhongVs from "../shaderlib/extra/blinn-phong.vs.glsl";
import particleFs from "../shaderlib/extra/particle.fs.glsl";
import particleVs from "../shaderlib/extra/particle.vs.glsl";
import trailFs from "../shaderlib/extra/trail.fs.glsl";
import trailVs from "../shaderlib/extra/trail.vs.glsl";
import pbrSpecularFs from "../shaderlib/extra/pbr-specular.fs.glsl";
import pbrFs from "../shaderlib/extra/pbr.fs.glsl";
import pbrVs from "../shaderlib/extra/pbr.vs.glsl";
Expand Down Expand Up @@ -43,6 +45,7 @@ export class ShaderPool {

Shader.create("skybox", [new ShaderPass(skyboxVs, skyboxFs, forwardPassTags)]);
Shader.create("particle-shader", [new ShaderPass(particleVs, particleFs, forwardPassTags)]);
Shader.create("trail-shader", [new ShaderPass(trailVs, trailFs, forwardPassTags)]);
Shader.create("SpriteMask", [new ShaderPass(spriteMaskVs, spriteMaskFs, forwardPassTags)]);
Shader.create("Sprite", [new ShaderPass(spriteVs, spriteFs, forwardPassTags)]);
Shader.create("background-texture", [new ShaderPass(backgroundTextureVs, backgroundTextureFs, forwardPassTags)]);
Expand Down
12 changes: 12 additions & 0 deletions packages/core/src/shaderlib/extra/trail.fs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
varying vec4 vColor;
varying vec2 v_uv;
uniform sampler2D u_texture;
void main(void)
{
#ifdef trailTexture
vec4 textureColor = texture2D(u_texture, v_uv);
gl_FragColor = vColor * textureColor;
#else
gl_FragColor = vColor;
#endif
}
36 changes: 36 additions & 0 deletions packages/core/src/shaderlib/extra/trail.vs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
uniform mat4 u_projMat;
uniform mat4 u_viewMat;
uniform mat4 u_modelMat;

uniform float u_textureTileS;
uniform float u_textureTileT;

uniform vec4 u_headColor;
uniform vec4 u_tailColor;

uniform float u_currentTime;
uniform float u_trailLifeTime;

attribute vec3 a_position;
attribute vec3 a_nodeCenter;

attribute float a_nodeIndex;
attribute float a_vertexNodeIndex;
attribute float a_trailBirthTime;

varying vec2 v_uv;
varying vec4 vColor;

void main(){
float s = a_nodeIndex / 80.0 * u_textureTileS;
float t = a_vertexNodeIndex * u_textureTileT;
v_uv = vec2( s, t );

float normalizeTime = (u_currentTime - a_trailBirthTime) / u_trailLifeTime;
vec4 realPosition = vec4( ( 1.0 - normalizeTime ) * a_position.xyz + normalizeTime * a_position.xyz, 1.0 );
gl_Position = u_projMat * u_viewMat * realPosition;

if (normalizeTime < 1.0){
vColor = ( 1.0 - normalizeTime ) * u_headColor + normalizeTime * u_tailColor;
}
}
20 changes: 0 additions & 20 deletions packages/core/src/trail/TrailMaterial.ts

This file was deleted.

Loading