Skip to content
Snippets Groups Projects

Resolve "Voxel cone tracing"

Merged Ghost User requested to merge 82-voxel-cone-tracing into develop
2 files
+ 66
6
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -19,13 +19,50 @@ layout(set=0, binding=0) uniform sunBuffer {
layout(set=0, binding=1) uniform texture2D shadowMap;
layout(set=0, binding=2) uniform sampler shadowMapSampler;
layout(set=0, binding=3) uniform cameraBuffer {
vec3 cameraPos;
};
const float pi = 3.1415;
vec3 lambertBRDF(vec3 albedo){
return albedo / pi;
}
vec3 fresnelSchlick(float cosTheta, vec3 f0){
return f0 + (vec3(1) - f0) * pow(1 - cosTheta, 5);
}
float GGXDistribution(float r, float NoH){
float r2 = r * r;
float denom = pi * pow(NoH * NoH * (r2 - 1) + 1, 2);
return r2 / max(denom, 0.000001);
}
float GGXSmithShadowingPart(float r, float cosTheta){
float nom = cosTheta * 2;
float r2 = r * r;
float denom = cosTheta + sqrt(r2 + (1 - r2) * cosTheta * cosTheta);
return nom / max(denom, 0.000001);
}
float GGXSmithShadowing(float r, float NoV, float NoL){
return GGXSmithShadowingPart(r, NoV) * GGXSmithShadowingPart(r, NoL);
}
void main() {
vec3 albedoTexel = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
vec3 normalTexel = texture(sampler2D(normalTexture, textureSampler), passUV).rgb;
vec3 specularTexel = texture(sampler2D(specularTexture, textureSampler), passUV).rgb;
vec3 albedo = albedoTexel;
float r = specularTexel.g;
r *= r; // remapping roughness for perceptual linearity
float metal = specularTexel.b;
vec3 albedo = mix(albedoTexel, vec3(0), metal);
vec3 f0_dielectric = vec3(0.04f);
vec3 f0 = mix(f0_dielectric, albedo, metal);
vec3 T = normalize(passTangent.xyz);
vec3 N_geo = normalize(passNormal);
@@ -33,9 +70,27 @@ void main() {
mat3 TBN = mat3(T, B, N_geo);
normalTexel = normalTexel * 2 - 1;
vec3 N = TBN * normalTexel;
vec3 sun = lightInfo.sunStrength * lightInfo.sunColor * clamp(dot(N, lightInfo.L), 0, 1);
vec3 N = TBN * normalTexel;
vec3 L = lightInfo.L;
vec3 V = normalize(cameraPos - passPos);
vec3 H = normalize(L + V);
float NoH = clamp(dot(N, H), 0, 1);
float NoL = clamp(dot(N, L), 0, 1);
float NoV = clamp(dot(N, V), 0, 1);
vec3 F = fresnelSchlick(NoH, f0);
float D = GGXDistribution(r, NoH);
float G = GGXSmithShadowing(r, NoV, NoL);
vec3 specular = (F * D * G) / max(4 * NoV * NoL, 0.000001);
vec3 sun = lightInfo.sunStrength * lightInfo.sunColor * NoL;
sun *= shadowTest(passPos, lightInfo, shadowMap, shadowMapSampler);
vec3 ambient = vec3(0.05);
outColor = albedo * (sun + ambient);
vec3 F_in = fresnelSchlick(NoL, f0);
vec3 F_out = fresnelSchlick(NoV, f0);
vec3 diffuse = lambertBRDF(albedo) * (1 - F_in) * (1 - F_out);
outColor = (diffuse + specular) * sun + lambertBRDF(albedo) * ambient;
}
\ No newline at end of file
Loading