summaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 22:37:15 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-16 22:37:15 +1000
commit3c9d08717cd129c1576ea91e5bd4b7b8e0af9885 (patch)
tree3edc5e5013c64f41be7b96c96175d26adbf6e0c8 /assets
parent60d1e086242940993432a40a934241dc40b7382c (diff)
fix one silly issue
Diffstat (limited to 'assets')
-rw-r--r--assets/shaders/pbr_params.frag15
-rw-r--r--assets/shaders/pbr_params.vert1
2 files changed, 11 insertions, 5 deletions
diff --git a/assets/shaders/pbr_params.frag b/assets/shaders/pbr_params.frag
index 0833c2f..ae4c1d2 100644
--- a/assets/shaders/pbr_params.frag
+++ b/assets/shaders/pbr_params.frag
@@ -36,15 +36,19 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness);
void main() {
vec3 norm = normalize(fragNormal); // N
+ vec3 N = norm;
vec3 viewDir = normalize(vec3(scene.viewPos) - fragWorldPos); // V
+ vec3 V = viewDir;
vec3 F0 = vec3(0.04);
F0 = mix(F0, pbr.albedo, pbr.metallic);
- vec3 Lo = vec3(0.0); // denoted L in the radiance equation
- for (int i = 0; i < 4; i++) {
+ vec3 Lo = vec3(0.0);
+ for (int i = 0; i < 4; ++i) {
vec3 lightVec = normalize(vec3(scene.pointLights[i].position) - fragWorldPos); // L
+ vec3 L = lightVec;
vec3 halfway = normalize(viewDir + lightVec); // H
+ vec3 H = halfway;
float distance = length(vec3(scene.pointLights[i].position) - fragWorldPos);
float attenuation = 1.0 / (distance * distance);
vec3 radiance = vec3(scene.pointLights[i].color) * attenuation;
@@ -52,10 +56,11 @@ void main() {
// cook-torrance brdf
float NDF = DistributionGGX(norm, halfway, pbr.roughness);
float G = GeometrySmith(norm, viewDir, lightVec, pbr.roughness);
- vec3 F = fresnelSchlick(max(dot(halfway, viewDir), 0.0), F0);
+ // vec3 F = fresnelSchlick(max(dot(halfway, viewDir), 0.0), F0);
+ vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0);
vec3 numerator = NDF * G * F;
- float denominator = 4.0 * max(dot(norm, viewDir), 0.0) * max(dot(norm, lightVec), 0.0) + 0.0001;
+ float denominator = 4.0 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.0001;
vec3 specular = numerator / denominator;
vec3 kS = F;
@@ -64,7 +69,7 @@ void main() {
kD *= 1.0 - pbr.metallic;
// add to outgoing radiance Lo
- float NdotL = max(dot(norm, lightVec), 0.0);
+ float NdotL = max(dot(N, L), 0.0);
Lo += (kD * pbr.albedo / PI + specular) * radiance * NdotL;
// Lo += radiance;
}
diff --git a/assets/shaders/pbr_params.vert b/assets/shaders/pbr_params.vert
index 01d0cfe..40a6f29 100644
--- a/assets/shaders/pbr_params.vert
+++ b/assets/shaders/pbr_params.vert
@@ -20,6 +20,7 @@ layout(location = 2) out vec2 fragTexCoords;
void main() {
fragWorldPos = vec3(mvp.model * vec4(inPosition, 1.0));
fragNormal = mat3(transpose(inverse(mvp.model))) * inNormal;
+ // fragNormal = inNormal;
fragTexCoords = inTexCoords;