47 lines
1.2 KiB
GLSL
47 lines
1.2 KiB
GLSL
#define EARTH
|
|
varying vec3 vViewPosition;
|
|
varying vec3 vLightDirection;
|
|
varying vec2 vUv;
|
|
varying vec3 vEyeNormal;
|
|
|
|
uniform vec3 diffuse;
|
|
uniform vec3 emissive;
|
|
uniform vec3 specular;
|
|
uniform float shininess;
|
|
uniform float opacity;
|
|
|
|
uniform sampler2D texture0;
|
|
uniform sampler2D texture1;
|
|
uniform sampler2D specularMap;
|
|
|
|
#include <common>
|
|
#include <packing>
|
|
#include <normal_pars_fragment>
|
|
#include <normalmap_pars_fragment>
|
|
|
|
void main() {
|
|
vec4 sampledDiffuseColor = texture2D(texture0, vUv);
|
|
vec4 sampledDiffuseColorNight = texture2D(texture1, vUv);
|
|
|
|
vec3 N = normalize(vEyeNormal);
|
|
vec3 L = normalize(vLightDirection);
|
|
vec3 V = normalize(vViewPosition);
|
|
vec3 H = normalize(V + L);
|
|
|
|
float diffuseAngle = dot(N, L);
|
|
float specularAngle = dot(N, H);
|
|
|
|
float cosineAngleSunToNormal = clamp( diffuseAngle * 10.0, -1.0, 1.0);
|
|
float mixAmount = cosineAngleSunToNormal * 0.5 + 0.5;
|
|
|
|
vec4 texelSpecular = texture2D(specularMap, vUv);
|
|
float specularStrength = texelSpecular.r;
|
|
|
|
vec3 outgoingLight = mix(sampledDiffuseColorNight.xyz, sampledDiffuseColor.xyz, mixAmount);
|
|
|
|
float specularAmount = max(0.0, specularAngle);
|
|
specularAmount = pow(specularAmount, 32.0 * shininess) * specularStrength;
|
|
|
|
gl_FragColor = vec4( outgoingLight + specular * specularAmount, 1.0 );
|
|
}
|