FAQ Database Discussion Community


Why do we compile shaders at runtime in OpenGL 2?

android,opengl-es,glsl,shader
I have been trying to learn OpenGL, specifically for Android. I have seen various tutorials online, and I noticed that many of the tutorials for OpenGL 1.0, or 1.2 do not require compilation of shader programs, while the only tutorials I could find for OpenGL 2.0 all involve creating a...

Setting vectors in shaders, How does it work? OpenGL GLSL

android,opengl-es,glsl,opengl-es-2.0,glsles
I am trying to understand how vertex and fragment shaders work in OpenGL ES 2.0. My shaders look like this: vertex shader: // source code for the vertex shader attribute vec4 vPosition attribute vec2 a_texCoord; varying vec2 v_texCoord; void main() { gl_Position = vPosition; v_texCoord = a_texCoord; } fragment shader:...

How can I render an infinite 2D grid in GLSL?

opengl,glsl
Ideally, what I'd like to do is draw a single quad and have GLSL handle the creation of the actual gridlines. In my attempt so far the vertex shader: #version 400 layout (location = 0) in vec4 in_position; layout (location = 2) in vec3 in_UV; uniform mat4 model; uniform mat4...

Applying perspective with GLSL matrix

opengl,matrix,glsl,frustum
I am not quite sure what is missing, but I loaded a uniform matrix into a vertex shader and when the matrix was: GLfloat translation[4][4] = { {1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.2, 0.0, 1.0}}; or so, I seemed to be able...

Overlaying a transparent color over a Texture with GLSL

glsl,lwjgl,slick2d,vertex-shader,blending
I have an image that I am loading using the Slick library, and the image renders fine without my shader active. When I use my shader to overlay a transparent color over the image the entire image is replaced by the transparent color. without the shader With the shader Vertex...

Bloom effect using downscaling (downsampling) technique using OpenGL/GLSL

opengl,glsl,shader
Hello I'm trying to implement Bloom effect in my program. In fact, I've already implemented the effect using a highlight pass and a separate gaussian blur pass. Here's an example: Bright pass texture: Gaussian blur render pass (2 internal passes for this effect): And finally the final pass (brightPass +...

Passing grayscale OpenCV image to an OpenGL texture

c++,opencv,opengl,glsl
I want to use a grayscale image generated in OpenCV in a GLSL shader. Based on the question on OpenCV image loading for OpenGL Texture, I've managed to come up with the code that passes RGB image to the shader: cv::Mat image; // ...acquire and process image somehow... //create and...

OpenGL deferred rendering: point light implementation

c#,opengl,glsl,opentk,deferred-rendering
I'm trying to write a deferred renderer using C# and OpenGL (with OpenTK). But don't understand how should I implement the normal calculation for a point light. The point light fragment shader: vec2 texCoord = gl_FragCoord.xy / ScreenSize; vec3 pixelPos = texture2D(PositionBuffer,texCoord).xyz; vec3 pixelNormal = normalize(texture2D(NormalBuffer, texCoord).xyz); vec3 diffuseColor =...

Deferred Shading - Multiple Lights (OpenGL/GLSL)

opengl,glsl,light,deferred-rendering,deferred-shading
I'm working on a deferred shading program and now I have to set up 50 different lights in the scene. To do so, I'm randomly generating its attributes (position, diffuse color, specular color) with this piece of code: void FBORender::BuildLights() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> dis(0.0, 0.1); for (int...

WebGL Normal calculations from position texture

glsl,webgl,normals,render-to-texture
Iam trying to create a procedural water puddle in webGL with "water ripples" by vertex displacement. The problem I'm having is that I get a noise I can't explain. Below is the first pass vertex shader where I calculate the vertex positions that i later render to a texture that...

OpenGL GLSL: How to implement the concept of gradient map in photoshop using fragment shader?

image-processing,glsl,photoshop
This may be not the perfect question for stackoverflow but I have asked this in graphicdesign network of stackexchange but did not get any answer so posting it here. I am trying to implement gradient map of Photoshop programmatically using glsl fragment shader. Consider below shown gradient map where all...

GLSL works weirdly for creating depth G-Buffer

glsl,shader,depth
Following pictures is geometry rendering result. Jesus! I have no enough reputation. Then i can't attach my picture. I describe the geometry, instead attach my picture. geometry is flat rectangle. Then following code is glsl source for creating depth g-buffer. --- Vertex Shader --- varying float uv_depth; void main (void)...

GLSL 400 samplerCube binding

opengl,glsl
My partner and I are working on an OpenGL project that includes a skybox. The skybox works fine on his computer (which has GLSL version 4.5) and everything BUT the skybox works on mine (GLSL 4.0). The compiler complains about a syntax error in this line: layout(binding=0) uniform samplerCube currTexture;...

OpenGL: Defining variables in shaders

opengl,glsl
My OpenGL program, using GLSL for shaders, has a simple vertex and fragment shader (given by a tutorial). The vertex shader is: #version 330 layout (location = 0) in vec3 Position; void main() { gl_Position = vec4(0.5 * Position.x, 0.5 * Position.y, Position.z, 1.0); } And the fragment shader is:...

Hide faces with GLSL shader

opengl-es,three.js,glsl,webgl
I'm trying to wright a shader to work with three.js. Which is a javascript library for WebGL. I just started reading up on GLSL so there are some thing i'm having trouble with. Basically I want reveal and hide faces of a geometry. I have cloned my geometry's face array...

Sampler3D in iOS

ios,opengl-es,glsl,opengl-es-3.0
I have just include OpenGL ES 3.0 in my iOS app and it is working fine. I have a working shader below: #version 300 es precision mediump float; uniform sampler2D texSampler; uniform float fExposure; in vec2 fTexCoord; in vec3 fColor; out vec4 fragmentColor; void main() { fragmentColor = texture(texSampler, fTexCoord)...

Solved - GLES2.0+ framebuffer fade artifacts

android,opengl-es,glsl,framebuffer
I'm writing a simple test program on android using GLES 2.0 or 3.0. (If the solution only works on one over the other, than that's what I'll go with.) Problem: Basically I am running into strange pixel artifacts when fading colors. The problem can be "hidden" by making the cutoff...

can I send an array of data as a vertex attribute?

three.js,glsl,webgl,shader
I have a PointCloud in which I am using to visualize some time-related data points. For each vertex in the PointCloud.Geometry, I'd like to assign an attribute which is an array of epoch times. These epoch times are ints, an example would be: epochTimes = [1432314839, 1432314840, 1432314841]; the custom...

OpenGL texture not rendering through GLSL

c++,opengl,textures,glsl
so i have a very simple glsl shader that renders an object with texture and directional light. now I'm having a really tough time trying to get the texture to display, everything else works except for that. when i disable the shader( glUseProgram(0) ) the texture renders in black and...

Water rendering in opengl [duplicate]

opengl,glsl,shader
This question already has an answer here: How to render ocean wave using opengl in 3D? [closed] 2 answers I have absolutely no idea how to render water sources (ocean, lake, etc). It's like every tutorial I come across assumes I have the basic knowledge in this subject, and...

GLSL shading: The entire screen is colored instead of just a quad

c++,opengl,glsl,fragment-shader,vertex-shader
The shaders I've done shades the entire screen in red instead of shading only the quad I'm drawing. The way I've done things in my code is described here. #version 140 core // vertex shader in vec3 position; out vec3 color; void main(void) { gl_Position = vec4(position,1.0); color = vec3(1.0,0.0,0.0);...

C++ equivalent to this GLSL functions

c++,glsl
Can somebody tell me what's the Cpp equivalent of this two GLSL functions is ? (Component wise solution prefered). vec4 pack( float v ) { vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v; enc = fract(enc); enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0); return enc; } float unpack( vec4 rgba )...

How do I properly declare a uniform array of structs in GLSL so that I can point a UBO at it?

opengl,glsl
The following glsl code appears in my fragment shader. The struct definition causes no problems, but my attempt to use it as the type of a uniform array causes an "invalid operation" error, which is not particularly helpful. struct InstanceData { vec3 rotation; vec3 scale; mat4 position; }; layout (std140)...

is early exit of loops on GPU worth doing?

opengl-es,glsl,webgl,shader,gpu
We've written GLSL shader code to do ray tracing visualisation using the GPU. It seems to be pretty standard to put an early exit break in the ray marching loop, so if the light is extinguished, the loop breaks. But from what I know about GPU code, each render will...

Opengl not drawing correctly using shader - issue with matrix setup/initialization?

opengl,matrix,glsl
When I render my app, I'm expecting to see a number of rectangles surrounding the edges of the window. Instead I'm seeing this .. All objects will be at z == 0.0f. If I dont render my scene using shaders, all objects show fine. So thinking it must be matrix...

Issues refactoring GLES30 shader?

opengl-es,textures,glsl,shader,hlsl
I'm currently rewriting a shader written in GLES30 for the GLES20 shader language. I've hit a snag where the shader I need to convert makes a call to the function textureLod, which samples the currently bound texture using a specific level-of-detail. This call is made within the fragment shader, which...

Porting Directional Light from OpenGL to DirectX11

opengl,directx,glsl,hlsl
I am porting my GLSL Directional Light Shader from OpenGL to DirectX11. My LightDirection is (1,0,0) (from left to right in the pictures) The Shader in GLSL looks like this: #version 330 core uniform sampler2D DiffuseMap; uniform sampler2D NormalMap; uniform sampler2D PositionMap; uniform sampler2D DepthMap; uniform vec3 LightDirection; uniform vec3...

GLSL can't compile a shader without interpolation (flat)

c++,glsl,fragment-shader,vertex-shader
I'm drawing a complete object with mutiple meshes from a single vertex/index buffer, and they have different textures. Thus, I thought of passing ID of texture along with the vertices from vertex shader to fragments in the fragment shader. The problem is disabling the interpolation. I'm using GLSL ver 3.3...

Tessellation shader drawing issues

glsl,shader,tessellation
I am currently trying to add tessellation shaders to my program and I feel as though I'm at my wit's end. I have gone through several tutorials and delved into a lot of the questions here as well. Unfortunately I still do not understand what I am doing wrong after...

Is there an accurate approximation of the acos() function?

opengl,glsl,shader,trigonometry,double-precision
I need an acos() function with double precision within a compute shader. Since there is no built-in function of acos() in GLSL with double precision, I tried to implement my own. At first, I implemented a Taylor series like the equation from Wiki - Taylor series with precalculated faculty values....

Implementing Normal Mapping using OpenGL/GLSL

opengl,glsl,fragment-shader,vertex-shader
I'm learning GLSL and trying to implement some lighting and mapping tricks. I'm working with ShaderDesigner tool. After coding normal mapping I recognized that my model illumination looks not real. Here is my code and some pictures. If it possible tell me what is my problem. Vertex Shader #define MAX_LIGHTS...

Why can't I add an int member to my GLSL shader input/output block?

opengl,glsl
I'm getting an "invalid operation" error when attempting to call glUseProgram against the fragment shader below. The error only occurs when I try to add an int member to the block definition. Note that I am keeping the block definition the same in both the vertex and fragment shaders. I...

Simple GLSL Shader (Light) causes flickering

opengl,glsl,shader,lighting
I'm trying to implement some basic lighting and shading following the tutorial over here and here. Everything is more or less working but I get some kind of strange flickering on object surfaces due to the shading. I have two images attached to show you guys how this problem looks....

HDR Bloom effect rendering pipeline using OpenGL/GLSL

opengl,glsl,shader
I have integrated bloom HDR rendering using OpenGL and GLSL... At least I think! I'm not really sure about the result. I followed a tutorial from intel website: https://software.intel.com/en-us/articles/compute-shader-hdr-and-bloom And about Gaussian blur effect I follow scrupulously all the advices concerning the performance on the following website: https://software.intel.com/en-us/blogs/2014/07/15/an-investigation-of-fast-real-time-gpu-based-image-blur-algorithms According to...

Error using glMultiDrawArraysIndirect and indirect buffer

opengl,glsl,jogl
I have two objects (A and B) to be rendered using glMultiDrawArraysIndirect(). Each object has a setupBuffers() method for creating, binding a vao, then creating and binding the indirect buffer, instanced ID buffer, vertices buffer and texture coords buffer. (using JOGL) Here is the problem: if I call setupBuffers() of...

How to access all vertexes within the same patch in Tessellation Control Shader

opengl,glsl,tessellation
I want to do LOD in Tessenllation Control Shader. And my method is to calculate the area each patch occupyed on screen coordinate, and set different tessellation level for them. So I need to access all vertices within a patch and I do so like: for(int i = 0; i...

glGetProgramiv returns a lower number of active uniforms, why?

java,android,glsl,opengl-es-2.0,uniform
I'm doing a game framework for Android with opengl es 2.0 and glsl in java. I did a method that automatically loads all the active uniform in the GL program to a java map with their locators. The problem I found is that the line GLES20.glGetProgramiv( this.m_GL_Program_ID, GLES20.GL_ACTIVE_UNIFORMS, total, 0);...

GLSL Error #132 Syntax error: “gl_position” parse error

java,opengl,glsl
I've tried my best to find the answer to this problem or any error i had made in the code, but i just couldn't find anything.. If this helps, i have a sapphire Radeon HD 6950 graphics card and it uses an AMD Radeon HD 6900 series driver. The Error...

Why is there a light area between edges when rendering an inner shadow by calculating the nearest distance to an edge?

opengl-es,glsl,opengl-es-2.0,glsles
I'm rendering an inner shadow (same idea as an inner glow, but dark instead of light) by calculating the nearest distance to an edge for each pixel. This is done in the fragment shader by interpolating the vertex position from the vertex shader (using varying), passing the shape's edge points...

webgl lighting shader working with firefox but not with chrome

google-chrome,firefox,glsl,webgl,shader
I am currently developing a 3D engine using WebGL, and I encountered a problem with the lighting shader. I am using an array of structure in order to pass the light parameters to the vertex and fragment shaders (with the same array passed as "uniform"). It actualy works very well...

GLSL - program link error: Slot 0 unavailable from layout location request

c++,opengl,glsl
I'm trying to draw a textured quad copying some code from a tutorial but I'm afraid there is a problem with the shaders. Both the vertex shader and the fragment shader compilation works, but when linking the program I get the error: ERROR: Active attribute aliasing. Slot 0 unavailable for...

Applying glow effect to a square using glsl without texture

opengl,glsl,glow
I've taken some same code from Android OpenGL tutorials, and I'm wondering is it possible to achieve the glowing effect seen here: http://glslsandbox.com/e#25224.0 using the Square implementation below? i.e without using textures? I'd like to apply this glowing effect to the entire Square i.e fill The link above uses a...

GLSL offsetting multitexture

opengl,glsl,shader,vertex-shader
How can I do something like this in GLSL shaders? vec2 attribute texture_sky; vec2 attribute texture_floor; if(texture_sky) gl_position = position+Xoffset; else gl_position = position; I want to move one texture over the other. Is it possible to do with the vertex shaders?...

Attribute Variable not found in OpenGL, possible optimization

opengl,optimization,glsl,shader
I'm currently working in a deferred shading and I created a class which manages the FBOs and draw the buffers on the screen. This is how it looks so far: FBORender::FBORender(float screenWidth, float screenHeight) : _screenWidth(screenWidth), _screenHeight(screenHeight), ProgramManager("defVertexShader.txt", "defFragShader.txt") { CreateProgram(); _vbo[0] = 0; _vbo[1] = 0; _vao = 0;...

Modern GLSL ( opengl 3+ ) : Implementing phong effect correctly;

glsl,opengl-3
I am implementing a basic phong lighting GLSL shader; I have looked up some things on the internet, and found that the phong effect was created by adding an ambient, diffuse, and specular layer on the object (see image below, from tom dalling's site); problem is I have seen a...

How the gl_TessCoord is computed during the tessellation?

opengl,glsl,jogl
Currently I am learning the tessellation shader of OpenGL. But when it comes to the built in variable "gl_TessCoord" in the tessellation evaluation shader, I can't understand how it is calculated. I know that the "gl_TessCoord" is different when different tessellation mode is used (quads or triangles). And I checked...

Efficient way to generate normal map (from height) for all 360 degrees of a rotated image

opengl,glsl,shader,hlsl,normals
I already have a shader that generates a normal map from a height map. Now I need to apply the effect to all 360 degrees of the rotated heightmap. Of coarse I could just apply the effect 360 times to each heighmap, but if I have already done it once...

GLSL - compressing/packing multiple 0-1 colours (var4) into a single var4 variable

compression,glsl,bit-shift,glsles,bit-packing
I am trying to do the following in GLSL 2 es: Given a number (say 4 for example) of normalized var4 variables(RGBA) reduce their bit depth and pack the results in a single 0-1 clamped var4. This will be stored as an 8 bit (per channel) texture and later unpacked....

Simplify code by finding a way to remove many if statements

javascript,c++,c,glsl,webgl
I'm having trouble figuring out a good way to structure my code. I am writing a shader in GLSL. I'm using WebGL. So I have a sprite sheet with 22 items. The sheet is 640 X 640. Except for the last each row has 5 sprites. So I used the...

Pass data from std::vector to uniform array in glsl

c++,opengl,glsl,glm
I have a uniform in a shader like this: uniform vec3 origins[10]; and a std::vector in my code like this: std::vector<glm::vec3> origins; that is filled with ten glm::vec3 elements. Does anyone know how do I pass that to the shader? I thought: GLint originsLoc = glGetUniformLocation(programID, "origins"); glUniform3fv(originsLoc, 10, origins.data());...

Opengl error 1281 when trying to glUseProgram

opengl,glsl
Any ideas how I could debug this opengl error further? 1281 I'm loading source from files, compiling, linking and then trying to check for errors after glUseProgram In my object's draw method .. log.info(gl2.glIsProgram(shaderProgram)); // true gl2.glUseProgram(shaderProgram); int error; while ((error = gl2.glGetError()) != GL2.GL_NO_ERROR) { throw new RuntimeException("glUseProgram" +...

How to create latitudinal (horizontal) contour lines in GLSL?

opengl,glsl,webgl
I'm aiming for this effect: (horizontal-only contour lines): I did find this example, however it creates horizontal and vertical contour lines. I can't quite wrap my head around how the call to fwidth() is generating the lines. uniform float gsize;//size of the grid uniform float gwidth;//grid lines'width in pixels varying...

Why does OpenGL 3+ throws viewing matrices manipulation away?

opengl,glsl,jogl
GL version 1 and 2 contain functions manipulating the model, view and projection matrices, such as "glLoadIdentity()" and etc. And glu is usually used together to set the camera and viewing perspective. However, GL version 3+ does not support those any more, which means you have to implement those instead....

Preparing model, view and projection matrices for glsl

java,matrix,glsl
I'm using the vecmath library to help with matrix maths while I'm converting opengl program to utilize glsl better. After writing question I guess I've 3 small questions: Where does the model matrix get it's value from? Do I need to reset all model, view and projection matrices inside display()?...

What happens if Vertex Attributes not match Vertex Shader Input

opengl,attributes,glsl,vertex-shader,pixel-shader
As I know, if the vertex buffer has an attribute that shader does not use, there will be no problem. What happens if the vertex buffer does not have an attribute that the vertex shader uses for OpenGL? I know for DirectX11, nothing will draw if the attribute needed in...

GLSL getting odd values back from my uniform and it seems to be set with the wrong value too

opengl,glsl
I'm having problems using a uniform in a vertex shader heres the code // gcc main.c -o main `pkg-config --libs --cflags glfw3` -lGL -lm #include <GLFW/glfw3.h> #include <stdio.h> #include <stdlib.h> #include <math.h> void gluErrorString(const char* why,GLenum errorCode); void checkShader(GLuint status, GLuint shader, const char* which); float verts[] = { -0.5f,...

How to get shader version from QOpenGLShader?

qt,opengl,glsl
I am using QT to load, compile and link OpenGL shaders. I need to perform specific operations depending on the GLSLversion used in the shader code Is it possible to recover the version from the QOpenGLShader interface without actually getting the shader source code and parsing it to detect the...

Computational cost of math operations in GLSL

glsl
I'm writing a GPGPU program using GLSL shaders and am trying to come up with a few optimizations for an N-body collision detection algorithm. One is performing a 'quick' check to determine whether two objects are even in the same ballpark. The idea is to quickly disqualify lots of possibilities...

GLSL : Should I concern if variables are correct or not?

opengl,glsl
In case of treating many kind of materials, some information are omitted because they are not needed. and if they are not handled, CPU will pass nothing to GPU(or vertex to frag). In this case, should I concern if variables(especially uniforms) are correct(passed) or not in the shader? Or, should...

glsl layout with glvertexattribpointer issues

layout,glsl,vbo
So I have a working program that displays a terrain mesh generated from a height map. I want to use the layout qualifier to declare the vertex attributes now, but I am having issues. When I just use the built in gl_Normal for my normals, everything works fine. When I...

Toon.shader not finding _light var

ios,objective-c,opengl-es,glsl,scenekit
So I'm loading my custom shader in Apple's SceneKit by doing. - (NSDictionary *)celShading { NSMutableDictionary *shaders = [NSMutableDictionary new]; shaders[SCNShaderModifierEntryPointFragment] = [NSString stringWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"toon" withExtension:@"shader"] encoding:NSUTF8StringEncoding error:NULL]; return shaders; } My custom shader is toon.shader vec3 lDir = normalize(vec3(0.1,1.0,1.0)); float dotProduct = dot(_surface.normal,lDir); _lightingContribution.diffuse += (dotProduct * dotProduct...

Shaders in WebGL vs openGL? [closed]

opengl,glsl,webgl
I want to use shaders to use in WebGL and specifically three.js. Is there a specific version of GLSL that WebGL and three.js uses?

Is it always good to use Vec3f / Vec4f class defined by yourself?

opengl,glsl,jogl
A question about coding style: When you're going to reconstruct a virtural scene containing plenty of objects (Using JOGL), is it always good to define a Vec3f class and face class representing the vertices, normals, and faces rather than to directly use float[] type? Any ideas?

What is texture downsampling (downscaling) using OpenGL?

opengl,glsl,shader
I did not found any tutorial that explains how to downscale a texture using OpenGL. For example if I have a 1024x720 texture and I want to generate downscale by the factor 1/4 how to do it? Here's a tutorial talking about downsampling. UPDATE I tried the following filtering code...

Scaling part of mesh in a given direction

opengl,math,glsl
I have a lot of cubes (ex 100) that are all part of the same mesh, and in a vertex shader I would like to scale each cube along a given axis, so it's top is moved and the cube stretched like this: Each cube has an ID, and each...

Comparing the multiDrawArrays, using primitive restart and multiDrawElements in terms of performance?

opengl,glsl,jogl
I want to draw a mass of branches with different shapes, each of which consisting of 4 triangle strips. (Using OpenGL) So now I'm considering using one of those method calls (multiDrawArrays, using primitive restart and multiDrawElements). I was wondering which one is more efficient. Is the method multiDrawArrays() equivalent...

GLSL Shader not Compiling, no Error Message

java,compilation,glsl,lwjgl
I am trying to use a GLSL shader I wrote from LWJGL. It is just a simple fragment-based phong shader. The shader has worked fine in the past, even on this computer. The other day, all of a sudden, it simply stopped compiling for no apparent reason. When I try...

Declaring array in GLSL based on uniform int

c++,arrays,opengl,glsl,uniform
In the program that I'm coding, I have to generate multiple lights sources and pass is to the shader. As this number is defined outside the shader, I though to pass it through an uniform int and use this to declare the arrays size. uniform int numLights; uniform vec4 ambientColor;...

Volume rendering is more transparent from one direction that another

three.js,glsl,webgl,volume-rendering,raymarching
I'm trying to get my head around volume rendering using three.js and ray marching GLSL. I've got some data I synthesised from a numpy array. The cube of data being rendered is more opaque on one side, graduating to being transparent on the other side - like this (ignore the...

What version of GLSL does WebGL use

glsl,webgl
Is this a per device sort of thing? Or is it based on the browser? Sorry for such a basic question but I cant seem to find a straight answer.

What can I use as an array index in GLSL in WebGL ?

arrays,indexing,glsl,webgl
Are there ONLY constants allowed or can I use for loop indices or any other dynamic values ?

Camera-space Normals from depth texture

opengl,glsl,lighting,normals,deferred-rendering
I want to use a stored (non-linear) depth texture from 1st pass to produce screen-space normals. In 2nd pass I can render out depth, diffuse, ID etc., but I can't seem to get normals from depth working. Current understanding of getting normals from depth: texture() / texelFetch() p at the...

OpenGL ES GLSL shader on Android not loading correct version?

android,opengl-es,glsl,glsles
I'm following this example on rendering the camera preview using GLES 2.0 (http://maninara.blogspot.com/2012/09/render-camera-preview-using-opengl-es.html). It worked great until I copied some GLSL shader code from somewhere else and noticed it didn't work and I get this error: error C7502: OpenGL does not allow type suffix 'f' on constant literals in versions...

illegal vector field selection length

vector,glsl,opengl-3,variable-length
I am receiving this error on a pc where I cannot have access. The error is on the Vertex Shader of the init program of the depth peeling technique. ERROR: 0:42: error(#222) Illegal vector field selection length ERROR: 0:42: error(#222) Illegal vector field selection length ERROR: error(#273) 2 compilation errors....

Anyone offer me an example using glMultiDrawArraysIndirect with JOGL?

opengl,glsl,jogl
I learned the method glMultiDrawArraysIndirect() from OpenGL, and I want to use this method call with JOGL. In the sample code, a C++ struct is used and the data in that struct is stored in a buffer by using glMapBufferRange(). I was wondering how it is down with JOGL? It...

opengl lighting is reversed on each model

java,opengl,glsl
I have a problem where the lighting in my model looks as if it is reversed on every model that is rendered. I am lighting a field of tiles, each tile encapsulates an 8x8 subset of smaller tiles so each larger tile contains 4*8*8 vertices. I have the normal set...

Video Memory from ETC2 Texture Compression on OpenGL 4.3

c++,opengl,opengl-es,textures,glsl
Currently I'm writing a renderer which uses many textures and will fill up my graphics card's video memory (3 Gb for my nVidia GTX 780 Ti). So I pre-compressed all necessary images by using Mali's texture compression tool and integrated my renderer with libktx for loading compressed textures(*.ktx). The compression...

How to blur a transparent texture in a glsl shader?

glsl,webgl
My setup: Ping-ponging RGBA FBO's, and two shaders for blurring: a horizontal and a vertical one. Imagine I want to blur a red rectangle. The blend function is as follows: _gl.blendEquationSeparate(_gl.FUNC_ADD, _gl.FUNC_ADD); _gl.blendFuncSeparate(_gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA); In my blur shaders I add several fragments like this: vec4 color = texture2D(u_image,...

superbible sample code ported to JOGL, yet not working

java,opengl,glsl,jogl
I wrote some sample code from superbible (6th, P27-P30) to JOGL, but it did not work(there should be a triangle, yet there is nothing but only green background). Please take a look at the code below. Great thanks for any help!! original code: /* * Copyright ?2012-2013 Graham Sellers *...

Why GLSL const bool doesn't works?

c++,opengl,visual-c++,glsl
I have a fragment shader with #version 130 and I have a vector: uniform vec3 sunPosition;. This is works fine: bool isTheSunUp = sunPosition.y > 0; But the following doesn't complie: const bool isTheSunUp = sunPosition.y > 0; Why?...

Write positions to texture OpenGL/GLSL

c++,opengl,textures,glsl
I want to write the model-space vertex positions of a 3D mesh to a texture in OGL. Currently in order to write to a texture I set it to a fullscreen quad and write to it using a separate pass (based on tutorial seen here.) The problem is that, from...

Atmosphere Scattering for Earth from space and on the ground

three.js,glsl,webgl
Please provide prompt how to make the atmosphere of the Earth so that it is visible from space and from the ground (as shown in the image) a model of the earth: Earth = new THREE.Mesh(new THREE.SphereGeometry(6700,32,32),ShaderMaterialEarth); model of the cosmos: cosmos= new THREE.Mesh(new THREE.SphereGeometry(50000,32,32),ShaderMaterialCosmos); and a light source: sun...

GL_ARB_sparse_texture not supported

opengl,glsl,opengl-extensions
I have this code which check if GL_ARB_sparse_texture is supported: GLint ExtensionCount = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &ExtensionCount); for (GLint i = 0; i < ExtensionCount; ++i) if (std::string((char const*)glGetStringi(GL_EXTENSIONS, i)) == std::string("GL_ARB_sparse_texture")){ std::cout << "supported" << std::endl; } It prints out that it is supported. Problem is that my shader says...

Writing fragment shaders: cannot make sense of how the uniforms are defined

javascript,glsl,webgl,phaser-framework,pixi
I'm trying to make custom filters with Phaser, but I don't get how the uniforms, and vTextureCoord in particular are specified. Here's a JSFiddle (EDIT: Ignore the image, the minimal case lays in the square gradient): Why isn't the top-right corner white? I've set both the filter resolution and the...

OpenGL OGLDev SSAO Tutorial Implementation Fragment Shader yields Noise

c++,opengl,glsl,ssao,deferred-shading
TASK BACKGROUND I am trying to implement SSAO after OGLDev Tutorial 45, which is based on a Tutorial by John Chapman. The OGLDev Tutorial uses a highly simplified method which samples random points in a radius around the fragment position and steps up the AO factor depending on how many...

GLSL: sampler upload only works when unused sampler is removed

opengl,textures,glsl,framebuffer
Im currently trying to implement deferred shading with framebuffers in OpenGL. The framebuffer itself works perfectly, but when I dont use all uniform samplers in the shader, one of the textures stop working. This is my fragment shader, a test demonstration of the framebuffer: #version 330 core uniform sampler2D texCoordTex;...

GLSL Fragment shader won't compile with a texture2D call uncommented

android,opengl-es,glsl,opengl-es-2.0,glsles
I have a N910f note 4 with the last lollipop 5.0.1. Well, the fragment shader isn't compilling, but if i comment out the line of texture sampling (texture2D call) the shader compiles. I don't know what happends to the compiler because of Log.e(TAG, GLES20.glGetShaderInfoLog(shader)) call is not throwing any information....

Shader's function parameters performance

opengl,directx,glsl,shader,hlsl
I'm trying to understand how passing parameters is implemented in shader languages. I've read several articles and documentation, but still I have some doubts. In particular I'm trying to understand the differences with a C++ function call, with a particular emphasis on performances. There are slightly differences between HSLS,Cg and...

Should Meshes with and without Skeleton use different Shaders?

c++,opengl,glsl,shader,vertex-shader
Should Meshes with and without Skeleton use different Shaders? Background: Right now my shader is constructed to handle meshes with skeletons. Each vertex takes 3 bone IDs, with respective bone weight. This works well for models with skeletons that I wish to animate, but I feel that it is a...

opengl - use large (100k) uniform array in shader

c++,opengl,glsl,buffer
In my program I am doing a single render of one model. I have a generated array of unsigned chars where all bits in each byte can be used. There is an element in the array for each triangle in the model. To get the color for the triangle I...

What is the best way of drawing massive of different objects with the same texture using JOGL

opengl,glsl,jogl
The following questions are about the coding style. (currently using JOGL + gl3) If I want to draw a mass of different objects containing the same texture with JOGL, and to reduce the resources usage, is it better to seperate the objects and their texture (meaning that creating another class...

How vertex and fragment shaders communicate in OpenGL?

opengl,graphics,glsl,fragment-shader,vertex-shader
I really do not understand how fragment shader works. I know that vertex shader runs once per vertices fragment shader runs once per fragment Since fragment shader does not work per vertex but per fragment how can it send data to the fragment shader? The amount of vertices and amount...

GLSL layout attribute number

c,opengl,glsl
I was trying out a shader example to draw a triangle with the RGB interpolated across the vertices, and assumed that using layout (location = 0)in vec4 vertex; layout (location = 1) in vec4 VertexColor; in the vertex shader would work, since the 4 float colors immediately follow 4 float...

GLSL small float value truncation starting from iPad Air

ios,ipad,opengl-es,glsl
In my attempts of fixing the liquid simualtion app that works fine on iPad3(PowerVR SGX543MP4, iOS 8.1) and older hardware but fails on iPad Air(PowerVR G6430, iOS 8.1)... I stumbled upon quite "curious" handling of small floating point values on latter. It boiled down to such test case: Fragment Shader...

Ambient and Specular lighting not working correctly in GLSL

opengl,glsl,lighting,phong
In my lighting scene, for some reason the ambient lighting isn't working at all. The whole model is the same brightness, no matter which way it is facing. I tried getting rid of the attenuation but it still has the same results. Along with that, the specular lighting is always...

Skeletal Animation in OpenGL (GLSL) with Assimp

c#,opengl,animation,glsl,skeletal-animation
I am trying to implement GLSL-powered skeletal animation in a program... and rather than beautiful 3D animation, I've created a monster: https://i.imgur.com/dmpKg6n.gif After trying a few different techniques, I created a less terrifying but still monstrous thing: The model is a basic human in a suit, the animation is supposed...

Does it make any difference which shader calculations are performed in?

c++,opengl,graphics,opengl-es,glsl
With GLSL, I'd be performing lighting calculations, texturing and all sorts; but does it make any difference which shader it is done in? For example, is there a performance benefit in performing lighting calculations in the vertex shader rather than the fragment shader? I'd have to pass only the end-result...

alpha not changing transparency of object using glsl shader

opengl,glsl
How come when i manually change the alpha value in array, being passed to shader, the result is the same for both 0.0f and 1.0f? I was expecting the object to be drawn with some level of transparency, depending on alpha value. I'm not using any textures. I always see...

Shader - Simple SSS lighting issue

opengl,directx,glsl,shader,hlsl
I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface...

Porting GL ES 2.0 shaders to desktop GLSL (should I?)

opengl,opengl-es,glsl,shader,glsles
I'm developing a cross-platform game, for iOS, Windows, and OS X. Right now I'm at the point where I'm writing all my shaders for my graphics. So here's the question: If I have working GL ES 2.0 shaders (#version 100) for the mobile version of the game (which I developed...