glsl

How to calculate gl_FragCoord in glsl

Ok, in my glsl fragment shader I want to be able to calculate the distance of the fragment from a particular line in space. The result of this is that I am first trying to use a varying vec2 set in my vertex shader to mirror what ends up in gl_FragCoord: varying vec2 fake_frag_coord; //in vertex shader: gl_Position = gl_ModelViewProjec...

Calculating 3D tangent space

In order to use normal mapping in GLSL shaders, you need to know the normal, tangent and bitangent vectors of each vertex. RenderMonkey makes this easy by providing it's own predefined variables (rm_tangent and rm_binormal) for this. I am trying to add this functionality to my own 3d engine. Apparently it is possible to calculate the tan...

How does opengl decide which mip level to use?

The question is fairly self explanatory. I'm asking in terms of using texture coordinates that could have come from anywhere (a uniform, a varying, another texture fetch). Say for example I do a texture fetch on a mipmapped (or anisotropically filtered) texture, and I use the square of a varying which was set in the vertex shader. I ass...

How do you handle multiple textures in an OpenGL indexed buffer array for use with a data-shader?

I'm attempting to implement this paper. I've have most of it down, but the part about sending arbitrary, non-geometric data to the shader for use in determining and displaying geometric edges is causing me problems. I've managed to successfully send most of my data just fine using what I know of VBOs. However, I need to send a large amou...

HTML 5 filter language or some analog of filter language?

Is there in HTML 5 filtering language or some analog of filter language? Something like GLSL / HYDRA / HLSL or just JS pixel filter/shader lib? ...

How do I pre preform bit operations in glsl.

How do I pre preform bit operations in glsl? Using the regular C style bitwise operators |, &, ^, or ! do not work. ...

Fragment shaders: output variables

Reading the GLSL 1.40 specification: Fragment outputs can only be float, floating-point vectors, signed or unsigned integers or integer vectors, or arrays of any these. Matrices and structures cannot be output. Fragment outputs are declared as in the following examples: out vec4 FragmentColor; out uint Luminosity; ...

how to render multiple textures with GLSL

hello, i am about to port all my rendering from "old" opengl to glsl. now i have a mesh with different textures, so in "old" gl i just used bindTexture to change the texture. i guess, i still need to do this, but something is missing, since my everything seems to be rendered with the first texture only. uniform sampler2D tex; void mai...

Shader limitations

I've been tuning my game's renderer for my laptop, which has a Radeon HD 3850. This chip has a decent amount of processing power, but rather limited memory bandwidth, so I've been trying to move more shader work into fewer passes. Previously, I was using a simple multipass model: Bind and clear FP16 blend buffer (with depth buf...

How to change a GLSL shader parameter in Processing

I'm playing with shaders in openGL using Processing. I'm pretty noob at this and a bit lost. I found this thread that has an example on how to use GLSL shaders in Processing. I'm just trying to the change LightPosition parameter in the shader I'm using. I don't know how to access it though. Here's my code so far: import processing.o...

How to transform directional light to camera space in GLSL

I have the following GLSL code for lighting: uniform vec3 lightDir; // Parallel light uniform float ambient; uniform vec3 lightColour; void main() { gl_Position = ftransform(); vec3 eyeNormal = normalize(gl_NormalMatrix * gl_Normal); float intensity = max(ambient, dot(eyeNormal, normalize(-lightDir)); gl_FrontColo...

Shaders with pygtkglext

Do someone know how to get glsl shaders work in gtk-opengl window? With glut all glCreateProgram etc. functions works, but when I tried to put the same gl code into pygtkglext window, its complaining about NullReference: OpenGL.error.NullFunctionError: Attempt to call an undefined function glCreateProgram, check for bool(glCreateProgram...

What is required to compile and run GLSL programs?

I'm trying to run a GLSL example, but I can't. The error is in the line glGetShaderiv(vShader, GL_COMPILE_STATUS, &status); where the program exits. vShader is the file vPhong.glsl. The error returned is: 0(18) : error C0000: syntax error, unexpected $undefined at token "<undefined>" 0(18) : error C0501: type name expected at token "<...

Unable to link compiled shaders (GLSL)

I have a small class that allows me to load shaders and use them in my program. I am able to compile the shaders, but when it's time to link them, they just don't want to. Using glGetProgramInfoLog I got the following error log. I don't understand why it tells me that there are no program defined since the compilation worked fine... Ver...

Reading 32-bit RGBA float values in GLSL

I'm trying send some 32 bit float data to a shader, but the results are erratic. If I test with full white (1,1,1,1) the values are all zero. This is my code for creating the texture: gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA32F_ARB, 512, 512, 0, GL.GL_RGBA, GL.GL_FLOAT, data); and reading from it in GLSL: uniform sampler2D u_t...

GLSL shader generation of normals

Hi I am writing 3D modeling app and I want to speed up rendering in OpenGL. Currently I use glBegin/glEnd which is really slow and deprecated way. I need to draw very fast flat shaded models. I generate normals on CPU every single frame. This is very slow. I tried to use glDrawElements with indexed geometry, but there is problem in norma...

Cocoa and OpenGL, How do I set a GLSL vertex attribute using an array?

I'm fairly new to OpenGL, and I seem to be experiencing some difficulties. I've written a simple shader in GLSL, that is supposed to transform vertices by given joint matrices, allowing simple skeletal animation. Each vertex has a maximum of two bone influences (stored as the x and y components of a Vec2), indices and corresponding weigh...

Why can't I run my OpenGL program outside of Visual Studio?

I have an OpenGL-program using GLSL, that I can run just fine with the Play-button in Visual Studio (2008) -- both in the standard Release and Debug configurations. However, when I try to run the executable from Explorer, all I get is a flashing cmd-prompt with no text in it to indicate any kind of failure loading something. I have tri...

Ogre material scripts; how do I give a technique multiple lod_indexes?

I have an Ogre material script that defines 4 rendering techniques. 1 using GLSL shaders, then 3 others that just use textures of different resolutions. I want to use the GLSL shader unconditionally if the graphics card supports it, and the other 3 textures depending on camera distance. At the moment my script is; material foo { lod_...

How to transform back-facing vertices in GLSL when creating a shadow volume

I'm writing a game using OpenGL and I am trying to implement shadow volumes. I want to construct the shadow volume of a model on the GPU via a vertex shader. To that end, I represent the model with a VBO where: Vertices are duplicated such that each triangle has its own unique three vertices Each vertex has the normal of its triangle...