Giter Club home page Giter Club logo

threejs-particle-shader's Introduction

threejs-particle-shader

View Demo

This project offers an configurable and easy way to integrate a shader based particle system into a three.js project.
Basically it's a rewrite of my particle shader experiments with the goal to reuse the basic shader code anywhere but keeping everything flexible.

WIP!

Inspired by the "One Million Particles" Chrome Experiment

Usage

  1. Load the script from the dist folder
<script src="dist/particles.js"></script>
  1. Create a particle system. This function expects your THREE.js WebGL renderer and the rendered scene. Optionally you can customize the particle system by providing an options object.
var particles = new Particles(renderer, scene, options);
  1. To animate the particles you have to update the the system in your render loop.
particles.update();

Options

  • textureSize Integer (Default: 256): Sets the size of the particle shader textures resulting in the number of rendered particles. A size of 256 results in 256*256=65536 particles.

  • pointSize Float (Default: 1.0): The size of a single particle (the gl_PointSize value for the display shader)

  • gravityFactor Float (Default: 1.0): Gravity Factor for the default particle movement. In case you change the default movement using the velocityFunctionString this variable can be used as a custom input value.

  • explodeRate Float (Default: 1.0): The intensity of the initial random velocity and position spread

  • targetPosition THREE.Vector3 (Default: (0,0,0)): The position of the gravity center for the default particle movement. You can also use this value for custom movements. Have a look at example 4.

  • targetPosition THREE.DataTexture (Default: null): With a targetTexture you can specify a targetPosition for each particle. Have a look at example 3 for how to create a targetTexture.

  • velocityFunctionString String (Default: null): The velocityFunctionString allows to change the default behavior of the velocity fragment shader. If a value is specified the original code of the shader will be replaced with the defined string. The value has to be valid GLSL code and should set the variable outVelocity as a vec3. Currently these values are available for calculations:

inVelocity
inPosition
targetPos
dist        //the distance from the particle to the targetPosition
direction   //the normalized direction pointing from the particle to the targetPosition

If you specify a targetTexture, the targetPos will not be the targetPosition from options.targetPosition but the position for this specific particle defined in the targetTexture.

  • positionFunctionString String (Default: null): The positionFunctionString works in the same way. The string value will be set in the position fragment shader. pos should be set as a vec3. For now the only input variable is: velocity

  • colorFunctionString String (Default: null): The colorFunctionString works in the same way. The string value will be set in the displays fragment shader. color should be set as a vec4. For now the only input variables are: dist, alpha

License

MIT

threejs-particle-shader's People

Contributors

pwambach avatar

Watchers

Andre Hayter avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.