p5jsShaderExamples | A collection of heavily commented WebGL shaders | Graphics library
kandi X-RAY | p5jsShaderExamples Summary
kandi X-RAY | p5jsShaderExamples Summary
A collection of heavily commented WebGL shaders created with p5.js and GLSL
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of p5jsShaderExamples
p5jsShaderExamples Key Features
p5jsShaderExamples Examples and Code Snippets
Community Discussions
Trending Discussions on p5jsShaderExamples
QUESTION
I am trying to use a glsl shader with p5js to create a simulation like the game of life. To do that I want to create a shader which will take a texture as uniform and which will draw a new texture based on this previous texture. In a next iteration this new texture will be used as uniform and that should allow me create a simulation following the idea exposed here. I am experienced with p5.js but I'm completely new to shader programming so I'm probably missing something.
For now my code is as straightforward as possible:
- In the
preload()
function, I create a texture using thecreateImage()
function and setup some pixels to be white and the others to be black. - In the
setup()
function I use this texture to run the shader a first time to create a new texture. I also set a timer to run the shader at regular intervals and draw the result in a buffer. - In the
draw()
function I draw the buffer in the canvas. - To keep things simple I keep the canvas and the texture the same size.
My issue is that at some point the y
coordinates in my code seems to get inverted and I don't understand why. My understanding is that my code should show a still image but each time I run the shader the image is inverted. Here is what I mean:
I am not sure if my issue comes from how I use glsl or how I use p5 or a mix of both. Can someone explain to me where this weird y
inversion comes from?
Here is my minimal reproducible example (which is also in the p5 editor here):
The sketch file:
...ANSWER
Answered 2021-May-18 at 08:52Long story short: the texture coordinates for a rectangle or a plane drawn with p5.js are (0, 0) in the bottom left, and (1, 1) in the top right, where as the coordinate system for sampling values from a texture are (0, 0) in the top left and (1, 1) in the bottom right. You can verify this by commenting out your color sampling code in your fragment shader and using the following:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install p5jsShaderExamples
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