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
49
votes
2 answers

Why does my OpenGL Phong shader behave like a flat shader?

I've been learning OpenGL for the past couple of weeks and I've run into some trouble implementing a Phong shader. It appears to do no interpolation between vertexes despite my use of the smooth qualifier. Am I missing something here? To give credit…
Jonba
  • 1,117
  • 2
  • 11
  • 12
47
votes
5 answers

Efficiency of branching in shaders

I understand that this question may seem somewhat ungrounded, but if someone knows anything theoretical / has practical experience on this topic, it would be great if you share it. I am attempting to optimize one of my old shaders, which uses a lot…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
43
votes
2 answers

How to get a "Glow" shader effect in OpenGL ES 2.0?

I'm writing a 3D app for iOS. I'm new to OpenGL ES 2.0, so I'm still getting myself around writing basic shaders. I really need to implement a "Glow" effect on some of my models, based on the texturing. Here's a sample: . I'm looking for code…
st4wik
  • 476
  • 1
  • 4
  • 5
41
votes
3 answers

GLSL multiple shaderprogram VS uniforms switches

I'm working on a shader manager architecture and I have several questions for more advanced people. My current choice oppose two designs which are: 1. Per material shader program => Create one shader program per material used in the…
Profet
  • 944
  • 1
  • 15
  • 22
40
votes
11 answers

OpenGL 4.x learning resources

I know there are some question about learning OpenGL. Here is what I know: math for 3D 3D theory Here is what I want to know: - OpenGL 4.0 Core profile (or latter) - Shader Language 400 (or latter) - every part of above (if it do not work…
przemo_li
  • 3,932
  • 4
  • 35
  • 60
39
votes
6 answers

Learning modern OpenGL

I am aware that there were similar questions in past few years, but after doing some researches I still can't decide where from and what should I learn. I would also like to see your current, actual view on modern OpenGL programming with more C++…
Neomex
  • 1,650
  • 6
  • 24
  • 38
38
votes
7 answers

How do I get the current color of a fragment?

I'm trying to wrap my head around shaders in GLSL, and I've found some useful resources and tutorials, but I keep running into a wall for something that ought to be fundamental and trivial: how does my fragment shader retrieve the color of the…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
36
votes
3 answers

Organizing GLSL shaders in OpenGL engine

Which is better ? To have one shader program with a lot of uniforms specifying lights to use, or mappings to do (e.g. I need one mesh to be parallax mapped, and another one parallax/specular mapped). I'd make a cached list of uniforms for lazy…
Pythagoras of Samos
  • 3,051
  • 5
  • 29
  • 51
35
votes
1 answer

How do Shadertoy's audio shaders work?

To start off, I couldn't really find any appropriate community to post this question in so I picked this one. I was wondering how the audio shaders of the popular webGL based shader tool worked, because when, even though I had obviously heard of…
tbvanderwoude
  • 587
  • 6
  • 17
34
votes
2 answers

Why not vec3 for OpenGL ES 2.0 gl_Position?

I am new to OpenGL ES 2.0, and cannot understand the following simplest shader: attribute vec4 vPosition; void main() { gl_Position = vPosition; } My question is, since a position would be a vector of (x, y, z), why is gl_Position a vec4 instead…
peter
  • 1,034
  • 1
  • 9
  • 23
34
votes
1 answer

Custom Texture Shader in Three.js

I'm just looking to create a very simple Fragment Shader that draws a specified texture to the mesh. I've looked at a handful of custom fragment shaders that accomplished the same and built my own shaders and supporting JS code around it. However,…
rrowland
  • 2,734
  • 2
  • 17
  • 32
32
votes
4 answers

Shader optimization: Is a ternary operator equivalent to branching?

I'm working on a vertex shader in which I want to conditionally drop some vertices: float visible = texture(VisibleTexture, index).x; if (visible > threshold) gl_Vertex.z = 9999; // send out of frustum I know that branches kill performance when…
sharoz
  • 6,157
  • 7
  • 31
  • 57
32
votes
3 answers

What are shaders in OpenGL and what do we need them for?

When I'm trying to get through openGL wiki and tutorials on www.learnopengl.com, it never ends up understandable by intuition how whole concept works. Can someone maybe explain me in more abstract way how it works? What are vertex shader and…
Tommz
  • 3,393
  • 7
  • 32
  • 44
29
votes
5 answers

Is discard bad for program performance in OpenGL?

I was reading this article, and the author writes: Here's how to write high-performance applications on every platform in two easy steps: [...] Follow best practices. In the case of Android and OpenGL, this includes things like "batch draw calls",…
Jave
  • 31,598
  • 14
  • 77
  • 90
28
votes
2 answers

What are the advantage of using indirect rendering in OpenGL?

I read that the APIs like glDrawElementsIndirect, glDrawArraysIndirect help us in indirect rendering. Indirect rendering is different from direct in the way that the rendering parameters like "number of vertex attributes", "number of instances to…
viktorzeid
  • 1,521
  • 1
  • 22
  • 35