Skip to content

Commit

Permalink
Merge pull request #51410 from clayjohn/GLES-blinn-phong
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Aug 10, 2021
2 parents ef0dff3 + f92a600 commit 6518a61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
23 changes: 12 additions & 11 deletions drivers/gles2/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ void light_compute(
vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0);
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL;
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn;
#endif

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;
}
}

Expand Down Expand Up @@ -1365,7 +1365,7 @@ LIGHT_SHADER_CODE

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);
#else
float specular_brdf_NL = 0.0;
Expand All @@ -1375,18 +1375,20 @@ LIGHT_SHADER_CODE

//normalized blinn
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL;
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn;
float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));

specular_brdf_NL = blinn * diffuse_color * specular;

#elif defined(SPECULAR_PHONG)

vec3 R = normalize(-reflect(L, N));
float cRdotV = max(0.0, dot(R, V));
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float phong = pow(cRdotV, shininess);
phong *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
phong *= (shininess + 1.0) * (1.0 / (8.0 * M_PI));

specular_brdf_NL = phong * diffuse_color * specular;

#elif defined(SPECULAR_TOON)

Expand Down Expand Up @@ -2170,8 +2172,7 @@ FRAGMENT_SHADER_CODE

#ifdef USE_VERTEX_LIGHTING
//vertex lighting

specular_light += specular_interp * specular_blob_intensity * light_att;
specular_light += specular_interp * albedo * specular * specular_blob_intensity * light_att;
diffuse_light += diffuse_interp * albedo * light_att;

#else
Expand Down
18 changes: 9 additions & 9 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, float roughness, in
vec3 H = normalize(V + L);
float cNdotH = max(dot(N, H), 0.0);
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL;
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI));
specular_brdf_NL = blinn;
#endif

specular += specular_brdf_NL * light_color * (1.0 / M_PI);
specular += specular_brdf_NL * light_color;
}
}

Expand Down Expand Up @@ -1127,22 +1127,22 @@ LIGHT_SHADER_CODE

//normalized blinn
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float blinn = pow(cNdotH, shininess) * cNdotL;
blinn *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
float blinn = pow(cNdotH, shininess);
blinn *= (shininess + 2.0) * (1.0 / (8.0 * M_PI)); // Normalized NDF and Geometric term
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)

vec3 R = normalize(-reflect(L, N));
float cRdotV = max(0.0, dot(R, V));
float shininess = exp2(15.0 * (1.0 - roughness) + 1.0) * 0.25;
float phong = pow(cRdotV, shininess);
phong *= (shininess + 8.0) * (1.0 / (8.0 * M_PI));
float intensity = (phong) / max(4.0 * cNdotV * cNdotL, 0.75);
phong *= (shininess + 1.0) * (1.0 / (8.0 * M_PI)); // Normalized NDF and Geometric term
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)

Expand Down

0 comments on commit 6518a61

Please sign in to comment.