Coder Social home page Coder Social logo

shaderfrog-runtime's Introduction

ShaderFrog logo

Please file ShaderFrog.com bugs here!

ShaderFrog is currently closed source. Please file bugs here, using the issue tracker.

ShaderFrog Runtime Library

This is a utility library to load and update ShaderFrog.com shaders into your THREE.js scene or application.

Demo

Online Demo

Demo source found in the example/ folder.

Usage

npm

npm install --save shaderfrog-runtime

var ShaderFrogRuntime = require( 'shaderfrog-runtime' ):

Vanilla JavaScript

Download the built Javascript file and include it in your project after THREE.js:

<script src="shaderfrog-runtime.min.js"></script>

Instantiation

Instantiate a new runtime:

var runtime = new ShaderFrogRuntime();

Instantiate a new clock:

var clock = new THREE.Clock();

Load your desired shader, and assign it to a material:

runtime.load( 'Your_Shader.json', function( shaderData ) {

    // Get the Three.js material you can assign to your objects
    var material = runtime.get( shaderData.name );

    // Assign it to your objects
    mesh.material = material;
});

In your initialization code, register the main camera, which is the one that you call renderer.render( scene, camera ) with:

runtime.registerCamera( camera );

This tells the ShaderFrog runtime how to update the cameraPosition uniform, which some shaders use to calculate things based on the camera, like reflection.

In your animation loop, update the running shaders that the ShaderFrog runtime knows about:

runtime.updateShaders( clock.getElapsedTime() );

A full example can be found in the example/ folder.

API

Warning: This API is volatile and subject to change in future versions.

runtime.registerCamera( THREE.Camera camera )

Tells the runtime to use this camera's position for the default cameraPosition uniform. This uniform is normally passed by default in THREE.js to shader materials, but ShaderFrog shaders use the RawSahderMaterial class.

runtime.updateShaders( Float time )

Update uniform values for shaders, specifically float time, vec3 cameraPosition, and mat4 viewMatrix. The only uniform the runtime cannot define is time which should be provided by the elapsed time in milliseconds. THREE.Clock.getElapsedTime() provies this value.

runtime.load( [ String source | Array sources ], Function callback )

Call this function with either:

runtime.load( 'material.json', function( material ) ) {
    var shader = runtime.get( material.name ); ...
}

...for one material, or...

runtime.load( [  'material1.json', 'material2.json' ], function( materials ) ) {
    var shader = runtime.get( materials[ 0 ].name ); ...
}

Load the specified URLs and parse them into materials. If you pass in an array of URLs, the callback receives an array of materials in the same order you specified.

runtime.add( String name, Object shader )

If your shader data is already loaded in JSON form by some other means, you can add it to the runtime's repository of known shaders with this method.

runtime.get( String name )

The ShaderFrog runtime stores materials by name. This function returns a new instance of the material you have loaded. You can assign this new material to your object, update uniforms on it, etc.

Proposed Shader Format

ShaderFrog requires a shader file format to transfer all neccessary shader data from the editor to the end user. A proposed JSON format is discussed in THREE_SHADER_FORMAT.md.

Development

To install the dependencies:

git clone https://github.com/AndrewRayCode/ShaderFrog-Runtime
npm install

To build the distributable Javascript file:

npm run build

shaderfrog-runtime's People

Contributors

andrewraycode avatar

Watchers

 avatar  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.