Skip to content
Snippets Groups Projects
Commit e9c8097c authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#81] Optimize reflections by using noise to hide lower sample count

parent e2c97ce3
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
Pipeline #25921 passed
...@@ -50,6 +50,12 @@ float roughnessToConeAngle(float r){ ...@@ -50,6 +50,12 @@ float roughnessToConeAngle(float r){
return mix(degreeToRadian(20), degreeToRadian(90), r); return mix(degreeToRadian(20), degreeToRadian(90), r);
} }
// from: "Next Generation Post Processing in Call Of Duty Advanced Warfare" slide page 123
float interleavedGradientNoise(vec2 uv){
vec3 magic = vec3(0.06711056, 0.00583715, 62.9829189);
return fract(magic.z * fract(dot(uv, magic.xy)));
}
void main() { void main() {
vec3 albedoTexel = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; vec3 albedoTexel = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
...@@ -95,6 +101,7 @@ void main() { ...@@ -95,6 +101,7 @@ void main() {
vec3 R = reflect(-V, N); vec3 R = reflect(-V, N);
float reflectionConeAngle = degreeToRadian(roughnessToConeAngle(r)); float reflectionConeAngle = degreeToRadian(roughnessToConeAngle(r));
vec3 offsetTraceStart = passPos + N_geo * 0.1f; vec3 offsetTraceStart = passPos + N_geo * 0.1f;
offsetTraceStart += R * interleavedGradientNoise(gl_FragCoord.xy) * 0.5;
vec3 specularTrace = voxelConeTrace(R, offsetTraceStart, reflectionConeAngle, voxelTexture, voxelSampler, voxelInfo); vec3 specularTrace = voxelConeTrace(R, offsetTraceStart, reflectionConeAngle, voxelTexture, voxelSampler, voxelInfo);
specularTrace *= clamp(dot(N, R), 0, 1); specularTrace *= clamp(dot(N, R), 0, 1);
vec3 reflectionBRDF = cookTorrance(f0, r, N, V, R); vec3 reflectionBRDF = cookTorrance(f0, r, N, V, R);
......
...@@ -130,7 +130,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t ...@@ -130,7 +130,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t
float coneAngleHalf = coneAngleRadian * 0.5f; float coneAngleHalf = coneAngleRadian * 0.5f;
int maxSamples = 128; int maxSamples = 16;
for(int i = 0; i < maxSamples; i++){ for(int i = 0; i < maxSamples; i++){
vec3 samplePos = startPosition + d * direction; vec3 samplePos = startPosition + d * direction;
...@@ -149,7 +149,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t ...@@ -149,7 +149,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t
color += (1 - a) * voxelSample.rgb; color += (1 - a) * voxelSample.rgb;
a += (1 - a) * voxelSample.a; a += (1 - a) * voxelSample.a;
float minStepSize = 0.15; float minStepSize = 0.5f;
d += max(coneDiameter, minStepSize); d += max(coneDiameter, minStepSize);
samplePos = startPosition + d * direction; samplePos = startPosition + d * direction;
sampleUV = worldToVoxelCoordinates(samplePos, voxelInfo); sampleUV = worldToVoxelCoordinates(samplePos, voxelInfo);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment