Questions tagged [shader]

A shader is a program to perform calculations on geometry or pixel data in computer graphics.

A shader is a program to perform calculations on geometry or pixel data in computer graphics. With the rapid progress and availability of consumer GPUs during the last decade, an initially software-only solution for high-end RenderMan workstations became widely available. Today, the term is mostly associated with , , , or , which allow convenient, hardware agnostic high-level programmability on consumer GPUs.

6931 questions
18
votes
3 answers

Convert floating-point numbers to decimal digits in GLSL

As others have discussed, GLSL lacks any kind of printf debugging. But sometimes I really want to examine numeric values while debugging my shaders. I've been trying to create a visual debugging tool. I found that it's possible to render an…
jez
  • 14,867
  • 5
  • 37
  • 64
18
votes
2 answers

OpenGL - How to access depth buffer values? - Or: gl_FragCoord.z vs. Rendering depth to texture

I want to access the depth buffer value at the currently processed pixel in a pixel shader. How can we achieve this goal? Basically, there seems to be two options: Render depth to texture. How can we do this and what is the tradeoff? Use the value…
0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
18
votes
1 answer

Ambient occlusion in threejs

I've just finished porting of my first cloth simulation from opengl to webgl using three.js (can be seen here). The thing is it looks a bit dull, and I want to add (as i hope i remember correctly from my computer graphics classes) ambient occlusion,…
mjanisz1
  • 1,478
  • 3
  • 17
  • 43
18
votes
1 answer

glUniform4fv is giving GL_INVALID_OPERATION

I' trying to develop a basic game in iOS and OpenGL ES but I'm stuck on this problem with the uniforms, here is the code that passes the value to my uniform: glBindVertexArrayOES(_vertexArray); // Render the object with…
Pupillam
  • 631
  • 6
  • 26
18
votes
1 answer

Pointers on modern OpenGL shadow cubemapping?

Background I am working on a 3D game using C++ and modern OpenGL (3.3). I am now working on the lighting and shadow rendering, and I've successfully implemented directional shadow mapping. After reading over the requirements for the game I have…
toficofi
  • 583
  • 6
  • 24
17
votes
4 answers

OpenGL ES 2.0 Shader best practices

I've been searching for examples of shaders in OpenGL and I've seen some varying styles. Some shaders specifically use the built in types (ie. gl_Vertex) to transfer data to and from the application code and the shader. Some shaders use the varying…
MarkP
  • 4,168
  • 10
  • 43
  • 84
17
votes
6 answers

What happens when you divide by 0 in a shader?

Branching is known to be particularly computationally expensive in a OpenGL ES shader. In such a shader, I check if a value is null before dividing by it, for example: if(value == 0.0) other_value = 0.0; else other_value = 1.0 / value; In…
Stéphane Péchard
  • 2,013
  • 3
  • 22
  • 35
17
votes
2 answers

What is the difference between a sample, a pixel and a fragment?

I still can't wrap my head around what differences are there between a sample/pixel/fragment. Since the fragment shader executes per pixel, I think a fragment just refers to a pixel, is this correct? Can anybody give me an example and definition of…
Jeff
  • 833
  • 1
  • 8
  • 17
17
votes
0 answers

Ray and ellipsoid intersection accuracy improvement

I need to enhance precision for function in one of mine Atmospheric scattering GLSL fragment shader which computes the intersection between single ray and axis aligned ellipsoid. This is the core function for mine atmospheric scattering shader. The…
Spektre
  • 49,595
  • 11
  • 110
  • 380
17
votes
3 answers

Are 1D Textures Supported in WebGL yet?

I've been trying to find a clear answer, but it seems no one has clearly asked the question. Can I use a 1D sampler and 1D texture in WebGL Chrome, Firefox, Safari, IE, etc? EDIT Understandably 1 is indeed a power of 2 (2^0=1) meaning you could…
Adrian Seeley
  • 2,262
  • 2
  • 29
  • 37
17
votes
4 answers

Direct3D Line thickness

How do I change the thickness of lines when drawing line lists using Direct3D? This post says that line width is not supported and goes on to provide a workaround. Other options? While we are on this topic, do shaders allow one to draw lines with…
Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
17
votes
3 answers

How do I calculate pixel shader depth to render a circle drawn on a point sprite as a sphere that will intersect with other objects?

I am writing a shader to render spheres on point sprites, by drawing shaded circles, and need to write a depth component as well as colour in order that spheres near each other will intersect correctly. I am using code similar to that written by…
David
  • 13,360
  • 7
  • 66
  • 130
17
votes
1 answer

openGL: lines with shaders

How would I create a line (possibly colored) with shaders? I'm using programmable pipeline and I'm a beginner with openGL. I can't find an example on how to draw lines with shaders.. I suppose I have to load a VAO (vertices array object) into the…
Johnny Pauling
  • 12,701
  • 18
  • 65
  • 108
16
votes
2 answers

what is the fwidth glsl function actually used for?

Every time I drunk browse so I see an unanswered fwidth question. And it makes me wonder what it actually was designed to do. Reading the docs it is: abs(dFdx(p)) + abs(dFdy(p)) So it is not classic mip selection which is max(dx,dy). Is it for…
starmole
  • 4,974
  • 1
  • 28
  • 48
16
votes
0 answers

Unity 3D HDRP - Making a hole in a gameobject by shader using stencil

Unity version 2019.1.2f1 HDRP project. I am trying to make a hole in a finished gameobject which has a material and shader don't want to interfere with, the point being this should work with any object it is done on. I found this approach somewhere…
Alx
  • 651
  • 1
  • 9
  • 26