Adjust code to more properly reflect tutorial.

This commit is contained in:
Joey de Vries
2016-12-17 21:53:41 +01:00
parent ec42b25235
commit 70f2ec7c1b
2 changed files with 13 additions and 11 deletions

View File

@@ -88,10 +88,6 @@ void main()
// have no diffuse light). // have no diffuse light).
kD *= 1.0 - metallic; kD *= 1.0 - metallic;
// first do ambient lighting (note that the next IBL tutorial will replace
// this ambient lighting with environment lighting).
vec3 ambient = vec3(0.01) * albedo * ao;
// reflectance equation // reflectance equation
vec3 Lo = vec3(0.0); vec3 Lo = vec3(0.0);
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
@@ -117,6 +113,11 @@ void main()
// add to outgoing radiance Lo // add to outgoing radiance Lo
Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL; Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL;
} }
// ambient lighting (note that the next IBL tutorial will replace
// this ambient lighting with environment lighting).
vec3 ambient = vec3(0.01) * albedo * ao;
vec3 color = ambient + Lo; vec3 color = ambient + Lo;
// HDR tonemapping // HDR tonemapping

View File

@@ -25,7 +25,7 @@ const float PI = 3.14159265359;
// Don't worry if you don't get what's going on; you generally want to do normal // Don't worry if you don't get what's going on; you generally want to do normal
// mapping the usual way for performance anways; I do plan make a note of this // mapping the usual way for performance anways; I do plan make a note of this
// technique somewhere later in the normal mapping tutorial. // technique somewhere later in the normal mapping tutorial.
vec3 getNormal() vec3 getNormalFromMap()
{ {
vec3 tangentNormal = texture(normalMap, TexCoords).xyz * 2.0 - 1.0; vec3 tangentNormal = texture(normalMap, TexCoords).xyz * 2.0 - 1.0;
@@ -94,7 +94,7 @@ void main()
float roughness = texture(roughnessMap, TexCoords).r; float roughness = texture(roughnessMap, TexCoords).r;
float ao = texture(aoMap, TexCoords).r; float ao = texture(aoMap, TexCoords).r;
vec3 N = getNormal(); vec3 N = getNormalFromMap();
vec3 V = normalize(camPos - WorldPos); vec3 V = normalize(camPos - WorldPos);
vec3 R = reflect(-V, N); vec3 R = reflect(-V, N);
@@ -115,10 +115,6 @@ void main()
// have no diffuse light). // have no diffuse light).
kD *= 1.0 - metallic; kD *= 1.0 - metallic;
// first do ambient lighting (note that the next IBL tutorial will replace
// this ambient lighting with environment lighting).
vec3 ambient = vec3(0.01) * albedo * ao;
// reflectance equation // reflectance equation
vec3 Lo = vec3(0.0); vec3 Lo = vec3(0.0);
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
@@ -144,6 +140,11 @@ void main()
// add to outgoing radiance Lo // add to outgoing radiance Lo
Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL; Lo += (kD * albedo / PI + kS * brdf) * radiance * NdotL;
} }
// ambient lighting (note that the next IBL tutorial will replace
// this ambient lighting with environment lighting).
vec3 ambient = vec3(0.01) * albedo * ao;
vec3 color = ambient + Lo; vec3 color = ambient + Lo;
// HDR tonemapping // HDR tonemapping