Posts

Showing posts with the label glsl

exact coordinates of gl_PointCoord?

Image
Clash Royale CLAN TAG #URR8PPP exact coordinates of gl_PointCoord? In a vertex i give pointSize a value bigger than 1. Say 15. In the fragment i would like choose a point inside that 15x15 square : vec2 sprite = gl_PointCoord; if (sprite.s == (9. )/15.0 ) discard ; gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); But that does not work when Size is not a power of 2. (if size is 16, so (sprite.s == a/16.) where a is in 1..16 : Perfect !) is a way to achieve my purpose where size is not of power of 2 ? edit : i know the solution with a texture of size : PointSize * PointSize gl_FragColor = texture2D(tex, gl_PointCoord); but that not fit for dynamic change edit 26 july : first I do not understand why it is easier to read in a float texture using webgl2 rather than webgl. For my part I make an ext = gl.getExtension ("OES_texture_float"); and the gl.readpixel uses the same syntax. Then, it is certain that I did not understand everything but I tried the solution s = 0.25 and s = 0.75 ...

Should I ever use a `vec3` inside of a uniform buffer or shader storage buffer object?

Image
Clash Royale CLAN TAG #URR8PPP Should I ever use a `vec3` inside of a uniform buffer or shader storage buffer object? The vec3 type is a very nice type. It only takes up 3 floats, and I have data that only needs 3 floats. And I want to use one in a structure in a UBO and/or SSBO: vec3 layout(std140) uniform UBO { vec4 data1; vec3 data2; float data3; }; layout(std430) buffer SSBO { vec4 data1; vec3 data2; float data3; }; Then, in my C or C++ code, I can do this to create matching data structures: struct UBO { vector4 data1; vector3 data2; float data3; }; struct SSBO { vector4 data1; vector3 data2; float data3; }; Is this a good idea? 1 Answer 1 NO! Never do this! When declaring UBOs/SSBOs, pretend that all 3-element vector and matrix types don't exist . Pretend that the only types are scalars, 2, and 4 element vectors (and matrices). You will save yourself a very great d...