Cheers Krypt0n,
The moment you mentioned face normal, I realised immediately what was wrong. Here's the results:
[attachment=13609:givox2.jpg]
and here's the corrected code:
#version 430
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
//layout(binding = 0) uniform atomic_uint ac;
in VSOutput
{
vec4 ndcPos;
vec4 fNorm;
vec2 fTexCoord;
vec4 worldPos;
} vsout[];
out GSOutput
{
vec4 ndcPos;
vec4 fNorm;
vec2 fTexCoord;
vec4 worldPos;
vec4 axisCol;
mat4 oProj;
} gsout;
uniform mat4 voxSpace;
void main()
{
gsout.oProj = mat4(0.0);
vec4 n = normalize(vsout[0].fNorm);
for(int i = 0; i<gl_in.length(); i++)
{
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.0 : 1.0;
y = abs(n.y) < maxC ? 0.0 : 1.0;
z = abs(n.z) < maxC ? 0.0 : 1.0;
vec4 axis = vec4(x,y,z,1);
if(axis == vec4(1.0,0.0,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);
}
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);
}
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.axisCol = axis;
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;
EmitVertex();
}
}
Now the new challenge with switching from 6-directional 3d textures for storing my voxels to a single 3d texture is sampling anisotropically for voxel cone tracing.
Originally this was my code:
vec4 sampleVox(vec3 pos, vec3 dir, float lod)
{
vec4 sampleX = dir.x < 0.0 ? textureLod(voxTex[0], pos, lod) : textureLod(voxTex[1], pos, lod);
vec4 sampleY = dir.y < 0.0 ? textureLod(voxTex[2], pos, lod) : textureLod(voxTex[3], pos, lod);
vec4 sampleZ = dir.z < 0.0 ? textureLod(voxTex[4], pos, lod) : textureLod(voxTex[5], pos, lod);
vec3 wts = abs(dir);
float invSampleMag = 1.0/(wts.x + wts.y + wts.z + 0.0001);
wts *= invSampleMag;
vec4 filtered = (sampleX*wts.x + sampleY*wts.y + sampleZ*wts.z)/10;
return filtered;
}
where 'dir' is the direction of the cone that I'm tracing. I guess I would just offset 'pos' by 1 voxel in each direction?
[EDIT]
So I've tried offsetting 'pos' by 1 voxel for each direction to get anisotropic sampling - seems to work:
[attachment=13610:givox3.jpg][attachment=13611:givox4.jpg]
Here's the code:
vec4 sampleVox(vec3 pos, vec3 dir)
{
vec4 sampleX = dir.x < 0.0 ? textureLod(sampler0, pos-vec3(1,0,0)/voxDim, 0) : textureLod(sampler0, pos+vec3(1,0,0)/64.0, 0);
vec4 sampleY = dir.y < 0.0 ? textureLod(sampler0, pos-vec3(0,1,0)/voxDim, 0) : textureLod(sampler0, pos+vec3(0,1,0)/64.0, 0);
vec4 sampleZ = dir.z < 0.0 ? textureLod(sampler0, pos-vec3(0,0,1)/voxDim, 0) : textureLod(sampler0, pos+vec3(0,0,1)/64.0, 0);
vec3 wts = abs(dir);
float invSampleMag = 1.0/(wts.x + wts.y + wts.z + 0.0001);
wts *= invSampleMag;
vec4 filtered = (sampleX*wts.x+sampleY*wts.y+sampleZ*wts.z);
return filtered;
}
I will share results once I have implemented this into my voxel cone tracer and have proven that it is anisotropically sampled.