glsl

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

泪湿孤枕 提交于 2019-12-05 07:03:48
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 * View * ModelCube; glm::mat4 MVPT = Projection * View * ModelTriangle; So what do i do with those two now

Can you pass a fixed-size array as a GLSL function parameter?

坚强是说给别人听的谎言 提交于 2019-12-05 06:27:28
In a GLSL shader, I want to create a function that looks a bit like this : void MyFunction(out float results[9]) { float value0 = 3.1546; float value1 = 42; // whatever value /* ... long, complicated code ... */ results[0] = value0; results[1] = value1; results[2] = value2; ... } Can such a function signature be used and compiled in GLSL ? If no, are there any alternatives ? Yes, this is legal GLSL code. That doesn't mean it will certainly compile, but it is legal code. That being said, it's probably better to just return the array (which you can also do), rather than pass it as an output

Compute Shader write to texture

断了今生、忘了曾经 提交于 2019-12-05 06:11:18
I have implemented CPU code that copies a projected texture to a larger texture on a 3d object, 'decal baking' if you will, but now I need to implement it on the GPU. To do this I hope to use compute shader as its quite difficult to add an FBO in my current setup. Example image from my current implementation This question is more about how to use Compute shaders but for anyone interested, the idea is based on an answer I got from user jozxyqk, seen here: https://stackoverflow.com/a/27124029/2579996 The texture that is written-to is in my code called _texture , whilst the one projected is

Compute shader not modifying 3d texture

早过忘川 提交于 2019-12-05 05:09:07
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, &volume_tid); glBindTexture(GL_TEXTURE_3D, volume_tid); glTexImage3D(GL_TEXTURE_3D, 0, GL_R8, volume_dims

OpenGL超级宝典笔记——GLSL语言基础

僤鯓⒐⒋嵵緔 提交于 2019-12-05 04:39:09
变量 GLSL的变量命名方式与C语言类似。变量的名称可以使用字母,数字以及下划线,但变量名不能以数字开头,还有变量名不能以gl_作为前缀,这个是GLSL保留的前缀,用于GLSL的内部变量。当然还有一些GLSL保留的名称是不能够作为变量的名称的。 基本类型 除了布尔型,整型,浮点型基本类型外,GLSL还引入了一些在着色器中经常用到的类型作为基本类型。这些基本类型都可以作为结构体内部的类型。如下表: 类型 描述 void 跟C语言的void类似,表示空类型。作为函数的返回类型,表示这个函数不返回值。 bool 布尔类型,可以是true 和false,以及可以产生布尔型的表达式。 int 整型 代表至少包含16位的有符号的整数。可以是十进制的,十六进制的,八进制的。 float 浮点型 bvec2 包含2个布尔成分的向量 bvec3 包含3个布尔成分的向量 bvec4 包含4个布尔成分的向量 ivec2 包含2个整型成分的向量 ivec3 包含3个整型成分的向量 ivec4 包含4个整型成分的向量 mat2 或者 mat2x2 2x2的浮点数矩阵类型 mat3或者mat3x3 3x3的浮点数矩阵类型 mat4x4 4x4的浮点矩阵 mat2x3 2列3行的浮点矩阵(OpenGL的矩阵是列主顺序的) mat2x4 2列4行的浮点矩阵 mat3x2 3列2行的浮点矩阵 mat3x4

Behavior of uniforms after glUseProgram() and speed

流过昼夜 提交于 2019-12-05 03:32:58
How fast is glUseProgram()? Is there anything better (faster)?: Here are my thoughts: Use 1 universal shader program, but with many input settings and attributes (settings for each graphics class) Use more than 1 shader for each graphics class What state are uniforms in after changing the shader program? Do they save values (for example, values of matrices)? Here are what I consider the benefits of #1 to be: Doesn't use glUseProgram() And the benefits of #2: No matrix changes (for example, if class Menu and class Scene3D have different Projection matrices) What of the two options is better

Why don't people use tetrahedrons for skyboxes?

ⅰ亾dé卋堺 提交于 2019-12-05 03:14:18
When rendering a sky with a fixed texture in 3D games, people often create 6 textures in a cube map first, and then render a cube around the camera. In GLSL, you can access the pixels in the textures with a normal instead of a texture coordinate, and you can easily get this normal by normalizing the fragment position relative to the camera. However, this process can be done with any shape that surrounds the camera, because when you normalize each position it will always result in a sphere. Now I'm wondering: Why is it always a cube and not a tetrahedron? Rendering a cube takes 12 triangles, a

THREE.js repeat wrapping texture in shader

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:20:42
问题 I want to repeat wrapping texture in THREE.js shader. The original texture image is: I want it to repeat 4x4 times which will looks like: But with the following code, it turns out to be: Vertex shader: varying vec2 vUv; uniform float textRepeat; void main() { // passing texture to fragment shader vUv = uv * textRepeat; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); } Fragment shader: varying vec2 vUv; uniform sampler2D texture; void main() { // add origianl texture gl

Why am I not able to attach this texture uniform to my GLSL fragment shader?

喜你入骨 提交于 2019-12-05 02:12:40
问题 In my Mac application, I define a rectangular texture based on YUV 4:2:2 data from an attached camera. Using standard vertex and texture coordinates, I can draw this to a rectangular area on the screen without any problems. However, I would like to use a GLSL fragment shader to process these image frames on the GPU, and am having trouble passing in the rectangular video texture as a uniform to the fragment shader. When I attempt to do so, the texture simply reads as black. The shader program

Floyd–Steinberg dithering alternatives for pixel shader

≯℡__Kan透↙ 提交于 2019-12-05 00:47:05
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 until there are not more than 2 passes and CPU overhead between those passes is small. Any ideas ? EDIT: I