Graphics/Shaders: Fix point and spot lights in PhysicallyBasedMaterial
This commit is contained in:
parent
5a96ab3bf7
commit
f46f0da12a
|
|
@ -50,15 +50,15 @@ fn FresnelSchlick(cosTheta: f32, F0: vec3[f32]) -> vec3[f32]
|
|||
}
|
||||
|
||||
[export]
|
||||
fn ComputeLightRadiance(lightColor: vec3[f32], lightDir: vec3[f32], lightAttenuation: f32, albedoFactor: vec3[f32], eyeVec: vec3[f32], F0: vec3[f32], normal: vec3[f32], metallic: f32, roughness: f32) -> vec3[f32]
|
||||
fn ComputeLightRadiance(lightColor: vec3[f32], posToLight: vec3[f32], lightAttenuation: f32, albedoFactor: vec3[f32], eyeVec: vec3[f32], F0: vec3[f32], normal: vec3[f32], metallic: f32, roughness: f32) -> vec3[f32]
|
||||
{
|
||||
let radiance = lightColor * lightAttenuation;
|
||||
|
||||
let halfDir = normalize(lightDir + eyeVec);
|
||||
let halfDir = normalize(posToLight + eyeVec);
|
||||
|
||||
// Cook-Torrance BRDF
|
||||
let NDF = DistributionGGX(normal, halfDir, roughness);
|
||||
let G = GeometrySmith(normal, eyeVec, lightDir, roughness);
|
||||
let G = GeometrySmith(normal, eyeVec, posToLight, roughness);
|
||||
let F = FresnelSchlick(max(dot(halfDir, eyeVec), 0.0), F0);
|
||||
|
||||
let kS = F;
|
||||
|
|
@ -66,9 +66,9 @@ fn ComputeLightRadiance(lightColor: vec3[f32], lightDir: vec3[f32], lightAttenua
|
|||
diffuse *= 1.0 - metallic;
|
||||
|
||||
let numerator = NDF * G * F;
|
||||
let denominator = 4.0 * max(dot(normal, eyeVec), 0.0) * max(dot(normal, lightDir), 0.0);
|
||||
let denominator = 4.0 * max(dot(normal, eyeVec), 0.0) * max(dot(normal, posToLight), 0.0);
|
||||
let specular = numerator / max(denominator, 0.0001);
|
||||
|
||||
let NdotL = max(dot(normal, lightDir), 0.0);
|
||||
let NdotL = max(dot(normal, posToLight), 0.0);
|
||||
return (diffuse * albedoFactor + specular) * radiance * NdotL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
|
|||
let lightToPosNorm = lightToPos / max(dist, 0.0001);
|
||||
|
||||
let shadowFactor = ComputePointLightShadow(light, shadowMapsPoint[lightIndex], dist, lightToPosNorm);
|
||||
let radiance = ComputeLightRadiance(light.color.rgb, lightToPosNorm, attenuation, albedoFactor, eyeVec, F0, normal, metallic, roughness);
|
||||
let radiance = ComputeLightRadiance(light.color.rgb, -lightToPosNorm, attenuation, albedoFactor, eyeVec, F0, normal, metallic, roughness);
|
||||
|
||||
lightRadiance += shadowFactor * radiance;
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ fn ComputeLighting(color: vec3[f32], input: VertOut) -> vec3[f32]
|
|||
let lambert = clamp(dot(normal, -lightToPosNorm), 0.0, 1.0);
|
||||
|
||||
let shadowFactor = ComputeSpotLightShadow(light, shadowMapsSpot[lightIndex], input.worldPos, lambert);
|
||||
let radiance = ComputeLightRadiance(light.color.rgb, lightToPosNorm, attenuation, albedoFactor, eyeVec, F0, normal, metallic, roughness);
|
||||
let radiance = ComputeLightRadiance(light.color.rgb, -lightToPosNorm, attenuation, albedoFactor, eyeVec, F0, normal, metallic, roughness);
|
||||
|
||||
lightRadiance += shadowFactor * radiance;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue