Questions tagged [glsl]

A programming language for OpenGL shaders.

GLSL is a programming language for OpenGL shaders.

Information about GLSL and OpenGL can be found at http://www.khronos.org/opengl/

952 questions
29
votes
3 answers

Does == cause branching in GLSL?

Trying to figure out exactly what causes branching and what doesn't in GLSL. I'm doing this a lot in my shader: float(a==b) I use it to simulate if statements, without conditional branching... but is it effective? I don't have if statements…
14
votes
1 answer

GLSL - Declaring global variables outside of the main function scope

Does it help to declare variables outside of your main function scope in GLSL? Do these variables actually get reused and is it more efficient? Here is the code in question: varying vec2 vposition; uniform float seed; uniform float top; uniform…
RodgerDodger
  • 353
  • 1
  • 2
  • 9
12
votes
1 answer

GLSL: #define vs const

What is the difference between #define NAME VALUE and const int NAME = VALUE in GLSL 410 core? As far as I can see, they both create a constant integer.
Lucien
  • 1,176
  • 2
  • 10
  • 36
10
votes
2 answers

Sharing functions across multiple shaders

Simple question: In GLSL, is there a way to share functions across multiple shaders, or do I have to define all functions in every shader that needs them?
TravisG
  • 4,402
  • 4
  • 36
  • 59
8
votes
3 answers

How to improve this shader's performance?

I have a scene with 150000 instances. I use glsl and opengl 4.0. Shader A is 2 times slower than shader B. I.e. with shader A I get 20fps, with shader B I get 40fps on average. What can I do to improve shader A? Shader A: #version 400 struct Light…
user68854
  • 197
  • 2
  • 8
4
votes
2 answers

GLSL Atmospheric Scattering Issue

I am attempting to use Sean O'Neil's shaders to accomplish atmospheric scattering. For now I am just using SkyFromSpace and GroundFromSpace. The atmosphere works fine but the planet itself is just a giant dark sphere with a white blotch that follows…
mtf1200
  • 43
  • 1
  • 4
3
votes
1 answer

How can I repeat / scroll a tile which is part of an texture atlas?

I would like to scroll a tile which is part of a texture atlas like it can be done with a single quad and texture wrap mode set to repeat. Can this be done? I hope it's clear what I would like to achieve. Here is my shader code which I use to sample…
3
votes
2 answers

Passing multiple Vertex Attributes in GLSL 130

(note this question is closely related to this one however I didn't fully understand the accepted answer) To support videocards in laptops I have to rewrite my GLSL 330 shaders to GLSL 130. I'm trying to do this but somehow I don't get vertex…
Roy T.
  • 10,208
  • 34
  • 56
3
votes
1 answer

GLSL error on AMD gpu. No error on nVidia

I have an OpenGL program that works fine on nVidia card, but produces Access violation error and GL_INVALID_OPERATION at glDrawElements on AMD gpu. For starters I have this geometry shader which now won't compile. #version 330 // Input is…
mkanakis
  • 220
  • 1
  • 8
2
votes
3 answers

Passing POD arrays to shader?

How do I pass to my vertex shader an array of N elements? From what I see I can only pass float arrays of 3|4 elements, vectors 2|3d and matrices, but I want to pass a POD array and use it like this: void ShaderFunction(float* array,int count) { …
user1010005
  • 373
  • 1
  • 5
  • 11
2
votes
1 answer

Learning GLSL: What's a good intermediate project to work on?

I know the basics of OpenGL and I'm starting to love computer graphics more and more. I have a computer science background and have been programming for 5 years. I've been reading the orange book and kind of want to figure out a project that can…
Joey Green
  • 2,509
  • 4
  • 26
  • 46
2
votes
1 answer

GLSL Lighting with attenuation; how to add a fade-out color?

I am using the GLSL shader from this link, slightly modified and i got it working. The shader code is the following: VS: vPosition = uMVMatrix * vec4(aVertexPosition, 1.0); vTransformedNormal = uNMatrix * aVertexNormal; …
vlzvl
  • 163
  • 7
2
votes
1 answer

What is the difference between a mat3 and a float[9], in terms of size?

In my GLSL Compute Shader, I've declared a struct called ParticleData, and when I read in part of my buffer as a mat3, the size (which I assess by looking at the output) is different than if I use a float[9]. I haven't been able to find a definitive…
Matt
  • 165
  • 7
1
vote
2 answers

GLSL: define a constant for both vertex and fragment shader

I have a constant for defining an array in the vertex shader. I want to use this constant also in the fragment shader to define another array of the same size. Naive attempts fail (simply use the constant of the vertex shader in the fragment shader…
bobbel
  • 247
  • 2
  • 7
1
vote
0 answers

How to setup my texture cordinates correctly in GLSL 150 and OpenGL 3.3?

I'm trying to do texture mapping in GLSL 150 and OpenGL 3.3 Here are my shaders I've tried my best to get this correct as possible hopefully this is :) I'm guessing you want to know what the problem is well my texture shows but not in its fullest…
RubyKing
  • 79
  • 2
  • 4
1
2