webgl-2d | Canvas2D API in WebGL | Canvas library
kandi X-RAY | webgl-2d Summary
kandi X-RAY | webgl-2d Summary
Canvas2D API in WebGL
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse HTML .
- Parses a string
- tag handler
- Style selector .
- Advances the first token in the token input .
- Check option .
- Parse statements .
- Parse JSON values .
- Parse statement .
- Processes a CSS value .
webgl-2d Key Features
webgl-2d Examples and Code Snippets
Community Discussions
Trending Discussions on webgl-2d
QUESTION
Because of computation efficiency, I use a fragment shader to implement a simple 2D metaballs algorithm. The data of the circles to render is top-left oriented.
I have everything working, except that the origin of WebGL's coordinate system (bottom-left) is giving me a hard time: Obviously, the rendered output is mirrored along the horizontal axis.
Following https://webglfundamentals.org/webgl/lessons/webgl-2d-rotation.html (and others), I tried to rotate things using a vertex shader. Without any success unfortunately.
What is the most simple way of achieving the reorientation of WebGL's coordinate system?
I'd appreciate any hints and pointers, thanks! :)
Please find a working (not working ;) ) example here: https://codesandbox.io/s/gracious-fermat-znbsw?file=/src/index.js
...ANSWER
Answered 2021-Jun-07 at 08:43Since you are using gl_FragCoord in your pixels shader, you can't do it from the vertex shader becasuse gl_FragCoord is the canvas coordinates but upside down. You could easily invert it in javascript in your pass trough to WebGL
QUESTION
I'm trying to optimize my shader that draws sprites and I originally had something like this:
...ANSWER
Answered 2021-Apr-27 at 14:36For most graphics API commands what happens is that the command is encoded in a command-buffer, at some point (asynchronously) those buffers are synchronized to the GPU by the graphics driver. For a command buffer to be predictable all data needs to be copied to be put into the buffer.
Now one problem with your code is that you're setting the data and immediately ask the GPU to draw from it, requiring a hard sync of the complete buffer. The driver expects uniforms to need syncing but not necessarily array buffers, the usage hints (DYNAMIC
,STREAM
and STATIC
draw) don't really do much about that (actually in most cases STATIC_DRAW
is faster even for dynamic data).
When these hard syncs happen you're almost always stalling the pipeline, meaning the GPU needs to wait for all the data to be transferred before it can continue doing whatever it was doing. You can avoid this by utilizing double or even triple buffering (write data for the next frame but render current one etc.).
However with all this being said, trying to optimize the draw of 6 quads is very problematic as (in this context) we're talking about immeasurable differences here, changing one thing over the other might change the frame-time but it doesn't say anything about scalability as you're really just measuring the (often static) overhead rather than the actual performance.
QUESTION
I have been learning webgl from webglfundamentals where I came across a simple shader example where you can paint triangles with solid color. Here is link to tutorial and original demo.
I tried to create same effect in three js using plane geometry but I can't manage achieve solid color shader. When I use almost same setup in Three js, I get more like gradient effect. What am I doing wrong here? (I am noticing that my shader isn't consistent either as it renders differently on refresh) Also, is there place to learn shaders specifically for three js?
...ANSWER
Answered 2021-Jan-28 at 16:20The PlaneBufferGeometry
in three.js is using indexed vertices to share vertices so there are only 4 vertices and then 6 indices to use those 4 vertices to make 2 triangles. That means you can't give each triangle different solid colors because they share 2 vertices and a vertex can only have 1 color.
Further, the code is choosing random colors for each vertex so even if you you used 6 vertices so that the 2 triangles didn't share any you still wouldn't get the result you linked to, instead you'd get this result which is further down the page on the same tutorial.
Finally the code is only generating 3 floats per color so you need to set the number of components for the color attribute to 3 instead of 4
If you want to repeat the webgl sample you'll need to provide your own 6 vertices.
QUESTION
I have been trying to use my own matrices in WebGL (2d at the moment). My main reference is webglfundamentals.com. I multiply a 360-degree rotation with a (1, -1) scale, (-142, 6) translation, and a projection matrix. My rectangle shows up fine, but without a translation. Here is my code:
...ANSWER
Answered 2020-Jun-22 at 18:57The reason is in your shader math, z = 0.
This line in your shader
QUESTION
EDIT: Simpler explenation of the problem first. More detailed explanation below.
I use some jquery widgets code to create a UI slider. The code is here:
https://webgl2fundamentals.org/webgl/resources/jquery-gman-circle.js
This can be used, calling the component directly in the JS script like this:
...ANSWER
Answered 2020-Jun-06 at 19:47I had a closer look at your code and reduced it to the absolute minimum. It turns out you can supply the starting value of the angle simply by putting it into the empty options argument of the initiatior method: $("#example").gmanUnitCircle({value: -Math.PI/3});
. In my example I chose the value of -60° in radians.
QUESTION
Javascript is a new languaje for me so this is a simple task that I cannot achieve. I can set the slider and update the position of my element when I change the slider with:
...ANSWER
Answered 2020-May-28 at 02:53There's a couple of things that needed to be done in my opinion to achieve this based on the example you provided. First, the main()
function on lines 98 and 99 is setting up the sliders like so:
webglLessonsUI.setupSlider("#x", {slide: updatePosition(0), max: gl.canvas.width }); webglLessonsUI.setupSlider("#y", {slide: updatePosition(1), max: gl.canvas.height});
If we check the library you provided (around line 99) we can see that the function setupSlider
returns an object with both the html reference and a function to update its value:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install webgl-2d
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page