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
23
votes
3 answers

Can you have multiple pixel (fragment) shaders in the same program?

I would like to have two pixel shaders; the first doing one thing, and then the next doing something else. Is this possible, or do I have to pack everything into the one shader?
Harry
  • 3,076
  • 4
  • 28
  • 44
23
votes
3 answers

Constant float values in GLSL shaders - any reason to use uniforms?

I'm looking at the source of an OpenGL application that uses shaders. One particular shader looks like this: uniform float someConstantValue; void main() { // Use someConstantValue } The uniform is set once from code and never changes…
kshahar
  • 10,423
  • 9
  • 49
  • 73
23
votes
1 answer

glGetAttribLocation returns -1 when retrieving existing shader attribute

I'm trying to pass in attributes to my vertex shader but for some reason it keeps giving me a -1 on the 3rd attribute location I'm asking openGl to retrieve via glGetAttribLocation(). Currently it keeps giving me a -1 for the texCoord attribute and…
Joey Dewd
  • 1,804
  • 3
  • 20
  • 43
22
votes
2 answers

What is the relationship between gl_Color and gl_FrontColor in both vertex and fragment shaders

I have pass-through vertex and fragment shaders. vertex shader void main(void) { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } fragment shader void main(void) { gl_FragColor =…
Thomas Vincent
  • 2,214
  • 4
  • 17
  • 25
22
votes
1 answer

Why did GLSL change varying to in/out?

I know how to use both in/out variables, and varying variables. I am fully aware that using the in/out variables is better because it is not deprecated. It is a very small thing, but I don't really understand why they changed this. Previously I…
nedb
  • 586
  • 1
  • 4
  • 12
22
votes
1 answer

How to pass uniform array of struct to shader via C++ code

for eg. in FragmentShader:- struct LightSource { int Type; vec3 Position; vec3 Attenuation; vec3 Direction; vec3 Color; }; uniform LightSource Light[4]; main(){ //somecode } Now how can i send…
jpm
  • 1,042
  • 2
  • 12
  • 36
21
votes
2 answers

draw the depth value in opengl using shaders

I want to draw the depth buffer in the fragment shader, I do this: Vertex shader: varying vec4 position_; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; position_ = gl_ModelViewProjectionMatrix * gl_Vertex; Fragment shader: float depth =…
hidayat
  • 9,493
  • 13
  • 51
  • 66
20
votes
5 answers

Why do people use sqrt(dot(distanceVector, distanceVector)) over OpenGL's distance function?

When using ShaderToy I often see people using something like: vec2 uv = fragCoord / iResolution; vec2 centerPoint = vec2(0.5); vec2 distanceVector = uv - centerPoint; float dist = sqrt(dot(distanceVector, distanceVector)); over OpenGL's distance…
bradleygriffith
  • 948
  • 3
  • 11
  • 24
20
votes
1 answer

Get results of GPU calculations back to the CPU program in OpenGL

Is there a way to get results from a shader running on a GPU back to the program running on the CPU? I want to generate a polygon mesh from simple voxel data based on a computational costly algorithm on the GPU but I need the result on the CPU for…
danijar
  • 32,406
  • 45
  • 166
  • 297
20
votes
6 answers

Speed of cos() and sin() function in GLSL shaders?

I'm interested in information about the speed of sin() and cos() in Open GL Shader Language. The GLSL Specification Document indicates that: The built-in functions basically fall into three categories: ... ... They represent an operation graphics…
ulmangt
  • 5,343
  • 3
  • 23
  • 36
19
votes
2 answers

WebGL and HTML shader-type

I declare my GLSL ES shader program within a HTML file, using this code: as seen in the learning WebGL examples. Everything works fine, but I dont understand why I should…
Luca Hofmann
  • 1,442
  • 2
  • 14
  • 26
19
votes
9 answers

Beginning Shader Development

I want to get started doing some game development using Microsoft's XNA. Part of that is Shader development, but I have no idea how to get started. I know that nVidia's FX Composer is a great tool to develop shaders, but I did not find much useful…
Michael Stum
  • 177,530
  • 117
  • 400
  • 535
19
votes
1 answer

Using different push-constants in different shader stages

I have a vertex shader with a push-constant block containing one float: layout(push_constant) uniform pushConstants { float test1; } u_pushConstants; And a fragment shader with another push-constant block with a different float…
Silverlan
  • 2,783
  • 3
  • 31
  • 66
19
votes
1 answer

Shader position vec4 or vec3

I have read some tutorials about GLSL. In certain position attribute is a vec4 in some vec3. I know that the matrix operations need a vec4, but is it worth to send an additional element? Isn't it better to send vec3 and later cast in the shader…
Skides
  • 295
  • 1
  • 5
  • 14
19
votes
1 answer

GLKTexture is not correctly mapped since iOS6

I got a strange behavior since Xcode 4.5 and the iOS 6 SDK when using textures on my 3D objects. The problem also appears on my mac application when building against OS X 10.8 SDK. I am using OpenGL ES 2.0 on iOS and OpenGL legacy profile ( < 3.0 )…
SMP
  • 586
  • 3
  • 12