diff --git a/projects/voxelization/resources/shaders/shader.frag b/projects/voxelization/resources/shaders/shader.frag index 990c8f90df0c32175e526cd34ec1241db4cd435d..42605c17d69724773a1090a6c7ca2800f2c5e078 100644 --- a/projects/voxelization/resources/shaders/shader.frag +++ b/projects/voxelization/resources/shaders/shader.frag @@ -50,6 +50,12 @@ float roughnessToConeAngle(float 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() { vec3 albedoTexel = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb; @@ -95,6 +101,7 @@ void main() { vec3 R = reflect(-V, N); float reflectionConeAngle = degreeToRadian(roughnessToConeAngle(r)); vec3 offsetTraceStart = passPos + N_geo * 0.1f; + offsetTraceStart += R * interleavedGradientNoise(gl_FragCoord.xy) * 0.5; vec3 specularTrace = voxelConeTrace(R, offsetTraceStart, reflectionConeAngle, voxelTexture, voxelSampler, voxelInfo); specularTrace *= clamp(dot(N, R), 0, 1); vec3 reflectionBRDF = cookTorrance(f0, r, N, V, R); diff --git a/projects/voxelization/resources/shaders/voxel.inc b/projects/voxelization/resources/shaders/voxel.inc index 825fb241fc367a7d3d7f0ab7d48b396278fedf93..8e3fcfb69773333fc5238ecddb6ecb729b792c0b 100644 --- a/projects/voxelization/resources/shaders/voxel.inc +++ b/projects/voxelization/resources/shaders/voxel.inc @@ -130,7 +130,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t float coneAngleHalf = coneAngleRadian * 0.5f; - int maxSamples = 128; + int maxSamples = 16; for(int i = 0; i < maxSamples; i++){ vec3 samplePos = startPosition + d * direction; @@ -149,7 +149,7 @@ vec3 voxelConeTrace(vec3 direction, vec3 startPosition, float coneAngleRadian, t color += (1 - a) * voxelSample.rgb; a += (1 - a) * voxelSample.a; - float minStepSize = 0.15; + float minStepSize = 0.5f; d += max(coneDiameter, minStepSize); samplePos = startPosition + d * direction; sampleUV = worldToVoxelCoordinates(samplePos, voxelInfo);