Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Member Since 13 Dec 2001
Offline Last Active Dec 16 2014 04:59 PM

Topics I've Started

Simple imageBuffer Problem

16 December 2014 - 02:43 PM



I think this should be a fairly straight forward thing to figure out, but I'm having problems getting data into my fragment shader from a texture buffer object.


Problem Summary: When I eventually get to the shader and call imageLoad it is always returning 0.0.


Slightly more details: The texture buffer is the size of the FBO and is going to be used for some I/O work using imageAtomicMin to manage some weird-o transparency stuff I'm prototyping for a specific game feature


Texture and buffer + creation:

GLuint a_texID;
GLuint a_bufID;

    glGenTextures( 1, &a_texID );

    glGenBuffers( 1, &a_bufID );
    glBindBuffer( GL_TEXTURE_BUFFER, a_bufID );
    glBufferData( GL_TEXTURE_BUFFER, screenInfo.Width*screenInfo.Height*sizeof(float), NULL, GL_DYNAMIC_DRAW );

Pre-Render work (called every frame). If it matters this logic gets executed before the shader program is bound

    //reset the buffer data since the fragment shader will eventually write to it
    const float initializationValue = 1.0f;
    glBindBuffer( GL_TEXTURE_BUFFER, a_bufID );
    glClearBufferData( GL_TEXTURE_BUFFER, GL_R32F, GL_RED, GL_FLOAT, &initializationValue );

    //set up the texture buffer in the right place so the fragment shader can access it
    glActiveTexture( GL_TEXTURE3 );
    glBindTexture( GL_TEXTURE_BUFFER, a_texID );
    glTexBuffer( GL_TEXTURE_BUFFER, GL_R32F, a_bufID );

Fragment Shader

uniform int screenWidth;
layout(binding=3, r32f) uniform coherent imageBuffer myBuffer;

    int index = int(gl_FragCoord.x) + int(gl_FragCoord.y) * screenWidth;
    vec4 data = imageLoad( myBuffer, index );
    //PROBLEM: data.r is always == 0.0

Thing I tried:

I tried just skipping the glClearBufferData part and instead passed a data array that was all set to 1.0. That didn't work either which suggests to me I'm doing something wrong with binding...


Bind a VBO as a TexImage2D?

25 June 2014 - 09:06 PM



Random question to optimize a bizarro pipeline I have going.


I'm using a Geometry Shader + Transform Feedback right now to generate a data set. I want to then pass that data set through another Shader but have it addressable as a sampler2d because I need access to multiple data points in the next Shader (evaluating neighbors).


I know that I can use glGetBufferSubData to extract the output VBOs and then bind that data to a texture with the standard glTexImage2D stuff. But I'm wondering if there is a shortcut whereby I don't need to pull the information off of the graphics card or copy it from one location to another using a COPY_WRITE_BUFFER or whatever. Can I just rebind the VBO somehow and get it treated as a texture addressable by a sampler2d?


Please feel free to ask questions if that's not clear. It's a mouthful...

Dynamic Ambient Occlusion

23 June 2014 - 08:24 PM



So I'm trying to deepen my GPU knowledge and embarking on rendering a minecraft-style mesh with Dynamic Ambient Occlusion ala this GPU Gems article.



I guess the principle question I have is this:

When you are creating the AO shadow value per-vertex (element) in your mesh, do you then just follow that with a normal render and use normal fragment shader linear interpolation between adjacent vertex shadow values to actually shade the fragments?


i.e. does the process look something like this:

2 passes of the AO algorithm

1 pass of a normal render using a texture map output by the AO algroithm to get shadow values per vertex?


Or am I missing something in the article and you can actually do the screen render within the 2 AO passes?





Problem with glDrawElementsInstanced and glVertexAttribDivisor

15 June 2014 - 11:45 AM



Long time no posty... Anyway... I have a large grid of items that I'm rendering and want to do instanced rendering. I've obviously mis-set something because the data from my array buffer is coming in mangled. I'm looking for help identifying the problem. Thanks!


Setup for the Array Buffer in question:

glGenBuffers(1, &cellVBO.extraID0); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, cellVBO.extraID0); // Bind our Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, gridInfo.MaxX*gridInfo.MaxZ*sizeof(uint32_t), NULL, GL_DYNAMIC_DRAW);
glVertexAttribPointer(ATTRIB_EXTRA0, 1, GL_UNSIGNED_INT, GL_FALSE, 0, 0);
glVertexAttribDivisor(ATTRIB_EXTRA0, 1);

Per render tick updating of the Array Buffer's Content:

//fill the testCell
glUniform1ui( uniforms[UNIFORM_UINT2], layerStart[0] );

//fill the actual Array Buffer
glBindBuffer( GL_ARRAY_BUFFER, cellVBO.extraID0 );
uint32_t *layerCells = (uint32_t *)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
memcpy( layerCells, layerDataStart, gridInfo.MaxX*gridInfo.MaxZ*sizeof(uint32_t) );
glUnmapBuffer( GL_ARRAY_BUFFER );


glBindVertexArray( cellVBO.vaoID );
glDrawElementsInstanced(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, (GLvoid*)0, gridInfo.MaxX*gridInfo.MaxZ);
glBindVertexArray( 0 );

Vertex Shader:

const GLchar* CellVertexShader_Instanced =
	"#version 400\n"\
	"layout(location=0) in vec3 in_Position;\n"\
	"layout(location=1) in vec2 in_TexCoord;\n"\
	"layout(location=2) in vec3 in_Normal;\n"\
	"layout(location=3) in uint in_Cell;\n"\

	"uniform mat4 proj_matrix;\n"\
	"uniform mat4 view_matrix;\n"\
	"uniform mat4 model_matrix;\n"\

	"uniform vec3 gridStartPos;\n"\
	"uniform uint layerY;\n"\
	"uniform uint gridMaxX;\n"\

	"uniform uint testCell;\n"\

	"uniform sampler1D uvLookupTexture;\n"\
	"out vec2 ex_TexCoord;\n"\
	"out vec3 position_world, normal_world;\n"\
	"out float ex_Invert;\n"\
	"out uint ex_CellContent;\n"\

	"void main(void)\n"\
		"	mat4 mvp_matrix = proj_matrix * view_matrix * model_matrix;\n"\

		"	//calculate the cell coortinates\n"\
		"	uint cellCoordZ = gl_InstanceID / gridMaxX;\n"\
		"	uint cellCoordX = gl_InstanceID - cellCoordZ*gridMaxX;\n"\

		"	//extract cell information\n"\
		"	ex_CellContent = testCell >> 24;\n"\ !!!! CORRECT VALUE !!!!
		"	ex_CellContent = in_Cell >> 24;\n"\  !!!! WRONG VALUE !!!! 

I also added a debug uniform, "testCell", that's taking the first element that should be getting copied into the Array Buffer just to make sure the other logic is correct. It is rendering totally correctly if I just leave in the line grabbing the value from testCell.

iPhone: Pitch Shifting Without Frequency Change

22 July 2010 - 05:58 PM


So I'm wondering if there is a "built-in" way to do pitch shifting on the iPhone without changing the frequency (playback rate). This is definitely possible with FMOD on the iPhone, but it's a $500 commercial license which I'd like to avoid paying since I'd be buying for this feature only.

I have OpenAL working but it's AL_PITCH functionality operates by changing the frequency so you get chipmunk or elephant effects super quickly.