fixed background bug,

support directional light,
zoom speed can be adjust via +/-
This commit is contained in:
Anakin
2017-01-21 15:22:43 +01:00
parent 5ea90723b4
commit c4444bcefd
5 changed files with 49 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ left mouse - rotate
right mouse - move
scroll - zoom
space - reset view
+/- - adjust zoom speed
L - set light to current position
esc - close

View File

@@ -15,7 +15,7 @@ uniform bool b_transparent;
uniform bool b_light;
uniform struct Light {
vec3 position;
vec4 position;
vec3 intensities;
float attenuationFactor;
float ambientCoefficient;
@@ -31,11 +31,29 @@ void main()
{
// some values
vec3 normalWorld = normalize(n_matrix * v_surfaceNormal);
vec4 surfaceColor = vec4(texture2D(texture, v_surfaceUV));
surfaceColor.rgb = pow(surfaceColor.rgb, vec3(2.2));
if(!b_transparent)
surfaceColor.a = 1.0f;
vec3 surfaceToLight = normalize(light.position - v_surfacePosition);
vec3 surfaceToLight;
float attenuation;
// directional light
if(light.position.w == 0)
{
surfaceToLight = normalize(light.position.xyz);
attenuation = 1;
}
// point light
else
{
surfaceToLight = normalize(light.position.xyz - v_surfacePosition);
float distanceToLight = length(light.position.xyz - v_surfacePosition);
attenuation = 1.0 / (1.0 + light.attenuationFactor * pow(distanceToLight, 2));
}
vec3 surfaceToCamera = normalize(cameraPosition - v_surfacePosition);
// ambient
@@ -51,10 +69,6 @@ void main()
specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normalWorld))), materialShininess);
vec3 specular = specularCoefficient * materialSpecularColor * light.intensities;
// attenuation
float distanceToLight = length(light.position - v_surfacePosition);
float attenuation = 1.0 / (1.0 + light.attenuationFactor * pow(distanceToLight, 2));
// linear color before gamma correction)
vec3 linearColor = ambient + attenuation * (diffuse + specular);