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.


#Actualgboxentertainment

Posted 12 February 2013 - 08:40 AM

Okay, so I implemented the dominant axis voxelization into my voxel cone tracer. Here are the results:

 

[attachment=13612:vct3.jpg][attachment=13613:givox5.jpg]

 

Aside from the very soft and very voxelized shadows, the main artifact is the diffuse reflection from the red box caused by the illumination sampled from the base mip - this is due to the voxelized box being extruded out too much. I'm not using conservative voxelization by the way.

I don't think I've got the soft shadowing calculation right either, all I'm doing is just taking the vct function and tracing a single cone in the direction of the light.

 

Here is my vct code:

 

#version 430

in vec4 fNorm;
in vec2 fTexCoord;
in vec4 worldPos;
out vec4 fColor;

uniform sampler2D sampler0;

layout(binding = 1) uniform sampler3D voxTex;

uniform mat4 worldSpace;
uniform mat4 voxTexSpace;

uniform float voxDim;

uniform vec4 baseCol;
uniform float specConeRatio;
uniform vec4 lightPos;
uniform vec4 lightDir;
uniform vec3 camPos;

float minVoxDiam = 1/voxDim;

vec4 sampleVox(vec3 pos, vec3 dir, float lod)
{
	vec4 sampleX = dir.x < 0.0 ? textureLod(voxTex, pos-vec3(1,0,0)/voxDim, lod) : textureLod(voxTex, pos+vec3(1,0,0)/voxDim, lod);
	vec4 sampleY = dir.y < 0.0 ? textureLod(voxTex, pos-vec3(0,1,0)/voxDim, lod) : textureLod(voxTex, pos+vec3(0,1,0)/voxDim, lod);
	vec4 sampleZ = dir.z < 0.0 ? textureLod(voxTex, pos-vec3(0,0,1)/voxDim, lod) : textureLod(voxTex, pos+vec3(0,0,1)/voxDim, 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;
}

vec4 coneTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1.0/voxDim;
	float startDist = minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 8.0;

	return accum;
}

vec4 shadowConeTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1/voxDim;
	float startDist = minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 2.0;

	return accum;
}

void main()
{
	vec4 color = vec4(0,0,0,0);
	vec4 texMap = texture(sampler0, fTexCoord);
	vec4 voxPos = voxTexSpace*worldPos;
	voxPos.xyz *= 1.0/voxPos.w;

	//Direct Lighting
	vec4 L = normalize(lightPos - worldPos);
	vec4 D = normalize(lightDir);
	float spotAngle = dot(-L, D);
	float outerCone = 0.7;
	float innerCone = 0.2;
	float spot = clamp((spotAngle - outerCone)/innerCone, 0.0, 1.0);
	float dist = length(L);
	vec4 N = normalize(fNorm);
	float I = max(dot(N, L), 0.0);
	
	if(I > 0.0)
		color += I*spot;

	//Specular Reflection
	vec3 spec;
	vec3 viewToFrag = normalize(worldPos.xyz - camPos);
	vec3 reflDir = reflect(viewToFrag, N.xyz);
	spec = specConeRatio <= 1.0 ? coneTrace(voxPos.xyz, reflDir, specConeRatio, 0.3).xyz : vec3(0);

	//Indirect Lighting
	vec3 iDiffuse = vec3(0);
	float iConeRatio = 0.9;
	float iMaxDist = 0.3;
	iDiffuse += coneTrace(voxPos.xyz, N.xyz, iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(1,0,0), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,1,0), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,0,1), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,-1,0), iConeRatio, iMaxDist).xyz;
	vec4 shadowComp = vec4(0);
	shadowComp += shadowConeTrace(voxPos.xyz, L.xyz, 0.3, 0.4);
	float shadow = (shadowComp.x+shadowComp.y+shadowComp.z)*4;

	fColor.xyz = ((color.xyz/2+iDiffuse)*baseCol.xyz*texMap.xyz+spec)*(1-shadow);
	fColor.w = color.w*1;
}

 

 

Hopefully someone will come up with some tips to help me improve this.

 

[EDIT]

 

On second thoughts, it might actually be the shadowing calc that's causing the artifact with the red box.


#1gboxentertainment

Posted 12 February 2013 - 08:32 AM

Okay, so I implemented the dominant axis voxelization into my voxel cone tracer. Here are the results:

 

[attachment=13612:vct3.jpg][attachment=13613:givox5.jpg]

 

Aside from the very soft and very voxelized shadows, the main artifact is the diffuse reflection from the red box caused by the illumination sampled from the base mip - this is due to the voxelized box being extruded out too much. I'm not using conservative voxelization by the way.

I don't think I've got the soft shadowing calculation right either, all I'm doing is just taking the vct function and tracing a single cone in the direction of the light.

 

Here is my vct code:

 

#version 430

in vec4 fNorm;
in vec2 fTexCoord;
in vec4 worldPos;
out vec4 fColor;

uniform sampler2D sampler0;

layout(binding = 1) uniform sampler3D voxTex;

uniform mat4 worldSpace;
uniform mat4 voxTexSpace;

uniform float voxDim;

uniform vec4 baseCol;
uniform float specConeRatio;
uniform vec4 lightPos;
uniform vec4 lightDir;
uniform vec3 camPos;

float minVoxDiam = 1/voxDim;

vec4 sampleVox(vec3 pos, vec3 dir, float lod)
{
	vec4 sampleX = dir.x < 0.0 ? textureLod(voxTex, pos-vec3(1,0,0)/voxDim, lod) : textureLod(voxTex, pos+vec3(1,0,0)/voxDim, lod);
	vec4 sampleY = dir.y < 0.0 ? textureLod(voxTex, pos-vec3(0,1,0)/voxDim, lod) : textureLod(voxTex, pos+vec3(0,1,0)/voxDim, lod);
	vec4 sampleZ = dir.z < 0.0 ? textureLod(voxTex, pos-vec3(0,0,1)/voxDim, lod) : textureLod(voxTex, pos+vec3(0,0,1)/voxDim, 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;
}

vec4 coneTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1.0/voxDim;
	float startDist = minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 8.0;

	return accum;
}

vec4 shadowConeTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1/voxDim;
	float startDist = minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 2.0;

	return accum;
}

void main()
{
	vec4 color = vec4(0,0,0,0);
	vec4 texMap = texture(sampler0, fTexCoord);
	vec4 voxPos = voxTexSpace*worldPos;
	voxPos.xyz *= 1.0/voxPos.w;

	//Direct Lighting
	vec4 L = normalize(lightPos - worldPos);
	vec4 D = normalize(lightDir);
	float spotAngle = dot(-L, D);
	float outerCone = 0.7;
	float innerCone = 0.2;
	float spot = clamp((spotAngle - outerCone)/innerCone, 0.0, 1.0);
	float dist = length(L);
	vec4 N = normalize(fNorm);
	float I = max(dot(N, L), 0.0);
	
	if(I > 0.0)
		color += I*spot;

	//Specular Reflection
	vec3 spec;
	vec3 viewToFrag = normalize(worldPos.xyz - camPos);
	vec3 reflDir = reflect(viewToFrag, N.xyz);
	spec = specConeRatio <= 1.0 ? coneTrace(voxPos.xyz, reflDir, specConeRatio, 0.3).xyz : vec3(0);

	//Indirect Lighting
	vec3 iDiffuse = vec3(0);
	float iConeRatio = 0.9;
	float iMaxDist = 0.3;
	iDiffuse += coneTrace(voxPos.xyz, N.xyz, iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(1,0,0), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,1,0), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,0,1), iConeRatio, iMaxDist).xyz;
	iDiffuse += 0.707*coneTrace(voxPos.xyz, N.xyz+vec3(0,-1,0), iConeRatio, iMaxDist).xyz;
	vec4 shadowComp = vec4(0);
	shadowComp += shadowConeTrace(voxPos.xyz, L.xyz, 0.3, 0.4);
	float shadow = (shadowComp.x+shadowComp.y+shadowComp.z)*4;

	fColor.xyz = ((color.xyz/2+iDiffuse)*baseCol.xyz*texMap.xyz+spec)*(1-shadow);
	fColor.w = color.w*1;
}

 

 

Hopefully someone will come up with some tips to help me improve this.


PARTNERS