GithubHelp home page GithubHelp logo

leju_effect's Introduction

leju_effect

basic 2d effect with shader develop branch for develop

This is the basic project for simple 2D effect with webgl shader calculation. File structure:

. ├── lib │ ├── cuon-matrix.js // Webgl Matrix 4 * 4 class, no need to care here │ ├── cuon-utils.js // Webgl Shader warpper, no need to care here │ ├── webgl-debug.js // Webgl tool for debug, no need to care here │ ├── webgl-utils.js // Webgl warpper, no need to care here │ ├── resources │ ├── view.jpg // A giant image which is 2560 * 1600 for testing the effects' speed │ ├── src │ ├── effect.html // The frontend web page, which includes the UI │ ├── effect.js // The webgl shader and function logic │ ├── README.md

Setup: Just open the effect.html, if there is no image shows on the page, then do the following steps: (Assume the browser is chrome) 1. Right click on the Chrome's icon, choose property(Last option) 2. Add "--enable-webgl --ignore-gpu-blacklist --allow-file-access-from-files" in the "Target" For example: My path for chrome is : C:\Users\Lee\AppData\Local\Google\Chrome\Application\chrome.exe Then it becames: C:\Users\Lee\AppData\Local\Google\Chrome\Application\chrome.exe --enable-webgl --ignore-gpu-blacklist --allow-file-access-from-files

Restart the Chrome then.

PS: Shut down all the chrome pages before doing these.

Adjust the effect: There are several effects on the page you can play with: 亮度(Brightness) 对比度(Contrast) 色相(Hue) 饱和度(u_Saturation) 明度(Lightness) 色阶(Level) 锐化(Sharpen) Each one will have the immediately effect showing on the page.

Code: The code is not that hard to understand: All the key functions are start with "on" and end with "adjust" Such as "onHueAdjust" Passing the parameters from the frontend page into the shader.

Shaer: I combine all the function into one big shader since it's easy to implement. It's totally ok to split them and use them in different canvases.

'void main() {\n' +
'   vec3 color = texture2D(u_Sampler, v_TexCoord).xyz * 255.0;\n' + 

'   color = brightAdjust(color);  \n' +
'   color = contrastAdjust(color);  \n' +
'   color = hslAdjustment(color);  \n' +
'   color = stageAdjust(color);  \n' +
'   color = sharpenAdjust(color);  \n' +
'   gl_FragColor = vec4(color / 255.0, 1.0);\n' +

'}\n';

The shader takes the image texture's info, which is pixel as vec3 color, then pass it into the effect functions.
Such as brightAdjust() or contrastAdjust()
No need to read the implementation of each function.

Q&A: just contact me by QQ or wechar or by phone.

Li

leju_effect's People

Contributors

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