Git Product home page Git Product logo

glbrush.js's Introduction

glbrush.js

Rendering library for web-based painting applications. Includes WebGL and software (2D canvas) backends.

See a simple example in action: http://oletus.github.io/glbrush.js/example.html

Supported features so far include:

  • Hard-edged, soft and texturized circular airbrush with opacity, flow and dynamic size control.
  • Linear gradients.
  • Unlimited undo, and all operations except layer merges and layer stack reordering can be undone out of sequence.
  • Wide support for blending modes: normal, erase, multiply, screen, overlay, hard light, pin light, vivid light, difference, exclusion...
  • Alpha blended layers.
  • Replay animation.
  • Rasterization is done internally with at least 16 bits of precision, resulting in much better quality soft brush rendering than what is achievable with 2D canvas.
  • Serialization of pictures in text-based vector format and resizing them when parsing the serialization.

Code standards:

Contributions welcome!

Getting started with development scripts (not necessary to simply use the package):

  • Install Python 2.7
  • Install node.js (tested with version 10.15.3 LTS)
  • run "npm install"
  • run "python tools\compile_glbrush.py" to compile the library using Closure compiler

glbrush.js's People

Contributors

oletus avatar

Stargazers

Simon Breslav avatar Leandro Daher avatar Butcat avatar  avatar /人 ⌒ ‿‿ ⌒ 人\ avatar Nadeera Sampath avatar Vis avatar haorui avatar  avatar Joe Geldart avatar Muini avatar Wojciech Miłkowski avatar  avatar Jan Hug avatar  avatar Ziben avatar  avatar Jason avatar Jan Roudaut avatar Chaz Straney avatar Alexandre Nicastro avatar Alain Galvan avatar volos avatar Grig avatar  avatar Double Han avatar  avatar liquid avatar bitwolf avatar Erick Bazán avatar Dylan Cutler avatar Song Seunggeun avatar 爱可可-爱生活 avatar Bojan Čoka avatar Julien Viala avatar CJ Gammon avatar  avatar Andy Dayton avatar ofufu avatar JongChan Choi (Rieul) avatar  avatar ᦔꪖ꠸ꪀ ᥇ꪶꪮᦔꪮ᥅ꪀ ᛕ꠸ꪑ avatar  avatar Dmitry Iv. avatar Ketan Gupta avatar Bradley Bossard avatar  avatar Andreas Gysin avatar  avatar ningxu avatar  avatar Dean Halford avatar razh avatar Tuan Kuranes avatar  avatar Jerry Ylilammi avatar  avatar

Watchers

 avatar ningxu avatar  avatar James Cloos avatar Juha Törmänen avatar Vis avatar bitwolf avatar

glbrush.js's Issues

Implement remaining blending modes

Target is to implement all blending modes that PhotoShop and GIMP support today. A code generator should be written for the software fallback to avoid code duplication.

Improve out-of-sequence undo for move events

Out-of-sequence undo for move events doesn't produce very good results yet.

One reasonable goal for out-of-sequence undo would be that the following sequence would not change the picture:

  1. Move event A
  2. Move event B
  3. Undo move event A
  4. Undo move event B

but it's a bit unclear what's the best way to do this. Merges happening between move & undo can also mess things up, that should be thought about.

Clearing/resetting Picture?

Is there a preferred way to clear the current Picture instead of destroying it and recreating with a new Picture and then appending it to the drawArea?

Thank you

Improve buffer memory management

-Implement freeing memory entirely for buffers whose creation has been undone (for applications that don't use redo)

-Implement a method for choosing the least useful undo state from a buffer. This can be used to stay within budget as new undo states are added, as well as reducing the budget. For this, approximating the regeneration cost of an undo state could be done by calculating undoState.index - previousUndoState.index. Combining this somehow with the likelihood of it being used should provide a decent metric for which undo states to get rid of (or move to CPU memory as an intermediate step).

-Implement global memory budgets and a policy to select the least-relevant buffer to reduce their budget. Could be based on a least-recently-used policy.

Add support for testing Closure compiled code

Adding a script for compiling the unit tests along with the code would be the most obvious idea. The unit tests integrate with the code so tightly, that only compiling the code and exporting everything that's necessary for the tests is not really feasible. The big unknown here is how to handle the interface with Jasmine.

Implement arbitrarily textured brush

The circle in brush strokes should be possible to replace with an arbitrary bitmap. As an option, the picture could be rotated for each blit according to the brush direction.

Improve compositing code

WebGL multitexturing-based layer compositor is subject to texture unit limitations. Make it scale beyond the amount of texture units provided. WebGL/Canvas 2D compositing could also be abstracted away from the Picture class.

Setting BrushTipMover (Spacing and Scatter)

First I must say this is by far the best open source JS brush engine I've seen. Thanks for sharing it.

I'm trying to set the BrushTipMover spacing and scatteroffset attributes. So far I created a brushevent using createBrushEvent, but then it seems I have to assign a value to PictureEvent > BrushTipMovers > ScatterOffset in a mouse move event?

this.currentEvent.BrushTipMovers.ScatterOffset = "10" 

The functions available on BrushTipMover don't seem to have any setters. Is this the right way to adjust that setting?

Thanks!

Enable asserts

This would improve robustness of the code. Asserts offered by the Google library would probably be the best choice, since the library is already written with Closure compiler in mind.

Allow pressure to modify Opacity and/or Flow

Currently the pressure parameter alters the radius of the brush stroke. It would be beneficial if the pressure could also be used for changing the opacity and flow settings. The Photoshop brush allows the user to choose which brush properties are changed with pen pressure.

Write a minimal GLSL test exposing bug in setting a varying inside if statement

This type of vertex shader code failed to render a vertical gradient, which is why the current code generates different shaders for vertical and non-vertical gradients:

if (abs(uCoords0.x - uCoords1.x) < 0.001) {
varying = vertical gradient formula;
} else {
gradient code
varying = result;
}

Figure out if this really was a bug in WebGL / NVIDIA driver v311 stack or some misunderstanding, and see if it reproes elsewhere.

Figure out blending to target with 0 opacity for all blending modes

The blending shaders should implement at least one of these two modes:

  1. If blending mode is other than normal and target pixel opacity is 0, draw with normal mode (equivalent to PhotoShop).
  2. Option to keep target pixel opacity when drawing, which would be always on when blending mode is other than normal.

This will replace the current behavior, where blending to target of 0 opacity with other modes than normal hasn't been addressed as a special case, and the result is what happens to come out of the formula. Existing pictures breaking because of the changes is acceptable.

Support Closure compiler's ADVANCED_OPTIMIZATIONS flag

This will involve at least making sure GLSL uniform names are referenced only in strings, not in property names with dot notation. Otherwise uniform names will be inconsistent between JS and GLSL when they're shortened in JS.

Implement buffer merging

It should be possible to merge two buffers into one, rendering their compositing result to the bottom buffer. The merge should be added as an event to the bottom buffer, and be undoable like other events.

Expand the event mechanism to cover Picture operations

Operations that are not currently handled by events:
-Add a buffer
-Remove a buffer
-Move a buffer in the stack
-Change buffer settings (opacity, visibility, eventually mode...)

These could either be stored in an events array in the Picture itself, or in the buffer they relate to. If the latter approach is chosen, an addBuffer event would then always be the first thing stored in any buffer.

Load brush textures asynchronously?

I have an array of object literals for image brush textures. I loop to create img elements that are then pushed into a brushTextures array. That array is passed into the renderer when a picture is initialized. It appears as if they aren't loaded by the time Picture is attached, and brush events are pushed to the picture. This throws a bunch of web gl 'no image' errors in the console.

They eventually load when I go back to my page but the first time, there is no brush output if i'm using a textureid on the brush event.

Can we add a way in the renderer to keep loading the textures even after Picture has been attached to the canvas?

Verify interpolation alignment

Write a test that verifies whether varyings get interpolated at the pixel center (0.5, 0.5) and if not, think about possible ways to compensate for misalignment. Gradient rendering code could be used for this.

Implement having multiple current events at once

This would be useful for multitouch applications. Basically, the currentEvent could be replaced with an array of events, and Picture.setCurrentEvents() added beside Picture.setCurrentEvent(). A multitouch example could be built on top of this.

Consider freeing memory for removed buffers

The library should be able to determine when undoing a buffer removal becomes unlikely enough that the memory for the removed buffer can safely be freed. Freeing could also be done always if the buffer's contents are cheap to regenerate on undo.

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.