Improve light reflections on water
This commit is contained in:
parent
b1b263b483
commit
129eefcc3e
5 changed files with 37 additions and 15 deletions
|
@ -48,13 +48,22 @@ void main() {
|
|||
float nDotVP = max(0.0, dot(normal, VP));
|
||||
float nDotHV = max(0.0, dot(normal, halfVector));
|
||||
|
||||
vec4 color = texture2D( color_tex, coords );
|
||||
vec4 Iamb = Ambient * color * att;
|
||||
vec4 Idiff = Diffuse * color * att * nDotVP;
|
||||
vec4 color_material = texture2D( color_tex, coords );
|
||||
vec3 color = color_material.rgb;
|
||||
vec3 Iamb = Ambient.rgb * color * att;
|
||||
vec3 Idiff = Diffuse.rgb * color * att * nDotVP;
|
||||
|
||||
float matID = color_material.a * 255.0;
|
||||
float spec_intensity = spec_emis.x;
|
||||
float spec_att = att;
|
||||
if (matID == 254.0) { // 254: water, 255: Ubershader
|
||||
spec_intensity = 1.0; // spec_color shouldn't depend on cloud cover when rendering spot light
|
||||
spec_att = min(10.0 * att, 1.0); // specular attenuation reduced on water
|
||||
}
|
||||
|
||||
vec3 Ispec = vec3(0.0);
|
||||
if (cosAngIncidence > 0.0)
|
||||
Ispec = pow( nDotHV, spec_emis.y * 128.0 ) * spec_emis.x * att * Specular.rgb;
|
||||
Ispec = pow( nDotHV, spec_emis.y * 128.0 ) * spec_intensity * spec_att * Specular.rgb;
|
||||
|
||||
gl_FragColor = vec4(Iamb.rgb + Idiff.rgb + Ispec, 1.0);
|
||||
gl_FragColor = vec4(Iamb + Idiff + Ispec, 1.0);
|
||||
}
|
||||
|
|
|
@ -60,13 +60,25 @@ void main() {
|
|||
float nDotVP = max(0.0, dot(normal, VP));
|
||||
float nDotHV = max(0.0, dot(normal, halfVector));
|
||||
|
||||
vec4 color = texture2D( color_tex, coords );
|
||||
vec4 Iamb = Ambient * color * att;
|
||||
vec4 Idiff = Diffuse * color * att * nDotVP;
|
||||
vec4 color_material = texture2D( color_tex, coords );
|
||||
vec3 color = color_material.rgb;
|
||||
vec3 Iamb = Ambient.rgb * color * att;
|
||||
vec3 Idiff = Diffuse.rgb * color * att * nDotVP;
|
||||
|
||||
float matID = color_material.a * 255.0;
|
||||
float spec_intensity = spec_emis.x;
|
||||
float spec_att = att;
|
||||
if (matID == 254.0) { // 254: water, 255: Ubershader
|
||||
spec_intensity = 1.0; // spec_color shouldn't depend on cloud cover when rendering spot light
|
||||
spec_att = min(10.0 * att, 1.0); // specular attenuation reduced on water
|
||||
}
|
||||
|
||||
vec3 Ispec = vec3(0.0);
|
||||
if (cosAngIncidence > 0.0)
|
||||
Ispec = pow( nDotHV, spec_emis.y * 128.0 ) * spec_emis.x * att * Specular.rgb;
|
||||
Ispec = pow( nDotHV, spec_emis.y * 128.0 ) * spec_intensity * spec_att * Specular.rgb;
|
||||
|
||||
gl_FragColor = vec4(Iamb.rgb + Idiff.rgb + Ispec, 1.0);
|
||||
if (matID >= 254.0)
|
||||
Idiff += Ispec * spec_emis.x;
|
||||
|
||||
gl_FragColor = vec4(Iamb + Idiff + Ispec, 1.0);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,8 @@ void main() {
|
|||
}
|
||||
vec3 lightDir = (fg_ViewMatrix * vec4( fg_SunDirection, 0.0 )).xyz;
|
||||
lightDir = normalize( lightDir );
|
||||
vec3 color = texture2D( color_tex, coords ).rgb;
|
||||
vec4 color_material = texture2D( color_tex, coords );
|
||||
vec3 color = color_material.rgb;
|
||||
vec3 Idiff = clamp( dot( lightDir, normal ), 0.0, 1.0 ) * color * fg_SunDiffuseColor.rgb;
|
||||
vec3 halfDir = normalize( lightDir - viewDir );
|
||||
vec3 Ispec = vec3(0.0);
|
||||
|
@ -97,8 +98,8 @@ void main() {
|
|||
if (cosAngIncidence > 0.0)
|
||||
Ispec = pow( blinnTerm, spec_emis.y * 128.0 ) * spec_emis.x * fg_SunSpecularColor.rgb;
|
||||
|
||||
float matID = texture2D( color_tex, coords ).a * 255.0;
|
||||
if (matID == 255.0)
|
||||
float matID = color_material.a * 255.0;
|
||||
if (matID >= 254.0) // 254: Water, 255: Ubershader
|
||||
Idiff += Ispec * spec_emis.x;
|
||||
|
||||
gl_FragColor = vec4(mix(vec3(0.0), Idiff + Ispec, shadow) + Iemis, 1.0);
|
||||
|
|
|
@ -207,5 +207,5 @@ void main(void)
|
|||
vec3( 0.3, 0.59, 0.11 )
|
||||
);
|
||||
float specular = smoothstep(0.0, 3.5, cover);
|
||||
encode_gbuffer(Normal, finalColor.rgb, 255, specular, 128, emission, gl_FragCoord.z);
|
||||
encode_gbuffer(Normal, finalColor.rgb, 254, specular, 128, emission, gl_FragCoord.z);
|
||||
}
|
||||
|
|
|
@ -379,5 +379,5 @@ void main(void)
|
|||
vec3( 0.3, 0.59, 0.11 )
|
||||
);
|
||||
float specular = smoothstep(0.0, 3.5, cover);
|
||||
encode_gbuffer(Normal, finalColor.rgb, 255, specular, water_shininess, emission, gl_FragCoord.z);
|
||||
encode_gbuffer(Normal, finalColor.rgb, 254, specular, water_shininess, emission, gl_FragCoord.z);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue