Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: problem with transform feedback for pushing an object through multiple lights

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Newbie
    Join Date
    Sep 2014
    Posts
    33

    Question problem with transform feedback for pushing an object through multiple lights

    hi, i know that questions where their is alot of code are frowned upon, but ive spent close to three hours trying to debug this and i can't figure out what is wrong with it. what i am trying to do is push an object through multiple light sources using transform feedback. basically i have a shader program designed for translating the objects vertices into world space coordinates. i then also try to capture that data back into some buffers without drawing anything (i use glEnable(GL_RASTERIZER_DISCARD)) i then pass the world coordinates through 1 ambient light source and capture the colors for each vertex. then i pass it through as many point and directional light sources (im gonna add spot when i debug this) as wanted and continue to capture the colors. i then do glDisable(GL_RASTERIZER_DISCARD) and draw the captured world coordinates with the captured colors. their is quite a bit of copying between bufers to. i copy the captured coordinates and colors to other buffers. i wont put all the code in here just one pass through my world coordinates program, one pass through the ambient program, one pass through the program that draws the captured data to the screen and the corresponding shaders.

    Code :
    GLint ibuffer, nbuffer, vbuffer;
     
    		GLuint vao[3];
     
    		glGenVertexArrays(3, vao);
     
    		glBindVertexArray(vao[0]);
     
    		glUseProgram(progtransform);
     
    		glEnable(GL_RASTERIZER_DISCARD);
     
    		glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, vertexbufferout);
    		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type3D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
    		glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 7, vertexbufferout, 0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
     
    		glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, normalbufferout);
    		glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type3D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
    		glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 8, normalbufferout, 0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
     
    		glTransformFeedbackVaryings(progtransform, 2, varyingstransform, GL_SEPARATE_ATTRIBS);
     
    		glLinkProgram(progtransform);
     
    		glGenBuffers(1, &ibuffer);
    		glGenBuffers(1, &nbuffer);
    		glGenBuffers(1, &vbuffer);
     
    		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibuffer);
    		glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(struct TypeVertexIndexList3) * mesh->MeshIndexListSize, mesh->MeshIndexList, GL_STATIC_DRAW);
     
    		glBindBuffer(GL_ARRAY_BUFFER, vbuffer);
    		glBufferData(GL_ARRAY_BUFFER, sizeof(struct Type3D) * mesh->MeshVertexListSize, mesh->MeshVertexList, GL_STATIC_DRAW);
    		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
    		glEnableVertexAttribArray(0);
     
    		glBindBuffer(GL_ARRAY_BUFFER, nbuffer);
    		glBufferData(GL_ARRAY_BUFFER, sizeof(struct Type3D) * mesh->MeshNormalListSize, mesh->MeshNormalList, GL_STATIC_DRAW);
    		glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
    		glEnableVertexAttribArray(1);
     
    		GLint translatemeshloc = glGetUniformLocation(progtransform, "translatemesh");
    		GLint translatecamloc = glGetUniformLocation(progtransform, "translatecam");
     
    		glUniform3fv(translatemeshloc, 1, mesh->WorldCoords.vec);
    		glUniform3fv(translatecamloc, 1, cam->Pos.vec);
     
    		glDrawElements(GL_TRIANGLES, 3 * mesh->MeshIndexListSize, GL_UNSIGNED_INT, (void *)0);
     
    		glBindBuffer(GL_COPY_WRITE_BUFFER, vertexbufferin);
    		glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type3D) * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
    		glBindBuffer(GL_COPY_READ_BUFFER, vertexbufferout);
    		//glBindBuffer(GL_COPY_WRITE_BUFFER, vertexbufferin);
    		glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
     
    		glBindBuffer(GL_COPY_WRITE_BUFFER, normalbufferin);
    		glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type3D) * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
    		glBindBuffer(GL_COPY_READ_BUFFER, normalbufferout);
    		//glBindBuffer(GL_COPY_WRITE_BUFFER, normalbufferin);
     
    		glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type3D) * mesh->MeshIndexListSize);
     
    		//glEnable(GL_RASTERIZER_DISCARD);
     
     
    		glBindVertexArray(vao[1]);
     
    		if (lights->ambient != NULL)
    		{
    			glUseProgram(progambient);
     
    			glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, colorbufferout);
    			glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize, NULL, GL_DYNAMIC_COPY);
    			glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 9, colorbufferout, 0, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize);
     
    			glTransformFeedbackVaryings(progambient, 1, varyingsambient, GL_SEPARATE_ATTRIBS);
     
    			glLinkProgram(progambient);
     
    			GLint colorobjectloc = glGetUniformLocation(progambient, "colorobject");
    			GLint colorlightloc = glGetUniformLocation(progambient, "colorlight");
    			GLint intensityloc = glGetUniformLocation(progambient, "intensity");
     
    			glUniform4fv(colorobjectloc, 1, mesh->RGBA);
    			glUniform4fv(colorlightloc, 1, lights->ambient->colorlight.vec);
    			glUniform1f(intensityloc, lights->ambient->intensity);
     
    			glDrawArrays(GL_TRIANGLES, 0, 3 * mesh->MeshIndexListSize);
     
    			glBindBuffer(GL_COPY_WRITE_BUFFER, colorbufferin);
    			glBufferData(GL_COPY_WRITE_BUFFER, sizeof(struct Type4D) * 3 * mesh->MeshIndexListSize, NULL, GL_STATIC_DRAW);
    			glBindBuffer(GL_COPY_READ_BUFFER, colorbufferout);
    			//glBindBuffer(GL_COPY_WRITE_BUFFER, colorbufferin);
    			glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, (GLintptr)0, (GLintptr)0, sizeof(struct Type4D) * mesh->MeshIndexListSize);
    		}
    		else
    		{
    			printf("\n##An ambient light is needed\n");
     
    			exit(1);
    		}
     
                            glBindVertexArray(vao[2]);
     
    			glDisable(GL_RASTERIZER_DISCARD);
     
    			glUseProgram(progdraw);
     
    			GLint perspectiveloc = glGetUniformLocation(progdraw, "perspective");
    			GLint uvnloc = glGetUniformLocation(progdraw, "uvn");
     
    			glUniformMatrix4fv(perspectiveloc, 1, GL_FALSE, cam->ProjectionMat.marray);
    			glUniformMatrix3fv(uvnloc, 1, GL_FALSE, cam->UVNMat.marray);
     
    			glBindBuffer(GL_ARRAY_BUFFER, colorbufferin);
    			glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, 0, (void *)0);
    			glEnableVertexAttribArray(6);
     
    			glBindBuffer(GL_ARRAY_BUFFER, vertexbufferin);
    			glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, (void *)0);
    			glEnableVertexAttribArray(4);
     
    			glDrawArrays(GL_TRIANGLES, 0, 3 * mesh->MeshIndexListSize);

    here are the shaders

    transform
    Code :
    const char *vshadertransform =
    "#version 430 core\n"
    "layout (location = 0) in vec3 vPosition;\n"
    "layout (location = 1) in vec3 vNormal;\n"
    "layout (location = 7) out vec3 verticestfout;\n"
    "layout (location = 8) out vec3 normalstfout;\n"
    "uniform vec3 translatemesh;\n"
    "uniform vec3 translatecam;\n"
    "void main()\n"
    "{\n"
    "verticestfout = vPosition - translatecam + translatemesh;\n"
    "normalstfout = vNormal;\n"
    "}\n";

    ambient
    Code :
    const char *vshaderambient = 
    "#version 430 core\n"
    "uniform vec4 colorobject;\n"
    "uniform vec4 colorlight;\n"
    "uniform float intensity;\n"
    "layout (location = 9) out vec4 colorstfout;\n"
    "void main()\n"
    "{\n"
    "colorstfout = min(colorobject + (colorobject + colorlight * intensity), vec4(1, 1, 1, 1));\n"
    "}\n";

    drawing program
    Code :
    const char *vshaderdraw = 
    "#version 430 core\n"
    "uniform mat4 perspective;\n"
    "uniform mat3 uvn;\n"
    "layout (location = 4) in vec3 verticestfin;\n"
    "layout (location = 6) in vec4 colorstfin;\n"
    "out vec4 color;\n"
    "void main()\n"
    "{\n"
    "gl_Position = perspective * vec4(uvn * verticestfin, 1);\n"
    "color = colorstfin;\n"
    "}\n";
     
    const char *fshaderdraw = 
    "#version 430 core\n"
    "in vec4 color;\n"
    "out vec4 colorout;\n"
    "void main()\n"
    "{\n"
    "colorout = color;\n"
    "}\n";

    thanks alot
    (btw the screen just shows the color that i cleared it to, it doesnt draw the image.)
    Last edited by a-sylum; 09-01-2015 at 09:14 AM. Reason: a bit more info

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •