Last active
September 30, 2019 22:47
-
-
Save sortofsleepy/411fb9594c0ce37c9e17e02ac711a326 to your computer and use it in GitHub Desktop.
Basic template for utilizing a texture as an array and setting it up with data at specific columns/rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| precision highp float; | |
| // note - assuming OpenGL ES 2.0 - adjust as needed | |
| // the number of items total you want to write out on each row | |
| #define NUM 100 | |
| // the row of pixels to store, in this example positions | |
| #define POSITION_ROW 2 | |
| // the row of pixels to store, in this example, colors. | |
| #define COLOR_ROW 3 | |
| void main() { | |
| // figure out the position that we're sampling at. | |
| int index = int(gl_FragCoord.x); | |
| int row = int(gl_FragCoord.y); | |
| // figure out if we're parsing the row storing all particle positions. | |
| // positions are stored on row 10 | |
| bool isPos = row==POSITION_ROW; | |
| if(isPos){ | |
| if(index < NUM){ | |
| // write out your information here, will go to position row. | |
| gl_FragColor = vec4(1.); | |
| } | |
| }else { | |
| // it's important to discard whatever you don't need. | |
| discard; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment