Hot answers tagged

45

If you're getting started now, and you want to do GPU work (as opposed to always using a game engine such as Unity), you should definitely start by learning Vulkan. Maybe you should learn GL later too, but there are a couple of reasons to think Vulkan-first. GL and GLES were designed many years ago, when GPUs worked quite differently. (The most obvious ...


37

Hardly! This seems a lot like asking "Should new programmers learn C++ instead of C," or "Should new artists be learning digital painting instead of physical painting." Especially because it's NOT backward compatible, graphics programmers would be foolish to exclude the most common graphics API in the industry, simply because there's a new one. ...


36

Learning graphics programming is about more than just learning APIs. It's about learning how graphics works. Vertex transformations, lighting models, shadow techniques, texture mapping, deferred rendering, and so forth. These have absolutely nothing to do with the API you use to implement them. So the question is this: do you want to learn how to use an API?...


33

As far as I know there are no tools that allows you to steps through code in a shader (also, in that case you would have to be able to select just a pixel/vertex you want to "debug", the execution is likely to vary depending on that). (NOTE: Renderdoc allows you to do so by selecting a specific thread/pixel) What I personally do is a very hacky &...


31

The common names for the components of texture coordinates are U and V. However, because the next letter used (for 3D textures) is W, that causes a conflict with the names for the components of a position: X, Y, Z, and W. To avoid such conflicts, OpenGL's convention is that the components of texture coordinates are named S, T, and R. Thus, you have function ...


29

First, gl_FragCoord.xy are screen space coordinates of current pixel based on viewport size. So if viewport size is width=5, height=4 then each fragment contains: Why are uvs needed? For example I rendered geometry to screen quad and then I need to apply some postprocessing on this quad in another rendering pass. To sample from that quad I need texture ...


25

OpenGL is a state machine. An OpenGL context holds that state. The state contains information such as which textures are bound to which texture units, which attachments the current FBO has, and things like that. When you set the current context, you are switching all the state from the old context to the new context. Here's an example: ...


22

Pixel screen-space derivatives do drastically impact performance, but they impact performance whether you use them or not, so from a certain point of view they're free! Every GPU in recent history packs a quad of four pixels together and puts them in the same warp/wavefront, which essentially means that they're running right next to each other on the GPU, ...


21

Generally to see what is being rendered in the various steps of your pipeline I'd suggest the use of a tool for frame analysis. These usually provide you with a view on the content of each buffer for each API call and this can help you in your situation. A very good one is Renderdoc which is both completely free and opensource. Also it is actively supported....


18

Generally edge detection boils down to detect areas of the image with high gradient value. In our case we can crudely see the gradient as the derivative of the image function, therefore the magnitude of the gradient gives you an information on how much your image changes locally (in regards of neighbouring pixels/texels). Now, an edge is as you say an ...


17

Assuming you mean a camera that rotates based on mouse movement: One way to implement it is to keep track of the camera position and its rotation in space. Spherical coordinates happen to be convenient for this, since you can represent the angles directly. float m_theta; float m_phi; float m_radius; float3 m_target; The camera is located at P which is ...


16

No, there is not really a way to do that. A geometry shader invocation requires an input primitive and generates 0 or more output primitives. Without an input primitive, there is not really a way to actually invoke the geometry shader. Of course you can stretch the limits of the geometry shader's maximum number of output primitives for each input primitive (...


15

Use cases are only limited by your imagination! noperspective means that the attribute is interpolated across the triangle as though the triangle was completely flat on the surface of the screen. You can do antialiased wireframe rendering with this: output a screen-space distance to the nearest edge as a noperspective varying and use that as coverage in the ...


14

I don't think uniform arrays can be dynamically sized. In your case you should define the array as the maximum number of lights you will process and then use a uniform to control the number of iterations you do on this array. On the CPU side you can set a subset of the lights[] array according to the 'size' variable. e.g. #define MAX_LIGHTS 128 uniform ...


14

OK, I have figured out this problem. For the texture coordinates, there are two kind of texture coordinates. One is normalized texture coordinates, which is in the range [0, 1]. The other is texel space, which is in the range [0, size), where size is the size of the texture. For texelFetch(), the texel space is used. For lod, it means the level of detail ...


13

You don't need to rebind the attributes, so long as you ensure that their location stays the same in both shaders. (Usually using the layout(location = X) syntax in GLSL, but can also be done with glBindAttribLocation if former is not available.) Uniforms, however, are part of the Shader Object state, and so will need to be set at least once for every ...


13

No it is not guaranteed, since the OpenGL specification allows that two Compute Shader run concurrently or even in different order. You need to call glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT) before the second glDispatchCompute to ensure visibility of the writes from program_one. From the OpenGL.org wiki article on the memory model: [...] ...


13

Nvidia has an extension for creating command buffers in modern GL. The reason for the lack of similar functionality is that there is a lot of state involved regarding how to render and the display list be affected by a lot of different state. For example changing the blend state requires patching the fragment shader on some hardware. NVidia solved it by ...


13

Image 1: A bad case of shadow acne. (Synthetic and a bit exaggerated) Shadow acne is caused by the discrete nature of the shadow map. A shadow map is composed of samples, a surface is continuous. Thus, there can be a spot on the surface where the discrete surface is further than the sample. The problem does persist even if you multi sample, but you can ...


13

The problem is, glVertexAttribPointer(0, 4, GL_DOUBLE... doesn't do what you think it does. Using actual double-precision vertex attributes and performing double precision computations is a very modern hardware feature (GL4/DX12) and is different from specifying the type GL_DOUBLE in the good old glVertexAttribPointer call. This always worked and does ...


12

Modern hardware doesn't really have the concept of texture binding points as exposed by OpenGL. Rather, the shader unit uses a descriptor (which is just some kind of fat pointer) which can potentially address any texture as long as it's resident in video memory. This is what makes things like bindless textures possible. So the large amount of "texture units" ...


12

Because the fundamental foundation of OpenGL makes multi-CPU-core submission impossible. OpenGL, at its core, is a synchronous API. Every OpenGL command behaves "as if" it were executed and completed immediately. Sure, glFlush and glFinish are provided, so that implementations can have some asynchronous execution of commands. But these are essentially fig ...


12

Yes, there is a better way! 😊 OpenGL 4.3 and later support the glDebugMessageCallback API, which allows you to specify a function in your app that GL will call to issue a warning or error. In this function you can do whatever you like, such as setting a breakpoint in the debugger, or printing the error to a log file. This way you only need to setup the ...


11

In entirely technical terms, fwidth(p) is defined as fwidth(p) := abs(dFdx(p)) + abs(dFdy(p)) And dFdx(p)/dFdy(p) are the partial derivates of the value p with respect to the x and y screen dimensions. So they denote how the value of p behaves when going one pixel to the right (x) or one pixel up (y). Now how can they be practically computed? Well, if you ...


11

Updating an area of memory in the graphics device (a texture, buffer, and the like) is not quite the same as changing a rendering state. What makes a render state change expensive is the amount of work the driver has to do to validate the new state(s) and reorder the pipeline. This will most likely also incur some synchronization between CPU and graphics ...


11

A set of techniques to avoid explicit ordering go under the name of Order Independent Transparency (OIT for short). There are lots of OIT techniques. Historically one is Depth Peeling. In this approach you first render the front-most fragments/pixels, then you find the closest to the one found in the previous step and so forth, going on with as many "...


11

I tested several applications/APIs/libraries to get data from FBOs in applications which use gbuffer for example. After months of suffering I discovered apitrace available on Github to debug OpenGL, Direct3D and WebGL. I used in Windows and Linux without problems. I hope that could be useful for you.


11

This issue looks like standard shadow map acne artifacts. Additionally your's lighting equation is incomplete or wrong. Light shouldn't influence faces with normals facing away from it. This also means that with a proper equation the "dark" side of the sphere shouldn't have any acne artifacts. There are three sources of acne artifacts: First acne source is ...


11

You still have to bind the desired texture to the texture unit to use it for rendering. In your current code, you're not specifying which texture to use for rendering, so the GL driver doesn't know which one you want to use and is defaulting to "no texture". There are a few ways to bind a texture. You can keep using glActiveTexture+glBindTexture as in your ...


11

If you are writing your own Vertex/Fragment Shader there is another additional possibility to do this. It is much more complicated but might be useful for you and/or others. Additionally it speeds up the whole drawing process since it uses only one call to a draw command. The maximum number of Viewports is defined by GL_MAX_VIEWPORTS and is usually 16. ...


Only top voted, non community-wiki answers of a minimum length are eligible