Scene Voxelization

Started by
10 comments, last by gboxentertainment 10 years, 6 months ago

When debugging over all of the textures, only some few depth slices actually have been written to, but it's usually just one pixel, which doesn't give any sense.

Gbox, did you implement your own implementation or did you follow this? : http://www.geeks3d.com/20121214/voxel-cone-tracing-global-illumination-in-opengl-4-3/

If the 2nd, can you share what matrices do you transpose?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement

vec4 storagePos = transpose(gsout.oProj)*gsout.ndcPos;
storagePos.xyz *= 1.0/storagePos.w;

Btw, how are you actually doing your voxelization? I'm using the geometry shader with the dominant-axis method. i.e:


#version 430

layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;

in VSOutput
{
	vec4 ndcPos;
	vec4 fNorm;
	vec2 fTexCoord;
	vec4 worldPos;
	vec4 shadowCoord[6];
} vsout[];

out GSOutput
{
	vec4 ndcPos;
	vec4 fNorm;
	vec2 fTexCoord;
	vec4 worldPos;
	vec4 shadowCoord[6];
	mat4 oProj;
	float density;
} gsout;

uniform mat4 voxSpace;
uniform mat4 invVoxSpace;

void main()
{
	gsout.oProj = mat4(0);
	vec4 n = normalize(vsout[0].fNorm);

	for(int i = 0; i<gl_in.length(); i++)
	{
		vec4 voxPos = invVoxSpace*vsout[i].ndcPos;	
		gsout.fNorm = n;
		
		float maxC = max(abs(n.x), max(abs(n.y), abs(n.z)));
		float x,y,z;
		x = abs(n.x) < maxC ? 0 : 1;
		y = abs(n.y) < maxC ? 0 : 1;
		z = abs(n.z) < maxC ? 0 : 1;

		vec4 axis = vec4(x,y,z,1);
		
		if(axis == vec4(1,0,0,1))
		{
			gsout.oProj[0] = vec4(0,0,-1,0);
			gsout.oProj[1] = vec4(0,-1,0,0);
			gsout.oProj[2] = vec4(-1,0,0,0);
			gsout.oProj[3] = vec4(0,0,0,1);
			gsout.density = (voxPos.x - floor(voxPos.x));
		}	
		else if(axis == vec4(0,1,0,1))
		{
			gsout.oProj[0] = vec4(1,0,0,0);
			gsout.oProj[1] = vec4(0,0,1,0);
			gsout.oProj[2] = vec4(0,-1,0,0);
			gsout.oProj[3] = vec4(0,0,0,1);
		gsout.density = (voxPos.y - floor(voxPos.y));
		}
		else if(axis == vec4(0,0,1,1))
		{
			gsout.oProj[0] = vec4(1,0,0,0);
			gsout.oProj[1] = vec4(0,-1,0,0);
			gsout.oProj[2] = vec4(0,0,-1,0);
			gsout.oProj[3] = vec4(0,0,0,1);
		gsout.density = (voxPos.z - floor(voxPos.z));
		}

		gl_Position = gsout.oProj*voxSpace*gl_in[i].gl_Position;
		gsout.ndcPos = gsout.oProj*voxSpace*vsout[i].ndcPos;
		gsout.fTexCoord = vsout[i].fTexCoord;
		gsout.worldPos = vsout[i].worldPos;
		gsout.shadowCoord[0] = vsout[i].shadowCoord[0];

		EmitVertex();
	}
	
}

This topic is closed to new replies.

Advertisement