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
228
votes
14 answers

Random / noise functions for GLSL

As the GPU driver vendors don't usually bother to implement noiseX in GLSL, I'm looking for a "graphics randomization swiss army knife" utility function set, preferably optimised to use within GPU shaders. I prefer GLSL, but code any language will…
Kos
  • 70,399
  • 25
  • 169
  • 233
208
votes
5 answers

What is state-of-the-art for text rendering in OpenGL as of version 4.1?

There are already a number of questions about text rendering in OpenGL, such as: How to do OpenGL live text-rendering for a GUI? But mostly what is discussed is rendering textured quads using the fixed-function pipeline. Surely shaders must make…
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
159
votes
5 answers

What is the correct file extension for GLSL shaders?

I'm learning glsl shading and I've come across different file formats. I've seen people giving their vertex and fragment shaders .vert and .frag extensions. But I've also seen .vsh and .fsh extensions, and even both shaders together in a single…
Samssonart
  • 3,443
  • 3
  • 31
  • 41
117
votes
5 answers

What's the origin of this GLSL rand() one-liner?

I've seen this pseudo-random number generator for use in shaders referred to here and there around the web: float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } It's variously called "canonical", or "a…
Grumdrig
  • 16,588
  • 14
  • 58
  • 69
109
votes
2 answers

Do conditional statements slow down shaders?

I want to know if "if-statements" inside shaders (vertex / fragment / pixel...) are really slowing down the shader performance. For example: Is it better to use this: vec3 output; output = input*enable + input2*(1-enable); instead of using…
Thomas
  • 2,093
  • 3
  • 21
  • 40
91
votes
6 answers

What are Vertex and Pixel shaders?

What are Vertex and Pixel shaders? What is the difference between them? Which one is the best?
Paulo
  • 7,123
  • 10
  • 37
  • 34
87
votes
3 answers

Explicit vs Automatic attribute location binding for OpenGL shaders

When setting up attribute locations for an OpenGL shader program, you are faced with two options: glBindAttribLocation() before linking to explicitly define an attribute location. or glGetAttribLocation() after linking to obtain an…
Jing
  • 1,881
  • 2
  • 15
  • 13
84
votes
2 answers

Creating a GLSL Arrays of Uniforms?

I would like to leave OpenGL's lights and make my own. I would like my shaders to allow for a variable number of lights. Can we declare an array of uniforms in GLSL shaders? If so, how would we set the values of those uniforms?
Miles
  • 1,858
  • 1
  • 21
  • 34
66
votes
3 answers

Getting the true z value from the depth buffer

Sampling from a depth buffer in a shader returns values between 0 and 1, as expected. Given the near- and far- clip planes of the camera, how do I calculate the true z value at this point, i.e. the distance from the camera?
Hannesh
  • 7,256
  • 7
  • 46
  • 80
57
votes
4 answers

In OpenGL is there a way to get a list of all uniforms & attribs used by a shader program?

I'd like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation() & glGetUniformLocation() can be used to map a string to a location, but what I would really like is the list of strings without having to…
hyperlogic
  • 7,525
  • 7
  • 39
  • 32
56
votes
1 answer

OpenGL ES 2.0 Multiple Programs or Multiple Shaders or what? How does it work?

The Problem (TL;DR) My problem, fundamentally, is that I do not know how OpenGL ES 2.0 expects me to write and use multiple shaders; or if it is even advisable/expected that a person will do so. The fundamental question here is: if I have an apple,…
Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73
52
votes
3 answers

What can cause glDrawArrays to generate a GL_INVALID_OPERATION error?

I've been attempting to write a two-pass GPU implementation of the Marching Cubes algorithm, similar to the one detailed in the first chapter of GPU Gems 3, using OpenGL and GLSL. However, the call to glDrawArrays in my first pass consistently fails…
Michael Powell
  • 853
  • 2
  • 9
  • 12
50
votes
5 answers

When transforming textures (drawn as flat 3D objects) to mimic depth, black lines appear randomly

We are developing a top-down RPG using XNA. Recently we bumped into a setback when writing the code to display our maps. When drawing the map, top-down view with a normal transformation matrix, everything seems to be fine. When using a non-flat…
Derk-Jan
  • 1,944
  • 16
  • 24
50
votes
2 answers

OpenGL bool uniform?

I'm trying to send a boolean to an OpenGL glsl shader. Currently I have this in the shader: uniform bool foo; And I use this to set it: glUniform1i(glGetUniformLocation(shader, "foo"), true); There doesn't seem to be a glUniform1b, so I'm setting…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
49
votes
4 answers

How to calculate Tangent and Binormal?

Talking about bump mapping, specular highlight and these kind of things in OpenGL Shading Language (GLSL) I have: An array of vertices (e.g. {0.2,0.5,0.1, 0.2,0.4,0.5, ...}) An array of normals (e.g. {0.0,0.0,1.0, 0.0,1.0,0.0, ...}) The position of…
user464230
  • 876
  • 2
  • 11
  • 21
1
2 3
99 100