Tag Info

New answers tagged

2

Finally got it working!!! The problem indeed was in the fragment shader. First of all, there was no need to invert the position, the error came from the UV coordinates. Finally I remembered when I was using XNA the textures where flipped vertically respect to OpenGL, and that was the problem. After flipping the V coordinate and correcting the reversed ...


1

Figured it out by looking other shader examples and hopefully it will benefit others. elapsedTime can be added to the computation or offset and will animate the effect, some use sin/cos as well.. uniform float elapsedTime;


1

I found that replacing v_texcoord0 with gl_FragCoord.xy / vec2(screen_width, screen_height) in the SSAO shader, solved this issue.


4

You don't set these values in the shader. You set them in your program, generally when first creating the texture (though it can be set or changed whenever). If you've already uploaded your texture data to OpenGL then all you have to do is this: First bind the texture if it is not already. glBindTexture(GL_TEXTURE_2D, texture_id); Then set the ...


1

One way of doing this is creating and loading an image into memory that is as large as the background. However, this seems like a horrible waste of memory. To affect the whole screen with a fragment shader you don't need a full-screen texture, just a full-screen polygon (one quad or two triangles). The four vertices would have attributes on them. At the ...


0

I suggest you make a skybox: A skybox is a large cube which you render around your camera which will give you the ability to pass each pixel through a fragment shader. And you can render anything onto the skybox: a color, an image, a gradient, etc. Just be sure to call glClear(GL_COLOR_BUFFER_BIT || GL_DEPTH_BUFFER_BIT); A good tutorial on this topic is ...


1

If you are just filling with a solid color then you could pass that color to the fragment shader as a uniform, and process it from there. Use a full screen quad for the fragment shader to render onto. Another way is to this to render the background to an FBO and do the full screen quad trick but apply the FBO texture to it. This would be very memory ...


2

That structure is not aligned correctly, which may be the source of your problem. To form an array using std140 out of PLight, you need to pad it with an extra float at the end. Otherwise, PLight pLights[TOTAL_LIGHTS] is misaligned and you will fetch the wrong memory from pLights [1] -- everything will be off by 1 scalar component on the second light in ...


1

Modern hardware performs early stencil testing using the same sort of tile-based approach as early depth. It can reject large groups of fragments before they make it to the fragment shader stage. That means shader units will not waste time calculating data they are just going to throw out anyway. You add an extra 8-bits of memory per-pixel (pretty much a ...


0

Non-constant indexing into uniform array can be tricky and depends on GLSL version. I think that what you are doing should be within spec (even for GLES 2.0), but it still might be problem. See for example what GLES 2.0 GLSL 1.0 spec says about indexing uniform array in fragmen shader: Apendix A section 5 In the vertex shader, support for all ...


2

The other answers already mention that you're getting a dangling pointer and should return the strings. But reading shaders from a file, really comes down to putting the whole file into a string. Here's one way to do it: // Read shader file into one string std::string shaderSource; if ( !readFileIntoString( shaderFileName, shaderSource ) ) { return ...


1

const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); will result in dangling pointers (with undefined behavior if you dereference it), after you assign the char* to the variable the temp std::string (and backing array you just got a pointer to) gets deleted. const std::string ...


7

You are using pointers to data inside a temporary object: const char* vertex_shader = load_shader("test.vert").c_str(); const char* fragment_shader = load_shader("test.frag").c_str(); Which means both vertex_shader and fragment_shader are pointing to invalid memory, since the strings returned by load_shader get destroyed at the end of each statement. ...


0

Read this through and my best guess is that there is something wrong here: root->finalMatrix = root->animationMatrix * root->offsetMatrix; How is offsetMatrix calculated? And what is it supposed to do (I know somekind of offset). Would also like to see these calculations: //rotation glm::mat4 R = ... //calculate rotation matrix based on time ...


1

What a dump question. I put the cubemap to the wrong samplerCube. I assigned the map to cubemap[1] not cubemap[0]. Great example of "I wouldn't do something like this. The error must be somewhere in the OpenGL code!" :D


1

The way to do this is with a FBO (Frame Buffer Object). You can render each pass to a FBO and use it as a texture input in the next stage, any kind of deferred shading and post processing is reliant upon this functionality. https://www.opengl.org/wiki/Framebuffer_Object


0

Okay so I solved it: 1. Make sure glEnable(GL20.GL_BLEND_COLOR); is on and the blend function is Gdx.gl.glBlendFunc(GL20.GL_BLEND_SRC_ALPHA,GL20.GL_ONE_MINUS_SRC_ALPHA); 2. Edit the light texture in something like GIMP to double check that your background is transparent. 3. MOST IMPORTANT Make sure the lightFramebuffer is Format.RGBA4444 or ...



Top 50 recent answers are included