mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Add specular mapping.
This commit is contained in:
parent
600f90175c
commit
4ebcc7e2d7
|
@ -5,6 +5,7 @@ mercury.jpg
|
|||
earth.jpg
|
||||
earth_normal.jpg
|
||||
earth_emission.jpg
|
||||
earth_specular.jpg
|
||||
cloudmap.jpg
|
||||
moon.jpg
|
||||
mars.jpg
|
||||
|
|
BIN
punyverse/assets/textures/earth_specular.jpg
Normal file
BIN
punyverse/assets/textures/earth_specular.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
|
@ -293,6 +293,7 @@ class SphericalBody(Body):
|
|||
|
||||
self.texture = get_best_texture(info['texture'])
|
||||
self.normal_texture = None
|
||||
self.specular_texture = None
|
||||
self.emission_texture = None
|
||||
self.sphere = self._get_sphere(division, tangent=self.type == 'planet')
|
||||
|
||||
|
@ -303,6 +304,9 @@ class SphericalBody(Body):
|
|||
if 'normal_map' in info:
|
||||
self.normal_texture = get_best_texture(info['normal_map'])
|
||||
|
||||
if 'specular_map' in info:
|
||||
self.specular_texture = get_best_texture(info['specular_map'])
|
||||
|
||||
if 'emission_map' in info:
|
||||
self.emission_texture = get_best_texture(info['emission_map'])
|
||||
|
||||
|
@ -349,7 +353,16 @@ class SphericalBody(Body):
|
|||
glBindTexture(GL_TEXTURE_2D, self.normal_texture)
|
||||
shader.uniform_texture('u_planet.normalMap', 1)
|
||||
|
||||
shader.uniform_bool('u_planet.hasSpecular', False)
|
||||
shader.uniform_bool('u_planet.hasSpecular', self.specular_texture)
|
||||
if self.specular_texture:
|
||||
glActiveTexture(GL_TEXTURE2)
|
||||
glBindTexture(GL_TEXTURE_2D, self.emission_texture)
|
||||
shader.uniform_texture('u_planet.specularMap', 2)
|
||||
shader.uniform_vec3('u_planet.specular', 2, 2, 2)
|
||||
shader.uniform_float('u_planet.shininess', 5)
|
||||
else:
|
||||
shader.uniform_vec3('u_planet.specular', 0, 0, 0)
|
||||
shader.uniform_float('u_planet.shininess', 0)
|
||||
|
||||
shader.uniform_bool('u_planet.hasEmission', self.emission_texture)
|
||||
if self.emission_texture:
|
||||
|
@ -363,9 +376,6 @@ class SphericalBody(Body):
|
|||
shader.uniform_vec3('u_planet.emission', 0, 0, 0)
|
||||
|
||||
shader.uniform_vec3('u_planet.diffuse', 1, 1, 1)
|
||||
shader.uniform_vec3('u_planet.specular', 0, 0, 0)
|
||||
|
||||
shader.uniform_float('u_planet.shininess', 0)
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, self.sphere.vbo)
|
||||
shader.vertex_attribute('a_normal', self.sphere.direction_size, self.sphere.type, GL_FALSE,
|
||||
|
|
|
@ -39,18 +39,15 @@ void main() {
|
|||
vec3 emission = u_planet.hasEmission ? texture2D(u_planet.emissionMap, v_uv).rgb : vec3(1);
|
||||
|
||||
vec3 incident = normalize(u_sun.position - v_position);
|
||||
vec3 reflected = normalize(-reflect(incident, normal));
|
||||
vec3 reflected = normalize(reflect(-incident, normal));
|
||||
|
||||
float diffuseIntensity = max(dot(normal, incident), 0.0);
|
||||
float shininess = pow(clamp(dot(normalize(v_camDirection), reflected), 0.0, 1.0), u_planet.shininess);
|
||||
float shininess = pow(max(dot(normalize(v_camDirection), reflected), 0), u_planet.shininess);
|
||||
|
||||
vec3 ambient = u_planet.ambient * u_sun.ambient * diffuse;
|
||||
diffuse *= u_planet.diffuse * u_sun.diffuse * diffuseIntensity;
|
||||
emission *= u_planet.emission * (1 - min(diffuseIntensity * 2, 1));
|
||||
if (u_planet.shininess > 0)
|
||||
specular *= u_planet.specular * u_sun.specular * clamp(shininess, 0, 1);
|
||||
else
|
||||
specular = vec3(0);
|
||||
specular *= u_planet.specular * u_sun.specular * max(shininess, 0);
|
||||
|
||||
gl_FragColor = vec4((ambient + diffuse + emission + specular) * u_sun.intensity, 1);
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
"rotation": 86400,
|
||||
"division": 90,
|
||||
"normal_map": ["earth_normal.jpg", "earth_normal_small.jpg"],
|
||||
"specular_map": ["earth_specular.jpg", "earth_specular_small.jpg"],
|
||||
"emission_map": ["earth_emission.jpg", "earth_emission_medium.jpg", "earth_emission_small.jpg"],
|
||||
"atmosphere": {
|
||||
"cloud_texture": ["cloudmap.jpg", "cloudmap_small.jpg"],
|
||||
|
|
|
@ -49,7 +49,7 @@ class World(object):
|
|||
shader = self.activate_shader('planet')
|
||||
shader.uniform_vec3('u_sun.ambient', 0.1, 0.1, 0.1)
|
||||
shader.uniform_vec3('u_sun.diffuse', 1, 1, 1)
|
||||
shader.uniform_vec3('u_sun.specular', 0.5, 0.5, 0.5)
|
||||
shader.uniform_vec3('u_sun.specular', 1, 1, 1)
|
||||
shader.uniform_vec3('u_sun.position', 0, 0, 0)
|
||||
shader.uniform_float('u_sun.intensity', 1)
|
||||
self.activate_shader(None)
|
||||
|
|
Loading…
Reference in a new issue