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();
}
}