mirror of
https://github.com/quantum5/punyverse.git
synced 2025-04-24 13:11:57 -04:00
Normal mapped the earth.
This commit is contained in:
parent
3f927427ae
commit
c3176ce7f6
Binary file not shown.
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 522 KiB |
|
@ -292,12 +292,16 @@ class SphericalBody(Body):
|
||||||
self.type = info.get('type', 'planet')
|
self.type = info.get('type', 'planet')
|
||||||
|
|
||||||
self.texture = get_best_texture(info['texture'])
|
self.texture = get_best_texture(info['texture'])
|
||||||
|
self.normal_texture = None
|
||||||
self.sphere = self._get_sphere(division, tangent=self.type == 'planet')
|
self.sphere = self._get_sphere(division, tangent=self.type == 'planet')
|
||||||
|
|
||||||
self.atmosphere = None
|
self.atmosphere = None
|
||||||
self.clouds = None
|
self.clouds = None
|
||||||
self.ring = 0
|
self.ring = 0
|
||||||
|
|
||||||
|
if 'normal_map' in info:
|
||||||
|
self.normal_texture = get_best_texture(info['normal_map'])
|
||||||
|
|
||||||
if 'atmosphere' in info:
|
if 'atmosphere' in info:
|
||||||
atmosphere_data = info['atmosphere']
|
atmosphere_data = info['atmosphere']
|
||||||
atm_size = world.evaluate(atmosphere_data.get('diffuse_size', None))
|
atm_size = world.evaluate(atmosphere_data.get('diffuse_size', None))
|
||||||
|
@ -333,10 +337,14 @@ class SphericalBody(Body):
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0)
|
glActiveTexture(GL_TEXTURE0)
|
||||||
glBindTexture(GL_TEXTURE_2D, self.texture)
|
glBindTexture(GL_TEXTURE_2D, self.texture)
|
||||||
shader.uniform_bool('u_planet.hasDiffuse', True)
|
|
||||||
shader.uniform_texture('u_planet.diffuseMap', 0)
|
shader.uniform_texture('u_planet.diffuseMap', 0)
|
||||||
|
|
||||||
shader.uniform_bool('u_planet.hasNormal', False)
|
shader.uniform_bool('u_planet.hasNormal', self.normal_texture)
|
||||||
|
if self.normal_texture:
|
||||||
|
glActiveTexture(GL_TEXTURE1)
|
||||||
|
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', False)
|
||||||
shader.uniform_bool('u_planet.hasEmission', False)
|
shader.uniform_bool('u_planet.hasEmission', False)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ in vec3 v_camDirection;
|
||||||
in mat3 v_TBN;
|
in mat3 v_TBN;
|
||||||
|
|
||||||
struct Surface {
|
struct Surface {
|
||||||
bool hasDiffuse;
|
|
||||||
sampler2D diffuseMap;
|
sampler2D diffuseMap;
|
||||||
bool hasNormal;
|
bool hasNormal;
|
||||||
sampler2D normalMap;
|
sampler2D normalMap;
|
||||||
|
@ -35,7 +34,7 @@ uniform Surface u_planet;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 normal = u_planet.hasNormal ? normalize(v_TBN * texture2D(u_planet.normalMap, v_uv).rgb * 2 - 1) : v_normal;
|
vec3 normal = u_planet.hasNormal ? normalize(v_TBN * texture2D(u_planet.normalMap, v_uv).rgb * 2 - 1) : v_normal;
|
||||||
vec3 diffuse = u_planet.hasDiffuse ? texture2D(u_planet.diffuseMap, v_uv).rgb : vec3(1);
|
vec3 diffuse = texture2D(u_planet.diffuseMap, v_uv).rgb;
|
||||||
vec3 specular = u_planet.hasSpecular ? texture2D(u_planet.specularMap, v_uv).rgb : vec3(1);
|
vec3 specular = u_planet.hasSpecular ? texture2D(u_planet.specularMap, v_uv).rgb : vec3(1);
|
||||||
vec3 emission = u_planet.hasEmission ? texture2D(u_planet.emissionMap, v_uv).rgb : vec3(1);
|
vec3 emission = u_planet.hasEmission ? texture2D(u_planet.emissionMap, v_uv).rgb : vec3(1);
|
||||||
|
|
||||||
|
|
|
@ -249,7 +249,7 @@ def load_clouds(file):
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
|
||||||
def get_best_texture(info, loader=load_texture, **kwargs):
|
def get_best_texture(info, loader=load_texture, optional=False, **kwargs):
|
||||||
if isinstance(info, list):
|
if isinstance(info, list):
|
||||||
for item in info:
|
for item in info:
|
||||||
try:
|
try:
|
||||||
|
@ -258,4 +258,5 @@ def get_best_texture(info, loader=load_texture, **kwargs):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return loader(info, **kwargs)
|
return loader(info, **kwargs)
|
||||||
raise ValueError('No texture found')
|
if not optional:
|
||||||
|
raise ValueError('No texture found')
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
"mass": 5.97219e+24,
|
"mass": 5.97219e+24,
|
||||||
"rotation": 86400,
|
"rotation": 86400,
|
||||||
"division": 90,
|
"division": 90,
|
||||||
"normal": "earth_normal.jpg",
|
"normal_map": ["earth_normal.jpg", "earth_normal_small.jpg"],
|
||||||
"atmosphere": {
|
"atmosphere": {
|
||||||
"cloud_texture": ["cloudmap.jpg", "cloudmap_small.jpg"],
|
"cloud_texture": ["cloudmap.jpg", "cloudmap_small.jpg"],
|
||||||
"diffuse_texture": "atmosphere_earth.png",
|
"diffuse_texture": "atmosphere_earth.png",
|
||||||
|
|
Loading…
Reference in a new issue