Make blinn and phong specular use full pbr

This commit is contained in:
clayjohn 2021-08-08 14:02:45 -07:00
parent 41cf7f2760
commit f92a600d5c
2 changed files with 21 additions and 20 deletions

View file

@ -275,13 +275,13 @@ void light_compute(
vec3 H = normalize(V + L); vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0); float cNdotH = max(dot(N, H), 0.0);
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL; float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn; specular_brdf_NL = blinn;
#endif #endif
SRGB_APPROX(specular_brdf_NL) SRGB_APPROX(specular_brdf_NL)
specular_interp += specular_brdf_NL * light_color * attenuation * (1.0 / M_PI); specular_interp += specular_brdf_NL * light_color * attenuation;
} }
} }
@ -1360,7 +1360,7 @@ LIGHT_SHADER_CODE
if (roughness > 0.0) { if (roughness > 0.0) {
#if defined(SPECULAR_SCHLICK_GGX) #if defined(SPECULAR_SCHLICK_GGX) || defined(SPECULAR_BLINN) || defined(SPECULAR_PHONG)
vec3 specular_brdf_NL = vec3(0.0); vec3 specular_brdf_NL = vec3(0.0);
#else #else
float specular_brdf_NL = 0.0; float specular_brdf_NL = 0.0;
@ -1370,9 +1370,10 @@ LIGHT_SHADER_CODE
//normalized blinn //normalized blinn
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL; float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn;
specular_brdf_NL = blinn * diffuse_color * specular;
#elif defined(SPECULAR_PHONG) #elif defined(SPECULAR_PHONG)
@ -1380,8 +1381,9 @@ LIGHT_SHADER_CODE
float cRdotV = max(0.0, dot(R, V)); float cRdotV = max(0.0, dot(R, V));
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float phong = pow(cRdotV, shininess); float phong = pow(cRdotV, shininess);
phong *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); phong *= (shininess + 1.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
specular_brdf_NL = phong * diffuse_color * specular;
#elif defined(SPECULAR_TOON) #elif defined(SPECULAR_TOON)
@ -2165,8 +2167,7 @@ FRAGMENT_SHADER_CODE
#ifdef USE_VERTEX_LIGHTING #ifdef USE_VERTEX_LIGHTING
//vertex lighting //vertex lighting
specular_light += specular_interp * albedo * specular * specular_blob_intensity * light_att;
specular_light += specular_interp * specular_blob_intensity * light_att;
diffuse_light += diffuse_interp * albedo * light_att; diffuse_light += diffuse_interp * albedo * light_att;
#else #else

View file

@ -225,12 +225,12 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float roughness, in
vec3 H = normalize(V + L); vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0); float cNdotH = max(dot(N, H), 0.0);
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL; float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn; specular_brdf_NL = blinn;
#endif #endif
specular += specular_brdf_NL * light_color * (1.0 / M_PI); specular += specular_brdf_NL * light_color;
} }
} }
@ -1122,11 +1122,11 @@ LIGHT_SHADER_CODE
//normalized blinn //normalized blinn
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL; float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI)); // Normalized NDF and Geometric term
float intensity = blinn; float intensity = blinn;
specular_light += light_color * intensity * specular_blob_intensity * attenuation; specular_light += light_color * intensity * specular_blob_intensity * attenuation * diffuse_color * specular;
#elif defined(SPECULAR_PHONG) #elif defined(SPECULAR_PHONG)
@ -1134,10 +1134,10 @@ LIGHT_SHADER_CODE
float cRdotV = max(0.0, dot(R, V)); float cRdotV = max(0.0, dot(R, V));
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25; float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float phong = pow(cRdotV, shininess); float phong = pow(cRdotV, shininess);
phong *= (shininess + 8.0) * (1.0 / (8.0 * M_PI)); phong *= (shininess + 1.0) * (1.0 / (8.0 * M_PI)); // Normalized NDF and Geometric term
float intensity = (phong) / max(4.0 * cNdotV * cNdotL, 0.75); float intensity = phong;
specular_light += light_color * intensity * specular_blob_intensity * attenuation; specular_light += light_color * intensity * specular_blob_intensity * attenuation * diffuse_color * specular;
#elif defined(SPECULAR_TOON) #elif defined(SPECULAR_TOON)