Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Geometry shaders & render to 3D texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 blubberbert   Members   -  Reputation: 236

Like
0Likes
Like

Posted 29 August 2011 - 11:56 AM

recently i asked on the forums on how to render to 3D textures
i ended up with binding each texture layer in each frame and then rendering to it wich is a solution, but quite slow

i now tried to go with geometry shaders and got the rendering working, however only half of the texture is filled
gDebugger shows that layer 63 is black, while layer 64 is filled normally (on a 128*128*128 texture)

here is my geometry shader

layout (points) in;
layout (triangle_strip, max_vertices = 512) out;

void main()
{
	float f = 2.0 / 128.0;
	for(int i = 0; i < 128; i++)
	{
		float lz = (f * float(i)) - 2.0;
		gl_Position = vec4(-1.0,-1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4( 1.0,-1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4(-1.0, 1.0,lz,1.0); gl_Layer = i; EmitVertex();
		gl_Position = vec4( 1.0, 1.0,lz,1.0); gl_Layer = i; EmitVertex();
		EndPrimitive();
	}
}
the fragment shader that is used to fill each of the layers

void main()
{
        vec3 coord = gl_FragCoord.xyz;
	//coordinates reach from 0.5 to 128.5
	coord.xy -= 0.5;
	coord.xy /= 128.0;
	coord.xy -= 0.5;
	gl_FragData[0] = vec4(coord,1.0);
}
and the code that fills the volume

void fillTarget()
{
	glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
	glPushAttrib(GL_VIEWPORT_BIT);
	glViewport(0,0,volRes,volRes);
	glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, volumetex->getId(), 0);
	glClearColor(0.0f,0.0f,0.0f,1.0f); //making this red shows that the layers still stay empty
	glClear(GL_COLOR_BUFFER_BIT);
	program->bind();
	glBegin(GL_POINTS);
	glVertex3f(0.0f,0.0f,0.0f);
	glEnd();
	Program::unbind();
	glPopAttrib();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

------------------------------
Join the revolution and get a free donut!

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS