glsl

How do i display 2 or more objects in openGL (model - view - projection matrices and shaders)

爷,独闯天下 提交于 2019-12-22 05:09:30
问题 It's all ok when i want to draw one object, for example a cube. I create vertices for cube, i create the buffer, i create the MVP matrix and send it to shader and it works nice. But, what to do when i want to draw 2 or more objects , for example both cube and a triangle? I believe that View and Projection matrices should be same both for triangle and cube, i only need different Model matrix, right? So that means that i will have two MVPs? //Example (using GLM): glm::mat4 MVPC = Projection *

Compute shader not modifying 3d texture

醉酒当歌 提交于 2019-12-22 04:35:13
问题 I want to move the initialization of my 3D texture from the CPU to the GPU. As a test, I wrote a shader to set all voxels to a constant value, but the texture is not modified at all. How do I make it work? Compute shader: #version 430 layout(local_size_x=1, local_size_y=1, local_size_z=1) in; layout(r8, location = 0) uniform image3D volume; void main() { imageStore(volume, ivec3(gl_WorkGroupID), vec4(0)); } Invocation: glEnable(GL_TEXTURE_3D); glActiveTexture(GL_TEXTURE0); glGenTextures(1,

Floyd–Steinberg dithering alternatives for pixel shader

左心房为你撑大大i 提交于 2019-12-22 03:56:10
问题 I know that Floyd–Steinberg dithering algorithm can't be implemented with pixel shader, because that algorithm is strictly sequential. But maybe there exist some higly parallel dithering algorithm which by it's visual output is similar to Floyd-Steinberg algorithm ? So the question is - What are dithering algorithms which are suitable to implement on pixel shader (preferably GLSL) and with output quality (very) similar to Floyd-Steinberg dithering ? BTW. Multi-pass algorithms are allowed

GLSL函数整理

走远了吗. 提交于 2019-12-22 01:43:09
1 角度和三角函数 标识为angle的函数参数假定以弧度为单位。这些函数不可能出现被0除的情况,如果被除数为0,结果是未定义的。 radian函数是将角度转换为弧度,degrees函数是将弧度转换为角度。sin, cos, tan都是标准的三角函数。asin, acos, atan是反三角函数。genType有点像面向对象中泛型,即如果genType是float型的,那么 genType pow (genType x, genType y) 就变成了: float pow (float x, float y) 同理,如果genType是int型的,那么就变成了: int pow (int x, int y); 2 指数函数 (1)genType pow (genType x, genType y) x的y次方。如果x小于0,结果是未定义的。同样,如果x=0并且y<=0,结果也是未定义的。使用时应特别注意。 (2)genType exp (genType x) e的x次方 (3)genType log (genType x) 计算满足x等于e的y次方的y的值。如果x的值小于0,结果是未定义的。 (4)genType exp2 (genType x) 计算2的x次方 (5)genType log2 (genType x) 计算满足x等于2的y次方的y的值。如果x的值小于0

Why am I getting a blank screen when using shader?

折月煮酒 提交于 2019-12-22 01:30:53
问题 I'm using this tutorial to create and draw an outline for my game Sprite s. However, all I get is a blank red screen. I'm very new to Shader s so I'm not sure if I'm missing something very trivial. My vertex and fragment shaders were copy-pasted from the above tutorial. (Commenting on the tutorial doesn't seem to work so I was unable to seek help there.) My code: float x = 0, y = 0, height = 256, width = 256, angle = 0, outlineSize = 1f; @Override public void create() { batch = new

Using GL_INT_2_10_10_10_REV in glVertexAttribPointer()

妖精的绣舞 提交于 2019-12-21 23:21:10
问题 Can anybody tell me how exactly do we use GL_INT_2_10_10_10_REV as type parameter in glVertexAttribPointer() ? I am trying to pass color values using this type. Also what is the significance of "REV" suffix in this type ? Does it require any special treatment in the shaders ? My code is as follows : GLuint red=1023,green=1023,blue=1023,alpha=3; GLuint val = 0; val = val | (alpha << 30); val = val | (blue << 20); val = val | (green << 10); val = val | (red << 0); GLuint test_data[]={val,val

GLSL shader for texture 'smoke' effect

落花浮王杯 提交于 2019-12-21 23:12:22
问题 I've looked around and haven't found anything relevant. I'm tyring to create a shader to give a texture smoke effect animation like here: Not asking for a complete/full solution (although that would be awesome) but any pointers towards where I can get started to achieve this effect. Would i need to have the vertices for the drawing or is this possible if I have the texture only? 回答1: In the example pictured it appears as if they have the vertices. Possibly the "drawing" of the flower shape

Coloring rectangle in function of distance to nearest edge produces weird result in diagonals

北战南征 提交于 2019-12-21 21:37:18
问题 I'm trying to color a rectangle in ShaderToy/GLSL in function of each pixel's distance to the nearest rectangle edge. However, a weird (darker) result can be seen on its diagonals: I'm using the rectangle UV coordinates for it, with the following piece of code: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Normalized pixel coordinates (from 0 to 1) vec2 uv = fragCoord/iResolution.xy; vec2 uvn=abs(uv-0.5)*2.0; float maxc=max(uvn.y,uvn.x); vec3 mate=vec3(maxc); fragColor = vec4

read and write integer 1-channel texture opengl

岁酱吖の 提交于 2019-12-21 21:32:31
问题 I want to: create a read and writable 1-channel texture that contains integers. using a shader, write integer "I" to the texture. use the texture as a source, sample it and compare if the sample is equal to the integer I. All this with core profile 3.3. This is what I've got so far: I create the texture like so: glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_INT, (java.nio.ByteBuffer) null); I've Also tried GL_R8I and GL_RED_INTEGER, but that won't work. I bind this

Use octree to organize 3D volume data in GPU

☆樱花仙子☆ 提交于 2019-12-21 21:03:36
问题 I am now trying to implement Ray Casting Volume Rendering using C++, OpenGL and GLSL (for GPU speeding). In order to get better quality and performance, I want to use octree to organize the 3D medical volume data,so I can use some algorithm such as Space Leaping and Adaptive Sampling easily. But how to build the octree effectively? How to visit the octree? When the ray travels in the volume data, how can I determine which cell or leaf of the octree the sample point belong? 回答1: There is an