Code Monkey home page Code Monkey logo

glsl-projectron's Introduction

GLSL-Projectron


This is a WebGL/GPGPU demo I made to try out shader programming. It generates random 3D polygons which resemble a given target image when projected. Basically it's similar to this, but done in 3D and on the GPU.

After many generations, you get a chaotic bunch of polygons that align into an image, but only from just the right angle:

Screencap of sample output

Live demos:

I also wrote a blog post here explaining the algorithm, and how I made it run fast on the GPU.

Installation & Usage

git clone [this repo]
cd glsl-projectron
npm install
npm start

That serves a local build of the "Create" demo linked above, in localhost:8080.

Use npm run build to rebuild the static version in /docs.

To use this as a dependency, follow the example in /demo/maker.js:

import { Projectron } from 'path/to/glsl-projectron'
var proj = new Projectron(canvasElement)

var img = new Image()
img.onload = () => { proj.setTargetImage(img) }
img.src = 'path/to/image.png'
//..
proj.runGeneration()    // many times..
proj.draw(x,y)          // once per frame..

Known issues:

  • Doesn't detect most error cases (just whether WebGL is supported)
  • Library treats input images as if they were square. To use for other aspects, just run it normally and change the aspect of the canvas you use to display the results.

Credits

Made with ๐Ÿบ by Andy Hall. MIT license.

glsl-projectron's People

Contributors

amilajack avatar dependabot[bot] avatar fenomas avatar nariyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glsl-projectron's Issues

Averaging using mipmaps

Hello! That's some nice and fast results you get, with such a simple setup. I have been experimenting with something similar myself, with emphasis on GA. The whole GA runs in JS, and just like you, I have found that readPixels is the bottleneck. Thus, my next step is to batch many individual fitnesses into a single framebuffer before reading all of them. Later, I will try to move the individual specifications into vertex textures and try to do the evolution almost solely on the GPU too.

I would just like to share an idea I have used for the averaging: Mipmaps. When you have an image with equal power-of-two dimensions, the smallest, single-pixel, representation in the mipmap will be the average color. This is something the GPU is optimized to do, and does not require repeated application of a custom shader. I simply draw a single-pixel representation of the texture.

And for the batching I am planning, I will just draw multiple single-pixel representations. 16-ish per draw call, then I think I can slide the quad over the buffer for multiple draw calls without clearing it, and then readPixels the whole population fitness at once.

BTW, here is an example of what I have done, in this case using a setup that draws GL points:
2kgen

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.