npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shaderfrog-runtime

v0.2.0

Published

ShaderFrog runtime library

Downloads

16

Readme

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