]> marstr Code Repo - orthographic/commitdiff
Improved building rendering by adding subtle details to make residential areas look...
authormarstr <marcus@marstr.online>
Tue, 3 Sep 2024 13:57:58 +0000 (15:57 +0200)
committermarstr <marcus@marstr.online>
Tue, 3 Sep 2024 13:57:58 +0000 (15:57 +0200)
13 files changed:
Textures/building/area/p1.png [new file with mode: 0644]
Textures/building/area/p10.png [new file with mode: 0644]
Textures/building/area/p2.png [new file with mode: 0644]
Textures/building/area/p3.png [new file with mode: 0644]
Textures/building/area/p4.png [new file with mode: 0644]
Textures/building/area/p5.png [new file with mode: 0644]
Textures/building/area/p6.png [new file with mode: 0644]
Textures/building/area/p7.png [new file with mode: 0644]
Textures/building/area/p8.png [new file with mode: 0644]
Textures/building/area/p9.png [new file with mode: 0644]
defines.py
layergen.py
maskgen.py

diff --git a/Textures/building/area/p1.png b/Textures/building/area/p1.png
new file mode 100644 (file)
index 0000000..1fa88ad
Binary files /dev/null and b/Textures/building/area/p1.png differ
diff --git a/Textures/building/area/p10.png b/Textures/building/area/p10.png
new file mode 100644 (file)
index 0000000..a3ba287
Binary files /dev/null and b/Textures/building/area/p10.png differ
diff --git a/Textures/building/area/p2.png b/Textures/building/area/p2.png
new file mode 100644 (file)
index 0000000..65d22b5
Binary files /dev/null and b/Textures/building/area/p2.png differ
diff --git a/Textures/building/area/p3.png b/Textures/building/area/p3.png
new file mode 100644 (file)
index 0000000..b1deab4
Binary files /dev/null and b/Textures/building/area/p3.png differ
diff --git a/Textures/building/area/p4.png b/Textures/building/area/p4.png
new file mode 100644 (file)
index 0000000..b353bda
Binary files /dev/null and b/Textures/building/area/p4.png differ
diff --git a/Textures/building/area/p5.png b/Textures/building/area/p5.png
new file mode 100644 (file)
index 0000000..c80fd1d
Binary files /dev/null and b/Textures/building/area/p5.png differ
diff --git a/Textures/building/area/p6.png b/Textures/building/area/p6.png
new file mode 100644 (file)
index 0000000..b7c5235
Binary files /dev/null and b/Textures/building/area/p6.png differ
diff --git a/Textures/building/area/p7.png b/Textures/building/area/p7.png
new file mode 100644 (file)
index 0000000..46fe2a2
Binary files /dev/null and b/Textures/building/area/p7.png differ
diff --git a/Textures/building/area/p8.png b/Textures/building/area/p8.png
new file mode 100644 (file)
index 0000000..17fdfbb
Binary files /dev/null and b/Textures/building/area/p8.png differ
diff --git a/Textures/building/area/p9.png b/Textures/building/area/p9.png
new file mode 100644 (file)
index 0000000..27fb771
Binary files /dev/null and b/Textures/building/area/p9.png differ
index da726cceb8210050f55235ba0ddcdac000dd00e7..2508c909b4a94b33135dc9ade84c5e0eab9b65a6 100644 (file)
@@ -139,6 +139,7 @@ mstr_ortho_layers = [
     # Z-Order 5
     ("aeroway", "taxiway", 42),
     ("aeroway", "runway", 80),
+    ("building", "detached", "building", "common"),
     ("building", "church", "building", "common"),
     ("building", "hotel", "building", "industrial"),
     ("building", "farm", "building", "industrial"),
@@ -151,6 +152,8 @@ mstr_ortho_layers = [
     ("building", "industrial", "building", "industrial"),
     ("building", "house", "building", "house"),
     ("building", "terrace", "building", "industrial"),
+    ("building", "hangar", "building", "industrial"),
+    ("building", "school", "building", "common"),
     ("building", "yes", "building", "common")
 ]
 
@@ -213,6 +216,7 @@ mstr_mask_blur = [
     # Z-Order 5
     ("aeroway", "taxiway", 12),
     ("aeroway", "runway", 12),
+    ("building", "detached", 1),
     ("building", "church", 1),
     ("building", "hotel", 1),
     ("building", "farm", 1),
@@ -225,5 +229,7 @@ mstr_mask_blur = [
     ("building", "industrial", 1),
     ("building", "house", 1),
     ("building", "terrace", 1),
+    ("building", "hangar", 1),
+    ("building", "school", 1),
     ("building", "yes", 1)
 ]
index bb805590ed81c310ce5cd79a643572e2c69e2369..1f482e61dc5068eaf6d10dbe72b389987b5af6a1 100644 (file)
@@ -134,7 +134,7 @@ class mstr_layergen:
         # There are some things we need to use sources for, and some things, we do not.
         # We need to differentiate that.
 
-        if (self._isline == False) or (self._is_completion == True):
+        if (self._isline == False and self._tag != "building") or (self._is_completion == True):
             # Determine where we get the our source material from
             root_folder = mstr_datafolder + "Textures\\"
             for s in mstr_ortho_layers:
@@ -371,16 +371,10 @@ class mstr_layergen:
                     ptc = randrange(1, 14)
                     img = Image.open(mstr_datafolder + "Textures\\tile\\completion\\p" + str(ptc)+".png")
                     lx = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width ) 
-                    ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width )
+                    ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.height )
                     layer.alpha_composite( img, (lx, ly) )
 
 
-            # Let's do something nice with buildings
-            if self._tag == "building":
-                osm_edge = osm_edge.filter(ImageFilter.GaussianBlur(radius=3))
-                layer.alpha_composite(osm_edge)
-
-
             # We now need to add the seamless border
             layer.alpha_composite( brd_src )
             mstr_msg("layergen", "Layer image completed")
@@ -517,7 +511,7 @@ class mstr_layergen:
 
         # If we encounter one of these road-specific tags, we need to proceed differently.
 
-        if self._isline == True:
+        if self._isline == True or self._tag == "building":
 
             # We will need the mask in question
             osm_mask = Image.open( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
@@ -543,6 +537,35 @@ class mstr_layergen:
             mask_pix = osm_mask.load()
             edge_pix = osm_edge.load()
             layer_comp_pix = layer_comp.load()
+
+            # Let's define some base color ranges for different types of buildings
+            bld_clr = [
+                ("detached",           190, 192, 195), 
+                ("church",             134, 134, 136), 
+                ("hotel",              153, 147, 138), 
+                ("farm",               145, 124, 121), 
+                ("semidetached_house", 167, 163, 152), 
+                ("apartments",         129, 134, 127), 
+                ("civic",              134, 134, 136), 
+                ("garage",             101, 109, 111),
+                ("office",             139, 152, 156),
+                ("retail",             121, 122, 108),
+                ("industrial",         191, 192, 187),
+                ("house",              145, 124, 121),
+                ("terrace",            191, 192, 187),
+                ("hangar",             137, 162, 195),
+                ("school",             111, 117, 115),
+                ("yes",                152, 144, 141)
+            ]
+
+            # Find the color index to work with
+            cidx = 0
+            if self._tag == "building":
+                for c in bld_clr:
+                    if c[0] == self._value:
+                        break
+                    cidx = cidx+1
+
             for y in range(self._imgsize):
                 for x in range(self._imgsize):
                     if mask_pix[x, y][3] > 0:
@@ -579,29 +602,16 @@ class mstr_layergen:
                             t = a[3]-d
                             if t < 0: t = 0
                             layer_comp_pix[x, y] = ( mats[pick-1][0], mats[pick-1][1], mats[pick-1][2], t )
+                        
+                        # A bit special here
                         if self._tag == "building":
-                            r = randrange(1, 20)
                             
-                            if self._value == "yes":
-                                d = (116-r, 117-r,135-r)
-                                layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
-                                if e[3] > 0:
-                                    b = (96-r, 97-r, 115-r)
-                                    layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
-
-                            if self._value == "office" or self._value == "retail":
-                                d = (100-r, 100-r, 100-r)
-                                layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
-                                if e[3] > 0:
-                                    b = (80-r, 80-r, 80-r)
-                                    layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
-
-                            if self._value == "industrial":
-                                d = (166-r, 170-r, 175-r)
-                                layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
-                                if e[3] > 0:
-                                    b = (146-r, 150-r, 155-r)
-                                    layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
+                            # Find a color range
+                            d = randrange(1,21)
+                            # Adjust this pixel
+                            c = (bld_clr[cidx][1]-d, bld_clr[cidx][2]-d, bld_clr[cidx][3]-d, 255)
+                            # Set pixel
+                            layer_comp_pix[x, y] = c                            
                             
                         if self._value == "track" or self._value == "path":
                             d = randrange(1,20)
@@ -610,6 +620,64 @@ class mstr_layergen:
                             b = 138  - d
                             layer_comp_pix[x, y] = ( r,g,b,a[3] )
 
+            # We will do some super magic here to let houses look more realistic
+            if self._tag == "building":
+                vls = [ "detached", "hotel", "farm", "semidetached_house", "apartments", "civic", "office", "retail", "industrial", "house", "school" ]
+                if self._value in vls:
+                    # Generate a new image
+                    details = Image.new("RGBA", (self._imgsize, self._imgsize))
+                    details_pix = details.load()
+                    layer_pix = layer_comp.load()
+                    for y in range(self._imgsize-1):
+                        for x in range(self._imgsize-1):
+                            p = layer_pix[x,y]
+                            if p[3] > 0:
+                                shf_x = x+randrange(1, 21)
+                                shf_y = y+randrange(1, 21)
+                                shf_x2 = x-randrange(1, 21)
+                                shf_y2 = y-randrange(1, 21)
+                                if shf_x <= self._imgsize-1 and shf_x >= 0 and shf_y <= self._imgsize-1 and shf_y >= 0:
+                                    st = random.uniform(0.85, 1.0)
+                                    ca = 255 * st
+                                    aa = int(ca)
+                                    d = randrange(1,26)
+                                    d2 = randrange(1,26)
+                                    details_pix[shf_x, shf_y] = (187-d, 179-d, 176-d, aa)
+                                    details_pix[shf_x2, shf_y2] = (187-d2, 179-d2, 176-d2, aa)
+                    # Merge the details BELOW the houses
+                    details.alpha_composite(layer_comp)
+                    layer_comp = details
+                    # New edge
+                    osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)
+                    osm_edge = osm_edge.filter(ImageFilter.GaussianBlur(radius=1))
+                    # Blur the image
+                    layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=1))
+                    osm_edge.alpha_composite(layer_comp)
+                    layer_comp = osm_edge
+
+
+                    # Add some random trees
+                    div = int(self._imgsize/200)
+                    for y in range(0, self._imgsize, div):
+                        for x in range(0, self._imgsize, div):
+                            if x > 0 and x < self._imgsize and y > 0 and y < self._imgsize:
+                                p = mask_pix[x, y]
+                                if p[3] != 0:
+                                    # We found something...
+                                    # Determine if we put something somewhere
+                                    placement = randrange(0, 5)
+                                    if placement == 1:
+                                        # Do some random shift away from this location
+                                        shf_x = randrange(x-11, x+11)
+                                        shf_y = randrange(y-11, y+11)
+                                        if shf_x > 0 and shf_x < self._imgsize and shf_y > 0 and shf_y < self._imgsize:
+                                            # Pick some file
+                                            pick = str(randrange(1, 11))
+                                            tree = Image.open(mstr_datafolder + "Textures\\building\\area\\p" + pick + ".png")
+                                            layer_comp.alpha_composite(tree, (shf_x, shf_y))
+                                            #layer_comp.paste(tree, (shf_x, shf_y))
+
+            
             mstr_msg("layergen", "Layer image generated")
 
             # Building shadow
@@ -622,13 +690,15 @@ class mstr_layergen:
                     for y in range(self._imgsize-1):
                         for x in range(self._imgsize-1):
                             m = mask_pix[x,y]
-                            shf_x = x + mstr_shadow_shift
-                            if shf_x <= self._imgsize-1:
+                            shf_x = x + randrange(1, mstr_shadow_shift)
+                            shf_x2 = x + randrange(1, mstr_shadow_shift)
+                            if shf_x <= self._imgsize-1 and shf_x >= 0 and shf_x2 <= self._imgsize-1 and shf_x2 >= 0:
                                 a = mask_pix[x,y][3]
                                 st = random.uniform(0.45, mstr_shadow_strength)
                                 ca = a * st
                                 aa = int(ca)
                                 shadow_pix[shf_x, y] = (0,0,0,aa)
+                                shadow_pix[shf_x2, y] = (0,0,0,aa)
                     shadow.save(mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
                     mstr_msg("layergen", "Shadow layer completed")
             
index e1fbe22f860d232d6a591398c42e97ea98765156..c040c0d466cb69c8f71fdb1f4c0a222e87e3feaf 100644 (file)
@@ -183,3 +183,4 @@ class mstr_maskgen:
         # Inform
         mstr_msg("maskgen", "Mask built.")
 
+